Fix a Google Maps container with zero height
A blank space where the map should be, with nothing in the console, is nearly always CSS. The map started up inside an element with no height, so there was nothing to draw into.
How to tell this is your problem
- There is no Google Maps error in the console at all.
- There's no grey “Oops! Something went wrong.” box and no watermark. The space is simply empty, or collapsed to nothing.
- Inspecting the map element in developer tools shows a height of 0.
- The map appears when you resize the window, rotate a phone, or open the tab or accordion it lives in.
- The network tab shows maps.googleapis.com requests succeeding, so the key and API are fine.
To check the height quickly, open the console and run this, with your map element's selector in place of #map:
document.querySelector("#map").getBoundingClientRect().height
If it prints 0, this guide is your fix. If it prints a real number and the map is still blank, look for an error instead. See reading Google Maps errors in the console.
Why it happens
The Maps JavaScript API fills the element you give it. It doesn't give that element a size. A div with no content and no height set collapses to zero pixels tall, so the map has a width and no height. The usual causes, most likely first:
- No height at all. The container was added with an ID and no CSS. A theme update or a CSS clean-up can remove a rule the map relied on.
- A percentage height with no sized parent. height: 100% means 100% of the parent's height. If the parent has no height set, the result is zero. Google's own samples set height: 100% on the map and on html and body for this reason.
- A hidden container when the map was created. Maps inside tabs, accordions, modals or sliders are often created while the panel is display: none. A hidden element has no size, and the map can render wrongly or not at all.
- Flex and grid layouts. A map inside a flex row or grid cell with no height of its own can collapse, depending on alignment settings.
- Page builder settings. A map widget with its height field left empty, or set in a unit that resolves to zero on mobile.
The fix, step by step
- 01Give the container an explicit height in your stylesheet. A fixed height is the most reliable choice.
- 02If you want height: 100%, make sure every ancestor up to html also has a height, or switch to a fixed or viewport-based height.
- 03For tabs, accordions and modals, create the map when its panel first becomes visible, not when the page loads.
- 04Clear any page cache or CSS optimisation cache so visitors receive the new styles.
/* Simple and reliable */
#map {
height: 400px;
}
/* Responsive: keeps a 16:9 shape at any width */
#map {
width: 100%;
aspect-ratio: 16 / 9;
min-height: 300px;
}
/* Full-page map: every ancestor needs a height */
html, body {
height: 100%;
margin: 0;
}
#map {
height: 100%;
}
Even if you size the map another way, adding min-height means a later layout change can't silently collapse it to nothing.
Maps in tabs, accordions and modals
The safest pattern is to create the map the first time the panel opens. The container then has its real size at the moment the map is drawn, and visitors who never open the tab don't create a map load at all.
let map;
document.querySelector("#location-tab").addEventListener("click", async () => {
if (map) return; // only create it once
const { Map } = await google.maps.importLibrary("maps");
map = new Map(document.getElementById("map"), {
center: { lat: 51.5072, lng: -0.1276 },
zoom: 14,
mapId: "DEMO_MAP_ID",
});
});
Run this after the tab's own script has made the panel visible. If your tab library fires a “shown” event, listen for that instead of the click. If an existing map was created while hidden and now shows grey or off-centre, set its centre again once the panel is visible, or move its creation into the handler as above.
WordPress and page builders
- Elementor, Divi, WPBakery. Map widgets have a height setting. Check it is set for desktop, tablet and mobile, since responsive overrides can be empty on one breakpoint.
- Shortcodes. Maps plugins often accept a height attribute. A missing or invalid value can fall back to zero.
- Theme updates. If the map disappeared after an update, the theme may have dropped a CSS rule. Add the height in Appearance → Customize → Additional CSS so it survives future updates.
If the space is blank and the console shows the map loading twice, the cause may be a duplicate loader instead. See two plugins loading Maps.
Confirm it is fixed
Reload the page in a private window. The map should appear without resizing the window. Run the height check above again and confirm it prints the value you set. Test on a phone-sized viewport as well, and open each tab or accordion that contains a map.
Then run a scan. A zero-height container produces no Google error, so a clean scan alone doesn't prove the map is visible. The scan confirms the key, APIs and loader are healthy, and your height check confirms the layout.
Common questions
Why is my Google Map blank with no error?
The map's container has no height, so the API has nowhere to draw. Give the element an explicit height in CSS, such as 400px, and the map appears.
Why doesn't height: 100% work for my map?
A percentage height is relative to the parent. If the parent has no height set, 100% of nothing is zero. Size every ancestor or use a fixed or viewport height.
Why is my map grey or blank inside a tab until I resize the window?
The map was created while the tab was hidden, so its container had no size. Create the map when the tab first opens.
Does a zero-height map still count as a map load?
Assume it does. Google bills successful map loads, and your code still creates the map even when nobody can see it. Creating the map on demand avoids paying for maps nobody looks at.
A scan tells you in about twelve seconds, from a clean session.