How to embed a Google map in HTML

Maps gives you a finished iframe under Share, then Embed a map. Paste it, replace the fixed size with CSS, and the map travels with the page.

To embed a Google map in HTML, copy the iframe that Google Maps hands you under Share, then Embed a map, and paste it into your page. No key, no script.

The copied code looks like this, with a very long pb value that encodes the exact view:

<iframe
  src="https://www.google.com/maps/embed?pb=!1m18!1m12..."
  width="600" height="450" style="border:0;"
  allowfullscreen loading="lazy"
  referrerpolicy="no-referrer-when-downgrade"></iframe>
The Google Maps share panel with the Embed a map tab open and the iframe code selected. (Illustration.)
The Google Maps share panel with the Embed a map tab open and the iframe code selected. (Illustration.)

Set the view before you copy

The embed captures whatever you are looking at. Pan, zoom and place the pin first, then copy.

Search the full street address rather than the business name if you want the marker in a precise spot. Names sometimes resolve to a district centre instead.

Once copied, the pb string is opaque. You cannot hand-edit a coordinate in it, so a wrong view means going back and copying again.

Making it fit the column

The copied iframe carries width="600" height="450". That is fine on a desktop and wrong on a phone. Override it in CSS:

.map iframe {
  width: 100%;
  height: 420px;
  border: 0;
  border-radius: 8px;
}

Set a height. A frequent mistake: authors set the width to 100 percent, leave the height alone, and the frame collapses to a thin grey strip.

An aspect ratio also works and scales better on small screens:

.map iframe { width: 100%; aspect-ratio: 4 / 3; border: 0; }
A map iframe with width set to 100 percent and no height. The frame renders as a grey strip.
A map iframe with width set to 100 percent and no height. The frame renders as a grey strip.

The iframe attributes, and what each one does

Attribute Effect if present Effect if removed
allowfullscreen The expand control works Full screen is not allowed
loading="lazy" The map loads when scrolled near It loads with the page, slowing first paint
referrerpolicy Sends the referrer as Maps expects Usually still fine, occasionally not
title Gives screen readers a label The frame is announced with no name
width/height A fallback size CSS takes over, if you wrote any

Add title yourself. Google's copied block does not include one, and an unlabelled iframe is an accessibility gap that costs one attribute to fix.

When you need the Embed API instead

The Share iframe covers one thing: a view of a place. The Maps Embed API covers more, and it needs a key from Google Cloud.

Its addresses follow a readable pattern, which is the real advantage. You can build them from your own data:

<iframe
  src="https://www.google.com/maps/embed/api/place?key=YOUR_KEY&q=Eiffel+Tower,Paris"
  style="border:0" allowfullscreen loading="lazy"></iframe>

The mode sits in the path. Swapping place for directions, view, streetview or search changes what the frame shows, and each mode takes its own parameters.

Check Google's current terms and quota before you ship anything that generates addresses in bulk. Those conditions change, and this page is not the place to quote numbers at you.

Choosing between the two routes

You want Route
One office location on a contact page Share, then Embed a map
A venue pin on an invitation Share, then Embed a map
A map address built from a spreadsheet column Embed API with a key
Driving directions between two points Embed API, directions mode
Street view of a specific doorway Embed API, streetview mode

For most pages, the first row is the answer, and reaching for a key is work you do not need to do.

Where a Google map embed in HTML breaks

Opened from disk. A page opened by double-clicking the file runs under the file:// scheme, which has no real origin. Frames are frequently refused there. File protocol lists the other symptoms.

Mixed content. A page served over HTTPS that embeds a frame over plain HTTP gets the frame blocked without a visible message. See mixed content.

A frame policy on the host page. If the page sets frame-src, Google has to be named in it. Content Security Policy covers the header.

No network. Maps is a live service. An offline reader sees an empty box, so add a text address underneath for anyone in that situation.

Putting the map where people will actually see it

A map is usually part of something else: an invitation, a venue note, an office page. That host page has to reach the reader intact, which is the harder half.

Paste the whole HTML into a NOS document and it renders, but the map iframe does not load there. Put a link to the map beside the written address instead. The document has its own address, so you send one link rather than a file.

Editing it later does not move the address. When the venue changes, you replace the map link and address in place, and the link you already sent shows the new venue.

Turning HTML into a link is that step on its own, and HTML for event invites shows the pattern applied to a whole page.

What to put next to the map

A map alone assumes the reader can see it, has a network, and is not printing the page. Write the address in text beside it.

<address>
  12 Rue de Rivoli, 75004 Paris<br>
  Nearest metro: Saint-Paul, line 1
</address>

Three more lines worth adding. A note on which entrance to use, because a pin lands on a building and not on a door. A landmark, because people navigate by them. And a phone number for anyone who arrives and cannot find you.

The map is a convenience layered on top of that text. Treated the other way round, a blocked frame or a flat battery leaves the reader with nothing.

Add title="Map of the office location" to the iframe as well. Without it, a screen reader announces an unnamed frame and moves on.

Questions people ask

Do I need an API key to embed a Google map?

Not for the iframe copied from the Share panel on maps.google.com. That code is self-contained. A key is required only when you build the address yourself with the Maps Embed API, which is what lets you switch between place, directions and street view modes.

Why is the map a small grey box?

The copied iframe carries fixed width and height attributes. If your CSS sets width to 100 percent but leaves height unset, the frame collapses. Set both, or set a height and an aspect ratio, in CSS rather than relying on the attributes.

Can I embed a map with a pin on my own address?

Yes. Search the address on Google Maps first so the pin is placed, then open Share and Embed a map. The generated iframe keeps the marker and the zoom level you were looking at.

Does the map still work when I send the page as a file?

Only with a network connection, and often not when the page is opened straight from disk. An iframe loaded from the file protocol has a different origin and may be refused. Serving the page from an address avoids the whole class of problem.

Keep reading

Map markers in HTML, without a map serviceClickable map markers on an SVG map or floor plan with plain HTML, CSS and JavaScript: perceGet the user's location in HTML with the Geolocation APIGet the user's location with navigator.geolocation: the permission prompt, HTTPS, options, eWhat is an iframe?What is an iframe: an HTML element that draws another document inside a box on your page. HoHow to embed a Google Form in HTMLEmbed a Google Form in HTML with the iframe from Send. Why the frame cuts off or scrolls twiHow to embed a website into another websiteOne iframe embeds a website inside another page, and many sites refuse. How to tell which, wHow to send an event invitation onlineSend an invitation as a link that opens on a phone, carries the details, and stays correct wEmbed a YouTube video in HTMLHow to embed a YouTube video in HTML with an iframe, make it responsive, set a start time, aSend HTML form data to Google SheetsPost an HTML form to a Google Sheet using Apps Script. The doPost function, the deployment sBuild a simple HTML todo listA working todo list in one HTML file: add, complete, delete and keep items after a reload. FLeaflet Map in One HTML File: Working Example and FixesBuild a Leaflet map in one HTML file, test markers and invalid coordinates, then share the wOpenLayers in a single HTML file, and in ReactOpenLayers is a JavaScript map library. See the smallest working map in one HTML file, the RMapbox in a single HTML file: the script, the token and the mapPut a Mapbox GL JS map in one HTML file: the script and CSS, your public access token, a siz