Select platform: [Android](https://developers.google.com/maps/documentation/android-sdk/infowindows.md.txt "View this page for the Android platform docs.") [iOS](https://developers.google.com/maps/documentation/ios-sdk/infowindows.md.txt "View this page for the iOS platform docs.") [JavaScript](https://developers.google.com/maps/documentation/javascript/infowindows.md.txt "View this page for the JavaScript platform docs.")

## Introduction

An [`InfoWindow`](https://developers.google.com/maps/documentation/javascript/reference.md.txt#InfoWindow) displays content (usually text or images) in a
popover window above the map, at a given location. The info window has a content
area and a tapered stem. The tip of the stem is attached to a specified
location on the map. Info windows appear as a Dialog to screen readers.
<iframe src="https://maps-docs-team.web.app/samples/infowindow-simple/dist/" allow="fullscreen; "></iframe>

Typically you will attach an info window to a
[marker](https://developers.google.com/maps/documentation/javascript/markers.md.txt), but you can also
attach an info window to a specific latitude/longitude, as described in the
section on adding an info window [below](https://developers.google.com/maps/documentation/javascript/infowindows.md.txt#add).

Broadly speaking, info windows are a type of overlay. For information on
other types of overlay, see
[Drawing on the map](https://developers.google.com/maps/documentation/javascript/overlays.md.txt).

> [!NOTE]
> **Hint:** If you want to display a single textual character on a marker, you can use a [marker
> label](https://developers.google.com/maps/documentation/javascript/markers#marker_labels).

> [!IMPORTANT]
> **Tip:** Check out the [Store Locator solutions](https://developers.google.com/maps/architecture/store-locator.md.txt) for more examples of using info windows.

## Add an info window

The [`InfoWindow`](https://developers.google.com/maps/documentation/javascript/reference.md.txt#InfoWindow) constructor takes an
`
InfoWindowOptions` object literal, which specifies the initial
parameters for displaying the info window.

The `InfoWindowOptions` object literal
contains the following fields:

- `content` contains either a string of text or a DOM node to display in the info window.
- `pixelOffset` contains an offset from the tip of the info window to the location on which the info window is anchored. In practice, you should not need to specify this field. You can leave it at the default value.
- `position` contains the `LatLng` at which this info window is anchored. Note: An `InfoWindow` may be attached either to a `Marker` object (in which case its position is based on the marker's location) or on the map itself at a specified `LatLng`. One way of retrieving a `LatLng` is by using the [Geocoding service](https://developers.google.com/maps/documentation/javascript/geocoding.md.txt). Opening an info window on a marker will automatically update the `position`.
- `maxWidth` specifies the maximum width of the info window in pixels. By default, an info window expands to fit its content, and auto-wraps text if the info window fills the map. If you add a `maxWidth` the info window will auto-wrap to enforce the specified width. If it reaches the maximum width and there is vertical room on the screen, the info window may expand vertically.

The content of the `InfoWindow` may contain a string of text, a
snippet of HTML, or a DOM element. To set the content, either specify it
within the `InfoWindowOptions` or call
`setContent()` on the `InfoWindow` explicitly.

If you wish to explicitly size the content, you can put it in a
`<div>` element and style the `<div>` with
CSS. You can use CSS to enable scrolling too. Note that if you do not
enable scrolling and the content exceeds the space available in the info
window, the content may spill out of the info window.

> [!NOTE]
> **Best practices:** For the best user experience, only one info window should be open on the map at any one time. Multiple info windows make the map appear cluttered. If you only need one info window at a time, you can create just one `InfoWindow` object and open it at different locations or markers upon map events, such as user clicks. If you do need more than one info window, you can display multiple `InfoWindow` objects at the same time.

## Open an info window

When you create an info window, it is not displayed automatically on the map.
To make the info window visible, you must call the `open()` method
on the `InfoWindow`, passing an [`InfoWindowOpenOptions`](https://developers.google.com/maps/documentation/javascript/reference/info-window.md.txt#InfoWindowOpenOptions)
object literal specifying the following options:

- `map` specifies the map or Street View panorama on which to open.
- `anchor` contains an anchor point (for example a `Marker`). If the `anchor` option is `null` or undefined, the info window will open at its `position` property.

### TypeScript

```typescript
// This example displays a marker at the center of Australia.
// When the user clicks the marker, an info window opens.

async function init(): Promise<void> {
    // Import the needed libraries.
    const [{ InfoWindow }, { AdvancedMarkerElement }] = await Promise.all([
        google.maps.importLibrary('maps'),
        google.maps.importLibrary('marker'),
    ]);

    // Get the map element and the inner map from it.
    const mapElement = document.querySelector('gmp-map')!;
    const innerMap = mapElement.innerMap;

    // Get the center of the map.
    const center = mapElement.center;

    // Create the info window content.
    const heading = document.createElement('h1');
    heading.textContent = 'Uluru (Ayers Rock)';

    const content = document.createElement('div');

    const infoParagraph = document.createElement('p');
    infoParagraph.textContent = `Uluru, also referred to as Ayers Rock, is a large sandstone rock formation 
  in the southern part of the Northern Territory, central Australia. It lies
  335 km (208 mi) south west of the nearest large town, Alice Springs; 450 km 
  (280 mi) by road. Kata Tjuta and Uluru are the two major features of the 
  Uluru - Kata Tjuta National Park. Uluru is sacred to the Pitjantjatjara and 
  Yankunytjatjara, the Aboriginal people of the area. It has many springs, 
  waterholes, rock caves and ancient paintings. Uluru is listed as a World 
  Heritage Site.`;

    content.appendChild(infoParagraph);

    const link = document.createElement('a');
    link.href = 'https://en.wikipedia.org/w/index.php?title=Uluru';
    link.textContent = 'https://en.wikipedia.org/w/index.php?title=Uluru';
    link.target = '_blank';
    content.appendChild(link);

    // Create the info window.
    const infoWindow = new InfoWindow({
        headerContent: heading,
        content,
        ariaLabel: 'Uluru',
        maxWidth: 500, // Set max width (optional).
    });

    // Create the marker.
    const marker = new AdvancedMarkerElement({
        position: center,
        map: innerMap,
        title: 'Uluru (Ayers Rock)',
        gmpClickable: true,
    });

    // Open the info window when the map loads.
    infoWindow.open({
        anchor: marker,
        map: innerMap,
    });

    // Open the info window when the marker is clicked.
    marker.addEventListener('gmp-click', () => {
        infoWindow.open({
            anchor: marker,
            map: innerMap,
        });
    });
}

void init();
```

### JavaScript

```javascript
// This example displays a marker at the center of Australia.
// When the user clicks the marker, an info window opens.

async function init() {
    // Import the needed libraries.
    const [{ InfoWindow }, { AdvancedMarkerElement }] = await Promise.all([
        google.maps.importLibrary('maps'),
        google.maps.importLibrary('marker'),
    ]);

    // Get the map element and the inner map from it.
    const mapElement = document.querySelector('gmp-map');
    const innerMap = mapElement.innerMap;

    // Get the center of the map.
    const center = mapElement.center;

    // Create the info window content.
    const heading = document.createElement('h1');
    heading.textContent = 'Uluru (Ayers Rock)';

    const content = document.createElement('div');

    const infoParagraph = document.createElement('p');
    infoParagraph.textContent = `Uluru, also referred to as Ayers Rock, is a large sandstone rock formation 
  in the southern part of the Northern Territory, central Australia. It lies
  335 km (208 mi) south west of the nearest large town, Alice Springs; 450 km 
  (280 mi) by road. Kata Tjuta and Uluru are the two major features of the 
  Uluru - Kata Tjuta National Park. Uluru is sacred to the Pitjantjatjara and 
  Yankunytjatjara, the Aboriginal people of the area. It has many springs, 
  waterholes, rock caves and ancient paintings. Uluru is listed as a World 
  Heritage Site.`;

    content.appendChild(infoParagraph);

    const link = document.createElement('a');
    link.href = 'https://en.wikipedia.org/w/index.php?title=Uluru';
    link.textContent = 'https://en.wikipedia.org/w/index.php?title=Uluru';
    link.target = '_blank';
    content.appendChild(link);

    // Create the info window.
    const infoWindow = new InfoWindow({
        headerContent: heading,
        content,
        ariaLabel: 'Uluru',
        maxWidth: 500, // Set max width (optional).
    });

    // Create the marker.
    const marker = new AdvancedMarkerElement({
        position: center,
        map: innerMap,
        title: 'Uluru (Ayers Rock)',
        gmpClickable: true,
    });

    // Open the info window when the map loads.
    infoWindow.open({
        anchor: marker,
        map: innerMap,
    });

    // Open the info window when the marker is clicked.
    marker.addEventListener('gmp-click', () => {
        infoWindow.open({
            anchor: marker,
            map: innerMap,
        });
    });
}

void init();
```
[View example](https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple.md.txt)

### Try Sample

[JSFiddle.net](https://jsfiddle.net/gh/get/library/pure/googlemaps-samples/js-api-samples/tree/main/dist/samples/infowindow-simple/jsfiddle)

The following example sets the `maxWidth` of an info window:
[view example](https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple-max).

## Set focus on an info window

To set focus on an info window, call its [`focus()`](https://developers.google.com/maps/documentation/javascript/reference/info-window.md.txt#InfoWindow.focus)
method. Consider using this method along with a [`visible`](https://developers.google.com/maps/documentation/javascript/reference/info-window.md.txt#InfoWindow.visible)
event prior to setting focus. Calling this method on a non-visible info
window will have no effect. Call [`open()`](https://developers.google.com/maps/documentation/javascript/infowindows.md.txt#open) to
make an info window visible.

## Close an info window

By default, an info window remains open until the user clicks the close
control (a cross at top right of the info window), or presses the ESC key.
You can also close the info window explicitly by calling its `close()`
method.

When an info window is closed, focus moves back to the element that was in
focus prior to the info window being opened. If that element is unavailable,
focus is moved back to the map. To override this behavior, you can listen to
the `closeclick` event, and manually manage focus as shown in the
following example:

```javascript
infoWindow.addListener('closeclick', ()=>{
  // Handle focus manually.
});
```

## Move an info window

There are a couple of ways to change the location of an info window:

- Call `setPosition()` on the info window, or
- Attach the info window to a new marker using the `InfoWindow.open()` method. Note: If you call `open()` without passing a marker, the `InfoWindow` will use the position specified upon construction through the `InfoWindowOptions` object literal.