MapSnippets logo MapSnippets logo

Add Markers and Popups to a Leaflet Map

Leaflet

Place a marker on a Leaflet map with L.marker() and attach an HTML popup to it with bindPopup(), opened when the user clicks the pin.

progress_activity Loading map...
const map = L.map('map').setView([48.8566, 2.3522], 13);
L.tileLayer('https://api.maptiler.com/maps/streets-v4/256/{z}/{x}/{y}.png?key=YOUR_MAPTILER_KEY', {
  tileSize: 256,
  attribution: '&copy; <a href="https://www.maptiler.com/">MapTiler</a> &copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap contributors</a>'
}).addTo(map);
L.marker([48.8584, 2.2945]).addTo(map).bindPopup('<strong>Eiffel Tower</strong><br>Champ de Mars, Paris');
L.marker([48.8606, 2.3376]).addTo(map).bindPopup('<strong>Louvre Museum</strong><br>Rue de Rivoli, Paris');
L.marker([48.8530, 2.3499]).addTo(map).bindPopup('<strong>Notre-Dame</strong><br>Île de la Cité, Paris');

How to add a marker with a popup in Leaflet

L.marker() creates a marker at the given [lat, lng] coordinates and adds it to the map with .addTo(map). Each marker can have a popup attached via .bindPopup(), which accepts an HTML string for rich content like bold text, links, or images.

Popups open when the user clicks the marker. You can also call .openPopup() to show it programmatically. By default only one popup is open at a time, so clicking a different marker closes the previous one.

Key APIs

API Description Docs
L.marker() Create a marker leafletjs.com/reference.html#marker
.bindPopup() Attach popup to layer leafletjs.com/reference.html#layer-bindpopup
.openPopup() Open popup programmatically leafletjs.com/reference.html#layer-openpopup

FAQ

How do I use a custom marker icon?

Pass an L.icon() instance in the marker options: L.marker([lat, lng], { icon: L.icon({ iconUrl: 'pin.png', iconSize: [25, 41] }) }).

Can I have multiple popups open at the same time?

Yes. Set autoClose: false and closeOnClick: false in the popup options: .bindPopup('text', { autoClose: false, closeOnClick: false }).

Common mistakes

  • Using [lng, lat] instead of [lat, lng]. Leaflet’s coordinate order is the opposite of GeoJSON.
  • Forgetting .addTo(map), so the marker is created but never added to the map
  • Putting unescaped quotes in popup HTML. Use single quotes inside double-quoted strings or vice versa.

Build maps using Leaflet with AI

Generate code like this add markers and popups to a leaflet map example using the Leaflet skill in your IDE.