How to embed Google map in HTML step by step guide

A clear, step-by-step guide to embedding Google Maps in HTML using Embed API and JavaScript, with practical tips.
Embedding Google Maps in HTML is a common need for websites, blogs, and business pages. You have a few straightforward options, depending on whether you want a simple map or a fully interactive map with custom markers and events. This guide walks you through step by step, from a quick iframe embed to a fully customized JavaScript-powered map.
Quick start options compared
| Option | Setup | Key limitation | Best use case | Availability | Notes |
|---|---|---|---|---|---|
| Iframe embed (no API key) | Easy | Limited interactivity | Simple map display | Immediate | No API key needed |
| Maps Embed API (official) | Easy | Quotas apply | Quick map embeds | High | Official API embed |
| JavaScript API (interactive) | Moderate | More code | Full interactivity | Scales well | Requires API key |
Compiled November 2026; check the provider's site for current details.
Quick start: embed with an iframe (no API key)
If you just need a simple map that shows a location, an iframe embed is the fastest route.
Steps
- Go to Google Maps and locate the place you want to show.
- Click the Share button, then choose Embed a map.
- Pick the desired size (small, medium, large) and copy the HTML iframe snippet.
- Paste the code into your HTML where you want the map to appear.
Pros and cons
- Pros: No API key required, easy, quick.
- Cons: Limited customization, no markers beyond the location, no event handling.
Using the Maps Embed API (official, no heavy coding)
For more control than a basic iframe but still minimal code, use the Maps Embed API. This approach uses a URL-based embed with optional parameters.
What you need
- A Google Cloud project and an API key with Maps Embed API enabled.
- Basic HTML page to place the map.
How to build the embed URL
- Base URL: https://www.google.com/maps/embed/v1/place
- Required parameter: key=YOUR_API_KEY
- Required parameter: q=Place+Name or address
- Optional: zoom, maptype, language, region Example URL structure:
- https://www.google.com/maps/embed/v1/place?key=YOUR_API_KEY&q=Space+Needle,Seattle+WA
Example iframe
Key considerations
- API key security: restrict by HTTP referrers (domains) to prevent misuse.
- Usage limits and pricing: Maps Embed API has quotas. Monitor usage in Google Cloud Console.
- Responsiveness: use responsive containers to keep the map view on different devices.
Embedding options vs features
| Feature / Method | Iframe (no API key) | Maps Embed API | Maps JavaScript API | Multi-location support | Custom markers | Interactivity |
|---|---|---|---|---|---|---|
| Need API key | no | optional/required | yes | yes | yes | yes |
| Interaction depth | limited | limited | full | yes | yes | full |
| Custom markers | no | yes (limited) | yes | yes | yes | yes |
| Multiple locations | yes (same map) | yes | yes | yes | yes | yes |
| Offline caching | no | no | no | no | no | no |
| Pricing model | free tier | free tier | pay as you go | depends | depends | depends |
Compiled November 2026; check the provider's site for current details.
Embedding an interactive map with the Maps JavaScript API
If you want interactivity like custom markers, info windows, or events, the Maps JavaScript API is the right choice. This requires loading the API script with your API key and writing a bit of JavaScript. Get paid in crypto
Prerequisites
- A Google Cloud project with the Maps JavaScript API enabled.
- An API key with proper restrictions.
- A basic HTML page to load the map into a container div.
Minimal setup
- Add a container in your HTML:
- Include the API script with your key:
- Create a JavaScript function to initialize the map:
- function initMap { var map = new google.maps.Map(document.getElementById('map'), { center: {lat: 37.4221, lng: -122.0841}, zoom: 14 }); }
- Note: Replace coordinates with your target location.
Adding markers and info Windows
- var marker = new google.maps.Marker({ position: {lat: 37.4221, lng: -122.0841}, map: map, title: 'My Location' });
- var infowindow = new google.maps.InfoWindow({ content: 'My Location
Address or description' }); - marker.addListener('click', function { infowindow.open(map, marker); });
A small, practical example (all in one)
- HTML:
- JavaScript:
- function initMap {
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 40.7484, lng: -73.9857},
zoom: 13
});
var marker = new google.maps.Marker({ position: {lat: 40.7484, lng: -73.9857}, map: map, title: 'Empire State Building' });
var info = new google.maps.InfoWindow({ content: 'Empire State Building
New York, NY' }); marker.addListener('click', function { info.open(map, marker); }); }
Tables: compare iframe, Embed API, and JavaScript API
| Method | Key required | Customization | Interactivity | Use case |
|---|---|---|---|---|
| iframe embed | Optional (no key required) | Low | None beyond default map actions | Simple location display on a page |
| Maps Embed API | Required (key) | Moderate via URL params | Basic controls, some interactions | Simple branded embeds with parameters |
| Maps JavaScript API | Required (key) | High (markers, events, styles) | Full interactivity (clicks, draggables, custom overlays) | Complex maps with custom features |
Best practices for the JavaScript API
- Restrict your API key to your domains to prevent unauthorized use.
- Enable only the APIs you need (Maps JavaScript API, optionally Geocoding, Places).
- Use loading strategies: defer and async to avoid blocking rendering.
- Handle errors gracefully in code (e.g., if the API fails to load).
Handling multiple locations and custom markers
If you need to show a list of locations, you can loop through a data array to add markers and attach info windows.
Example data-driven approach
- var locations = [ {name: 'Store A', lat: 34.0522, lng: -118.2437, info: 'Downtown LA store'}, {name: 'Store B', lat: 37.7749, lng: -122.4194, info: 'San Francisco store'} ];
- locations.forEach(function(loc) {
var m = new google.maps.Marker({ position: {lat: loc.lat, lng: loc.lng}, map: map, title: loc.name });
var iw = new google.maps.InfoWindow({ content: '' + loc.name + '
' + loc.info }); m.addListener('click', function { iw.open(map, m); }); });
Checklist comparison (steps from scratch)
| Step | Iframe path | Embed API path | JS API path | Notes | Required keys | Quick start confidence |
|---|---|---|---|---|---|---|
| Get map URL | yes | yes | yes | Copy URL or code | no | high |
| Copy embed code | yes | yes | no | Paste into HTML | no | high |
| Add API key | no | yes | yes | If using API-based | yes | medium |
| Set map size | yes | yes | yes | width/height | no | high |
| Configure markers | no | limited | full | Custom markers | yes | medium |
| Test in browser | yes | yes | yes | Resolve errors | yes | high |
Compiled November 2026; check the provider's site for current details.
Checklist: steps to embed Google Maps in HTML from scratch
- Decide on embed method: iframe for quick display or JavaScript API for interactivity.
- Create or open your HTML page.
- If using iframe:
- Use the embed code from Google Maps, paste into your page.
- If using Maps Embed API:
- Create a Google Cloud project, enable Maps Embed API, obtain an API key.
- Build the embed URL with required parameters and place it in an iframe tag.
- If using Maps JavaScript API:
- Create a Google Cloud project, enable Maps JavaScript API, obtain an API key.
- Add a map container div, load the API script with your key, and write initialization code (center, zoom, markers).
- test on multiple devices and screen sizes to ensure responsiveness.
- Monitor usage in the Google Cloud Console and implement key restrictions.
Security and pricing notes
- API key safety: restrict by HTTP referrers (websites) or by IP address if server-side usage.
- Billing and quotas: Google Maps Platform has pricing changes. Always review current quotas and enable alerts.
- Terms of service: ensure your use complies with Google Maps Platform Terms and Attribution requirements.
Final recommendation
If you need a quick map for a static location, start with the iframe method. It’s fast, simple, and requires no code beyond inserting a snippet. If you want interactivity, multiple markers, custom styles, or events, use the Maps JavaScript API with an API key, following best practices for security and performance. For many sites, a blend works well: embed a basic map for the location, and add a JavaScript-powered map component where users can explore nearby points of interest or get directions.
