Mapbox.js is no longer in active development. To learn more about our newer mapping tools see Mapbox GL JS.

Custom tooltip

Define custom HTML for popups from marker properties.

<!DOCTYPE html>
<meta charset=utf-8 />
<title>Custom tooltip</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v3.3.1/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v3.3.1/mapbox.css' rel='stylesheet' />
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
<div id='map'></div>

L.mapbox.accessToken = '<your access token here>';
var map = L.mapbox.map('map')
    .setView([49.16326, -123.89187], 17)

var featureLayer = L.mapbox.featureLayer({
        type: 'FeatureCollection',
        features: [{
            type: 'Feature',
            properties: {
                'from': 'Duke Point',
                'to': 'Tsawwassen',
                'marker-color': '#548cba',
                'marker-size': 'large',
                'marker-symbol': 'ferry'
            geometry: {
                type: 'Point',
                coordinates: [-123.89128804206847, 49.16351524490678]

// Note that calling `.eachLayer` here depends on setting GeoJSON _directly_
// above. If you're loading GeoJSON asynchronously, like from CSV or from a file,
// you will need to do this within a `featureLayer.on('ready'` event.
featureLayer.eachLayer(function(layer) {

    // here you call `bindPopup` with a string of HTML you create - the feature
    // properties declared above are available under `layer.feature.properties`
    var content = '<h2>A ferry ride!<\/h2>' +
        '<p>From: ' + layer.feature.properties.from + '<br \/>' +
        'to: ' + layer.feature.properties.to + '<\/p>';
to create your own custom map and use it in this example.
Use this example by copying its source into your own HTML page and replacing the Map ID with one of your own from your projects. Having trouble with JavaScript? Try out Codecademy or contact our support team.
Copy example