All integrations MapLibre Leaflet OpenLayers React Vue Svelte Angular React Native WordPress Webflow Squarespace Wix Shopify API docs

Add a map to your Squarespace site

A clean OpenStreetMap map of your shop, studio or office, added with a Code Block. Pick from ten styles to match your template.

Before you start

  • A Squarespace plan that runs JavaScript in Code Blocks. Squarespace says: "To add JavaScript or an iframe to a code block, your site needs to be on the Core, Plus, or Advanced plan." Older Business and Commerce plans include it too. On the Basic (or older Personal) plan, Code Blocks accept HTML and CSS but not the script this map needs. See Squarespace's Code blocks help article.
  • A free ExpressMaps API key. Sign up (no card), then copy a key from Console → Keys.
  • Your location as longitude and latitude. Our map embed generator is the easy way: drag and zoom to your address, double-click to drop the marker, and it puts the numbers into the code for you.

Step 1: Copy the map code

Replace YOUR_API_KEY with your key and the two sets of numbers with your location. The order is longitude, then latitude: [-0.1276, 51.5072] is London. Swap them and the map lands somewhere unexpected.

<link rel="stylesheet" href="https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.css">
<script src="https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.js"></script>
<div id="map" style="width:100%;height:400px;"></div>
<script>
  var map = new maplibregl.Map({
    container: "map",
    style: "https://tiles.expressmaps.com/styles/standard.json?key=YOUR_API_KEY",
    center: [-0.1276, 51.5072],
    zoom: 13
  });
  map.addControl(new maplibregl.NavigationControl());
  new maplibregl.Marker()
    .setLngLat([-0.1276, 51.5072])
    .setPopup(new maplibregl.Popup().setText("Our shop"))
    .addTo(map);
</script>

The embed generator writes this same snippet (the HTML (MapLibre) tab) with your style, position, popup text and key filled in.

Step 2: Add a Code Block in Squarespace

  1. Open the page where the map belongs, for example Contact, and click Edit.
  2. Hover over the section, click Add block (or a + insert point) and choose Code.
  3. Click the pencil icon on the new block to open it.
  4. Make sure the Mode menu is set to HTML and the Display Source toggle is off. With Display Source on, Squarespace shows the code as text instead of running it.
  5. Delete the placeholder text, paste the snippet, then click outside the block and Save the page.

While you are logged in, Squarespace may not run code in the editor, so the block can look empty. Open your site in a private or incognito window, or in another browser, to see what visitors see.

Step 3: Restrict your key to your domain

Anyone can see your key in the page source; that is normal for web maps. The domain restriction is what stops other websites from using it.

  1. Go to Console → Keys and open your key.
  2. Under Key Restrictions, type a domain without https:// or a path and click Add Restriction.
  3. Add every address your site is viewed on as its own entry: yourbusiness.com, www.yourbusiness.com, and your built-in Squarespace address such as your-site.squarespace.com.
  4. Click Save Changes. The change applies to new requests shortly after saving.

Once a key has restrictions, pages on any domain not in the list get a "403" error instead of the map.

Troubleshooting

  • An empty grey or white box. Check the key: is YOUR_API_KEY replaced, and is the exact domain in your address bar (with or without www.) in the key's restriction list?
  • The code shows as text on the page. Turn Display Source off and set Mode to HTML.
  • Nothing at all, even logged out. Your plan may not allow scripts in Code Blocks (Core, Plus or Advanced needed), or the map has no height: keep height:400px in the snippet.
  • It only appears after refreshing the page. Some older Squarespace 7.0 templates load pages without a full reload, which skips scripts in Code Blocks. Turn off Ajax loading in the template's site styles if your template has that option.
  • The map is in the ocean. Longitude and latitude are swapped. MapLibre wants [longitude, latitude].
  • Two maps on one page, only one works. Give the second one its own name: change id="map", container: "map" and var map to map2 in the second snippet.

Things to know

  • Is it really free? Yes. The free plan includes 100,000 map loads a month, commercial use allowed. A map load is one page view showing the map; panning and zooming are free.
  • Do I need a cookie banner for the map? Not for the map itself: the map sets no cookies and does not track visitors. Other parts of your site may still need consent.
  • Why not the built-in Map Block? Squarespace's Map Block uses Google Maps. If you want a different look, one of our ten styles, or a map that sets no cookies, use the Code Block method instead.
  • Can I change the style? Replace standard in the style address with basic, enhanced, darklands, greyscale, navigator, subtle, autobahn, lithium or mulberry. greyscale and subtle suit minimal templates.
  • Can I show a second address? Yes, for a few locations copy the four new maplibregl.Marker() lines and change the numbers and popup text.
  • Page scrolling gets stuck on the map on phones. Add cooperativeGestures: true, after zoom: 13,. Visitors then move the map with two fingers, and one-finger scrolling moves the page.
  • Do I have to keep the "© OpenStreetMap" credit? Yes, the data licence requires it; the map adds it automatically.
  • Is there a shorter version? Our expressmaps helper takes a little less code. After the two MapLibre lines add <link rel="stylesheet" href="https://unpkg.com/expressmaps@1.0.1/dist/expressmaps.css"> and <script src="https://unpkg.com/expressmaps@1.0.1/dist/expressmaps.umd.js"></script>, then:
<div id="map" style="width:100%;height:400px;"></div>
<script>
  expressmaps.createMap({ container: "map", key: "YOUR_API_KEY", center: [-0.1276, 51.5072], zoom: 13, marker: { popup: "Our shop" } });
</script>

Get a free API key Open the embed generator