HTML markers with CSS states
Markers made of your own HTML, their hovered and selected looks in your CSS.
Map and code
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
Loading the map…
The map couldn't load.
These maps come from Google Maps and OpenFreeMap, which see your IP address. They stay off until you say so, once for the whole site. What loading the maps sends
<!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<!-- Markers drawn by your CSS: each pin is your own markup (a <template data-icon>), which Maplace.js
marks data-hovered while the reader points at it and data-selected once they pick it, so your
CSS gives each state its look. The pin is drawn anew for each state, so the pop is an animation,
which starts on a new node, not a transition. -->
<style>
#css-markers-maplibre-map .pin {
display: inline-block;
padding: 0.25rem 0.625rem;
border: 2px solid #1d1d1b;
border-radius: 999px;
background: #fff;
color: #1d1d1b;
font: 600 0.8125rem/1.2 system-ui, sans-serif;
white-space: nowrap;
box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
cursor: pointer;
}
#css-markers-maplibre-map .pin[data-hovered] { transform: translateY(-3px); }
#css-markers-maplibre-map .pin[data-selected] {
border-color: #c62828;
background: #c62828;
color: #fff;
transform: scale(1.15);
}
@media (prefers-reduced-motion: no-preference) {
#css-markers-maplibre-map .pin[data-selected] { animation: css-markers-maplibre-pop 0.3s ease-out; }
}
@keyframes css-markers-maplibre-pop { from { transform: scale(0.85); } }
</style>
<maplace-map id="css-markers-maplibre-map">
<maplace-location location-id="rijks" lat="52.36" lng="4.8852" title="Rijksmuseum">
<template data-icon><span class="pin">Rijks</span></template>
</maplace-location>
<maplace-location location-id="anne-frank" lat="52.3752" lng="4.884" title="Anne Frank House">
<template data-icon><span class="pin">Anne Frank</span></template>
</maplace-location>
<maplace-location location-id="hermitage" lat="52.3654" lng="4.9025" title="Hermitage">
<template data-icon><span class="pin">Hermitage</span></template>
</maplace-location>
<maplace-location location-id="nemo" lat="52.3738" lng="4.9123" title="NEMO Science Museum">
<template data-icon><span class="pin">NEMO</span></template>
</maplace-location>
<maplace-location location-id="eye" lat="52.3843" lng="4.9008" title="Eye Filmmuseum">
<template data-icon><span class="pin">Eye</span></template>
</maplace-location>
</maplace-map><!doctype html>
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<!-- Markers drawn by your CSS: each pin is your own markup (a <template data-icon>), which Maplace.js
marks data-hovered while the reader points at it and data-selected once they pick it, so your
CSS gives each state its look. The pin is drawn anew for each state, so the pop is an animation,
which starts on a new node, not a transition. -->
<style>
#css-markers-map .pin {
display: inline-block;
padding: 0.25rem 0.625rem;
border: 2px solid #1d1d1b;
border-radius: 999px;
background: #fff;
color: #1d1d1b;
font: 600 0.8125rem/1.2 system-ui, sans-serif;
white-space: nowrap;
box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
cursor: pointer;
}
#css-markers-map .pin[data-hovered] { transform: translateY(-3px); }
#css-markers-map .pin[data-selected] {
border-color: #c62828;
background: #c62828;
color: #fff;
transform: scale(1.15);
}
@media (prefers-reduced-motion: no-preference) {
#css-markers-map .pin[data-selected] { animation: css-markers-pop 0.3s ease-out; }
}
@keyframes css-markers-pop { from { transform: scale(0.85); } }
</style>
<maplace-map id="css-markers-map" api-key="YOUR_KEY">
<maplace-location location-id="rijks" lat="52.36" lng="4.8852" title="Rijksmuseum">
<template data-icon><span class="pin">Rijks</span></template>
</maplace-location>
<maplace-location location-id="anne-frank" lat="52.3752" lng="4.884" title="Anne Frank House">
<template data-icon><span class="pin">Anne Frank</span></template>
</maplace-location>
<maplace-location location-id="hermitage" lat="52.3654" lng="4.9025" title="Hermitage">
<template data-icon><span class="pin">Hermitage</span></template>
</maplace-location>
<maplace-location location-id="nemo" lat="52.3738" lng="4.9123" title="NEMO Science Museum">
<template data-icon><span class="pin">NEMO</span></template>
</maplace-location>
<maplace-location location-id="eye" lat="52.3843" lng="4.9008" title="Eye Filmmuseum">
<template data-icon><span class="pin">Eye</span></template>
</maplace-location>
</maplace-map><!doctype html>
<!-- A page of your own script: the MapLibre CDN script, which bundles maplibre-gl and its stylesheet, what the map mounts on, and the map made with Maplace; each pin is a node of yours, styled by the page's CSS. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element-maplibre.iife.js"></script>
<style>
#css-markers-maplibre-script-map { height: 24rem; }
#css-markers-maplibre-script-map .pin {
display: inline-block;
padding: 0.25rem 0.625rem;
border: 2px solid #1d1d1b;
border-radius: 999px;
background: #fff;
color: #1d1d1b;
font: 600 0.8125rem/1.2 system-ui, sans-serif;
white-space: nowrap;
box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
cursor: pointer;
}
#css-markers-maplibre-script-map .pin[data-hovered] { transform: translateY(-3px); }
#css-markers-maplibre-script-map .pin[data-selected] {
border-color: #c62828;
background: #c62828;
color: #fff;
transform: scale(1.15);
}
@media (prefers-reduced-motion: no-preference) {
#css-markers-maplibre-script-map .pin[data-selected] { animation: css-markers-maplibre-script-pop 0.3s ease-out; }
}
@keyframes css-markers-maplibre-script-pop { from { transform: scale(0.85); } }
</style>
<div id="css-markers-maplibre-script-map"></div>
<script type="module">
const locations = [
{ id: "rijks", lat: 52.36, lng: 4.8852, title: "Rijksmuseum", icon: pinFor("Rijks") },
{ id: "anne-frank", lat: 52.3752, lng: 4.884, title: "Anne Frank House", icon: pinFor("Anne Frank") },
{ id: "hermitage", lat: 52.3654, lng: 4.9025, title: "Hermitage", icon: pinFor("Hermitage") },
{ id: "nemo", lat: 52.3738, lng: 4.9123, title: "NEMO Science Museum", icon: pinFor("NEMO") },
{ id: "eye", lat: 52.3843, lng: 4.9008, title: "Eye Filmmuseum", icon: pinFor("Eye") },
];
Maplace.createMapLibreMap("#css-markers-maplibre-script-map", { locations });
/**
* A pin of your own: one node for every state, which Maplace.js marks `data-hovered` and
* `data-selected`, so the page's CSS gives each state its look.
*/
function pinFor(label) {
const pin = document.createElement("span");
pin.className = "pin";
pin.textContent = label;
return pin;
}
</script><!doctype html>
<!-- A page of your own script: the CDN script, what the map mounts on, and the map made with Maplace, which adds Maps JS with your key; each pin is a node of yours, styled by the page's CSS. -->
<script src="https://cdn.jsdelivr.net/npm/@maplacejs/maplace@1/dist/maplace-element.iife.js"></script>
<style>
#css-markers-script-map { height: 24rem; }
#css-markers-script-map .pin {
display: inline-block;
padding: 0.25rem 0.625rem;
border: 2px solid #1d1d1b;
border-radius: 999px;
background: #fff;
color: #1d1d1b;
font: 600 0.8125rem/1.2 system-ui, sans-serif;
white-space: nowrap;
box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
cursor: pointer;
}
#css-markers-script-map .pin[data-hovered] { transform: translateY(-3px); }
#css-markers-script-map .pin[data-selected] {
border-color: #c62828;
background: #c62828;
color: #fff;
transform: scale(1.15);
}
@media (prefers-reduced-motion: no-preference) {
#css-markers-script-map .pin[data-selected] { animation: css-markers-script-pop 0.3s ease-out; }
}
@keyframes css-markers-script-pop { from { transform: scale(0.85); } }
</style>
<div id="css-markers-script-map"></div>
<script type="module">
const locations = [
{ id: "rijks", lat: 52.36, lng: 4.8852, title: "Rijksmuseum", icon: pinFor("Rijks") },
{ id: "anne-frank", lat: 52.3752, lng: 4.884, title: "Anne Frank House", icon: pinFor("Anne Frank") },
{ id: "hermitage", lat: 52.3654, lng: 4.9025, title: "Hermitage", icon: pinFor("Hermitage") },
{ id: "nemo", lat: 52.3738, lng: 4.9123, title: "NEMO Science Museum", icon: pinFor("NEMO") },
{ id: "eye", lat: 52.3843, lng: 4.9008, title: "Eye Filmmuseum", icon: pinFor("Eye") },
];
Maplace.createGoogleMap("#css-markers-script-map", { apiKey: "YOUR_KEY", locations });
/**
* A pin of your own: one node for every state, which Maplace.js marks `data-hovered` and
* `data-selected`, so the page's CSS gives each state its look.
*/
function pinFor(label) {
const pin = document.createElement("span");
pin.className = "pin";
pin.textContent = label;
return pin;
}
</script><!doctype html>
<!-- The page vanilla.ts runs on: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
#css-markers-maplibre-vanilla-map { height: 24rem; }
#css-markers-maplibre-vanilla-map .pin {
display: inline-block;
padding: 0.25rem 0.625rem;
border: 2px solid #1d1d1b;
border-radius: 999px;
background: #fff;
color: #1d1d1b;
font: 600 0.8125rem/1.2 system-ui, sans-serif;
white-space: nowrap;
box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
cursor: pointer;
}
#css-markers-maplibre-vanilla-map .pin[data-hovered] { transform: translateY(-3px); }
#css-markers-maplibre-vanilla-map .pin[data-selected] {
border-color: #c62828;
background: #c62828;
color: #fff;
transform: scale(1.15);
}
@media (prefers-reduced-motion: no-preference) {
#css-markers-maplibre-vanilla-map .pin[data-selected] { animation: css-markers-maplibre-vanilla-pop 0.3s ease-out; }
}
@keyframes css-markers-maplibre-vanilla-pop { from { transform: scale(0.85); } }
</style>
<div id="css-markers-maplibre-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>import "maplibre-gl/dist/maplibre-gl.css";
import type { Location } from "@maplacejs/maplace";
import { createMapLibreMap } from "@maplacejs/maplace/maplibre";
const locations: Location[] = [
{ id: "rijks", lat: 52.36, lng: 4.8852, title: "Rijksmuseum", icon: pinFor("Rijks") },
{
id: "anne-frank",
lat: 52.3752,
lng: 4.884,
title: "Anne Frank House",
icon: pinFor("Anne Frank"),
},
{ id: "hermitage", lat: 52.3654, lng: 4.9025, title: "Hermitage", icon: pinFor("Hermitage") },
{ id: "nemo", lat: 52.3738, lng: 4.9123, title: "NEMO Science Museum", icon: pinFor("NEMO") },
{ id: "eye", lat: 52.3843, lng: 4.9008, title: "Eye Filmmuseum", icon: pinFor("Eye") },
];
createMapLibreMap("#css-markers-maplibre-vanilla-map", { locations });
/**
* A pin of your own: one node for every state, which Maplace.js marks `data-hovered` and
* `data-selected`, so the page's CSS gives each state its look.
*/
function pinFor(label: string): HTMLElement {
const pin = document.createElement("span");
pin.className = "pin";
pin.textContent = label;
return pin;
}<!doctype html>
<!-- The page vanilla.ts runs on: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<script>
(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
key: "YOUR_KEY",
v: "weekly",
});
</script><style>
#css-markers-vanilla-map { height: 24rem; }
#css-markers-vanilla-map .pin {
display: inline-block;
padding: 0.25rem 0.625rem;
border: 2px solid #1d1d1b;
border-radius: 999px;
background: #fff;
color: #1d1d1b;
font: 600 0.8125rem/1.2 system-ui, sans-serif;
white-space: nowrap;
box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
cursor: pointer;
}
#css-markers-vanilla-map .pin[data-hovered] { transform: translateY(-3px); }
#css-markers-vanilla-map .pin[data-selected] {
border-color: #c62828;
background: #c62828;
color: #fff;
transform: scale(1.15);
}
@media (prefers-reduced-motion: no-preference) {
#css-markers-vanilla-map .pin[data-selected] { animation: css-markers-vanilla-pop 0.3s ease-out; }
}
@keyframes css-markers-vanilla-pop { from { transform: scale(0.85); } }
</style>
<div id="css-markers-vanilla-map"></div>
<script type="module" src="./vanilla.ts"></script>import type { Location } from "@maplacejs/maplace";
import { createGoogleMap } from "@maplacejs/maplace/google";
const locations: Location[] = [
{ id: "rijks", lat: 52.36, lng: 4.8852, title: "Rijksmuseum", icon: pinFor("Rijks") },
{
id: "anne-frank",
lat: 52.3752,
lng: 4.884,
title: "Anne Frank House",
icon: pinFor("Anne Frank"),
},
{ id: "hermitage", lat: 52.3654, lng: 4.9025, title: "Hermitage", icon: pinFor("Hermitage") },
{ id: "nemo", lat: 52.3738, lng: 4.9123, title: "NEMO Science Museum", icon: pinFor("NEMO") },
{ id: "eye", lat: 52.3843, lng: 4.9008, title: "Eye Filmmuseum", icon: pinFor("Eye") },
];
createGoogleMap("#css-markers-vanilla-map", { locations });
/**
* A pin of your own: one node for every state, which Maplace.js marks `data-hovered` and
* `data-selected`, so the page's CSS gives each state its look.
*/
function pinFor(label: string): HTMLElement {
const pin = document.createElement("span");
pin.className = "pin";
pin.textContent = label;
return pin;
}<!doctype html>
<!-- The page react.tsx renders into: what the module mounts on, and the module, which brings maplibre-gl and its stylesheet. -->
<style>
#css-markers-maplibre-react-root .map { height: 24rem; }
#css-markers-maplibre-react-root .pin {
display: inline-block;
padding: 0.25rem 0.625rem;
border: 2px solid #1d1d1b;
border-radius: 999px;
background: #fff;
color: #1d1d1b;
font: 600 0.8125rem/1.2 system-ui, sans-serif;
white-space: nowrap;
box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
cursor: pointer;
}
#css-markers-maplibre-react-root [data-hovered] > .pin { transform: translateY(-3px); }
#css-markers-maplibre-react-root [data-selected] > .pin {
border-color: #c62828;
background: #c62828;
color: #fff;
transform: scale(1.15);
}
@media (prefers-reduced-motion: no-preference) {
#css-markers-maplibre-react-root [data-selected] > .pin { animation: css-markers-maplibre-react-pop 0.3s ease-out; }
}
@keyframes css-markers-maplibre-react-pop { from { transform: scale(0.85); } }
</style>
<div id="css-markers-maplibre-react-root"></div>
<script type="module" src="./react.tsx"></script>import "maplibre-gl/dist/maplibre-gl.css";
import type { Location } from "@maplacejs/maplace";
import { createMapLibreAdapter } from "@maplacejs/maplace/maplibre";
import { MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
/** Your own field, in each location's `data`: its pin's label. */
interface Museum {
readonly pin: string;
}
const museums: Location<Museum>[] = [
{ id: "rijks", lat: 52.36, lng: 4.8852, title: "Rijksmuseum", data: { pin: "Rijks" } },
{
id: "anne-frank",
lat: 52.3752,
lng: 4.884,
title: "Anne Frank House",
data: { pin: "Anne Frank" },
},
{ id: "hermitage", lat: 52.3654, lng: 4.9025, title: "Hermitage", data: { pin: "Hermitage" } },
{ id: "nemo", lat: 52.3738, lng: 4.9123, title: "NEMO Science Museum", data: { pin: "NEMO" } },
{ id: "eye", lat: 52.3843, lng: 4.9008, title: "Eye Filmmuseum", data: { pin: "Eye" } },
];
/**
* A pin of your own, in a node Maplace.js keeps for each marker and marks `data-hovered` and
* `data-selected`, so the page's CSS gives each state its look (`[data-selected] > .pin`).
*/
const markerIcon = ({ data }: Location<Museum>) => <span className="pin">{data?.pin}</span>;
function CssMarkers() {
return (
<MaplaceProvider locations={museums}>
<MaplaceMap createAdapter={createMapLibreAdapter} className="map" markerIcon={markerIcon} />
</MaplaceProvider>
);
}
createRoot(document.getElementById("css-markers-maplibre-react-root") as HTMLElement).render(
<StrictMode>
<CssMarkers />
</StrictMode>,
);<!doctype html>
<!-- The page react.tsx renders into: Maps JS from Google's bootstrap loader, what the module mounts on, the module. -->Google's bootstrap loader, with your API key: from Google's docs
<script>
(g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once. Ignoring:",g):d[l]=(f,...n)=>r.add(f)&&u().then(()=>d[l](f,...n))})({
key: "YOUR_KEY",
v: "weekly",
});
</script><style>
#css-markers-react-root .map { height: 24rem; }
#css-markers-react-root .pin {
display: inline-block;
padding: 0.25rem 0.625rem;
border: 2px solid #1d1d1b;
border-radius: 999px;
background: #fff;
color: #1d1d1b;
font: 600 0.8125rem/1.2 system-ui, sans-serif;
white-space: nowrap;
box-shadow: 0 1px 4px rgb(0 0 0 / 30%);
cursor: pointer;
}
#css-markers-react-root [data-hovered] > .pin { transform: translateY(-3px); }
#css-markers-react-root [data-selected] > .pin {
border-color: #c62828;
background: #c62828;
color: #fff;
transform: scale(1.15);
}
@media (prefers-reduced-motion: no-preference) {
#css-markers-react-root [data-selected] > .pin { animation: css-markers-react-pop 0.3s ease-out; }
}
@keyframes css-markers-react-pop { from { transform: scale(0.85); } }
</style>
<div id="css-markers-react-root"></div>
<script type="module" src="./react.tsx"></script>import type { Location } from "@maplacejs/maplace";
import { createGoogleAdapter } from "@maplacejs/maplace/google";
import { MaplaceMap, MaplaceProvider } from "@maplacejs/maplace/react";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
/** Your own field, in each location's `data`: its pin's label. */
interface Museum {
readonly pin: string;
}
const museums: Location<Museum>[] = [
{ id: "rijks", lat: 52.36, lng: 4.8852, title: "Rijksmuseum", data: { pin: "Rijks" } },
{
id: "anne-frank",
lat: 52.3752,
lng: 4.884,
title: "Anne Frank House",
data: { pin: "Anne Frank" },
},
{ id: "hermitage", lat: 52.3654, lng: 4.9025, title: "Hermitage", data: { pin: "Hermitage" } },
{ id: "nemo", lat: 52.3738, lng: 4.9123, title: "NEMO Science Museum", data: { pin: "NEMO" } },
{ id: "eye", lat: 52.3843, lng: 4.9008, title: "Eye Filmmuseum", data: { pin: "Eye" } },
];
/**
* A pin of your own, in a node Maplace.js keeps for each marker and marks `data-hovered` and
* `data-selected`, so the page's CSS gives each state its look (`[data-selected] > .pin`).
*/
const markerIcon = ({ data }: Location<Museum>) => <span className="pin">{data?.pin}</span>;
function CssMarkers() {
return (
<MaplaceProvider locations={museums}>
<MaplaceMap createAdapter={createGoogleAdapter} className="map" markerIcon={markerIcon} />
</MaplaceProvider>
);
}
createRoot(document.getElementById("css-markers-react-root") as HTMLElement).render(
<StrictMode>
<CssMarkers />
</StrictMode>,
);How it works
Each pin is a node of yours, styled by the page’s CSS: Maplace.js marks it data-hovered while the reader points at it and data-selected once they pick it, so a rule on each attribute gives that state its look.
- HTML: a
<template data-icon>inside each<maplace-location>(Location attributes). The template is drawn anew for each state, so the pop is a CSS animation, which starts on a new node, rather than a transition; pointing at a selected pin plays it again. - Script and Bundler: an
iconthat is a node, the same node in every state (Icons). - React:
markerIconon<MaplaceMap>, whose output sits in a node Maplace.js keeps for each marker; that node carries the marks, so the rules read[data-selected] > .pinwhere the others read.pin[data-selected](<MaplaceMap>). - Styling: every class and attribute Maplace.js’s markup carries, in Styling.