--- title: Map summary: A map shows places and markers on an interactive world map. Tabler turns a single element into a themed map, and the map itself is rendered by MapLibre GL JS. description: Show interactive maps with markers, popups and a matching dark mode from plain HTML, using MapLibre GL JS and free map tiles. No account or access token is needed. added-in: '1.7.0' related: [/ui/plugins/vector-map] docs-libs: [maplibre-gl] source: core/scss/vendor/_maplibre.scss css-vars: map-marker classnames: component: - class: ratio desc: Wrapper that keeps the map at a fixed aspect ratio - class: map-marker desc: Marker drawn in HTML, a circle that can hold an icon, a count or an avatar part: - class: map-marker-label desc: Short text under a marker - class: map-controls desc: Column of buttons in the top end corner of the map modifier: - class: map-marker-dot desc: Small dot with no content - class: map-marker-pulse desc: Ring that grows out of the marker and fades, for a live position - class: map-marker-pin desc: Teardrop pin that points down, used with the bottom anchor - class: map-popup-card desc: Popup with no padding and a fixed width, for an image above the text - class: map-tooltip desc: Popup shown as a small dark label, for text on hover color: - class: map-marker-{color} desc: Any theme color, for example map-marker-red or map-marker-green size: - class: ratio-{ratio} desc: The aspect to hold, for example ratio-16x9 or ratio-21x9 --- import Example from '@components/Example.astro'; import Map from '@shared/components/demo/Map.astro'; import Icon from '@ui/Icon.astro'; import CodeDocs from '@components/CodeDocs.astro'; import { Code } from 'astro:components'; import { site } from '@shared/lib/site.ts'; import { cdnJsTag, cdnMapJsTag, cdnPluginSnippet } from '@lib/cdn-snippets.ts'; ## Overview The map component turns an element into an interactive map. Add `data-bs-toggle="map"` to it, set the center and the zoom with data attributes, and write the markers as child elements. No script is needed. The map is drawn by [MapLibre GL JS](https://maplibre.org/maplibre-gl-js/docs/), an open-source map library, which you load next to Tabler. The map tiles come from [OpenFreeMap](https://openfreemap.org/). It needs no account and no access token, and it can be used in commercial projects. If you only need a simple map of countries or regions, use the [vector map](/ui/plugins/vector-map) instead. It makes no network calls at all. ## Installation The map component is not part of `tabler.js`. It ships as a small add-on, `tabler-map.js`, so pages without a map do not carry it. Load the MapLibre stylesheet, and the add-on after `tabler.js`; it adds `MapView` to the `tabler` object: ${cdnJsTag()} ${cdnMapJsTag()}`} /> The add-on loads MapLibre GL JS by itself, from `dist/libs/maplibre-gl` next to the Tabler scripts. Tabler uses version 6, which is published as an ES module. When your files are somewhere else, point the `library` option at the module: `data-bs-library="/vendor/maplibre-gl.mjs"`. The library loads two more files from its own folder, `maplibre-gl-shared.mjs` and `maplibre-gl-worker.mjs`, so keep the three together. If the page sets `window.maplibregl` before the add-on runs, the component uses that and loads nothing. This is the way to go with a bundler: ```bash npm install maplibre-gl ``` ```js import * as maplibregl from 'maplibre-gl' import 'maplibre-gl/dist/maplibre-gl.css' window.maplibregl = maplibregl const { MapView } = await import('@tabler/core/dist/js/tabler-map.esm.js') ``` Older versions, including all of version 5, have a known security issue in the code that cleans the attribution text. Browsers do not load ES modules from a page opened straight from the disk. Use a local server to see the maps while you work. Tabler styles the map controls, popups and attribution to match the interface, in light and dark mode. These styles are in `tabler-vendors.css`, so load it after the MapLibre stylesheet: ## Usage ### Basic map Put the map element inside a `ratio` element, so the map keeps its shape on every screen size. `data-bs-center` takes the longitude first and the latitude second. This is the opposite of what most map services show. Change the shape with the ratio classes, for example `ratio-21x9` for a wide map or `ratio-1x1` for a square one. ### Map styles The map uses a light gray style in light mode and a dark one in dark mode. Tabler softens their colors, so markers and data stand out. Set another style with `data-bs-map-style`: the name of an OpenFreeMap style, or the URL of any MapLibre style. | Style | Result | | --- | --- | | `positron` | Light gray map. The default in light mode. | | `dark` | Dark gray map. The default in dark mode. | | `liberty` | Street map in color. | | `bright` | Street map with stronger colors. | | `fiord` | Dark blue map. | `data-bs-map-style-dark` sets the style for dark mode. Styles from other providers work the same way, as long as they follow the MapLibre style format. Check the terms of each provider, as many of them need an API key or a paid plan. ### Dark mode The map follows the nearest `data-bs-theme` and changes its style when the theme changes. Markers and popups stay on the map. To keep one look in both modes, set `data-bs-map-theme` to `light` or `dark`. ### Markers Each child element with `data-bs-lng` and `data-bs-lat` becomes a marker. Use the `.map-marker` class to draw it: a circle in the primary color that can hold an icon, a short count or an avatar. Put a `.map-marker-label` element inside the marker for a short text under it. Add `.map-marker-dot` for a small dot, or `.map-marker-pin` for a pin that points down. A pin needs `data-bs-anchor="bottom"`, so its tip sits on the place. Change the color with `.map-marker-{color}`. Store 12 Add `data-bs-draggable="true"` to let people move a marker, for example to pick an address. Add `.map-marker-pulse` for a ring that grows out of the marker, for a live position or a place that needs attention. HTML markers work well for up to a few hundred places. For more, use [clusters](#clusters). ### Popups Add `data-bs-popup` to a marker for a short text that opens when the marker is clicked. Tabler draws the popup as a small bordered panel with no arrow, and fades it in. For richer content, put a `