Create markers from HTML

Use L.divIcon to create custom HTML markers.

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Create markers from HTML</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox.js/v2.1.5/mapbox.css' rel='stylesheet' />
<style>
  body { margin:0; padding:0; }
  #map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<style>
/*
 * Unlike other icons, you can style `L.divIcon` with CSS.
 * These styles make each marker a pink triangle.
 */
.css-icon {
  width: 0;
  height: 0;
  border-top: 30px solid transparent;
  border-bottom: 30px solid transparent;
  border-left: 30px solid #ff8888;
  }
</style>
<div id='map'></div>
<script>
L.mapbox.accessToken = '<your access token here>';
var map = L.mapbox.map('map', 'examples.map-i86nkdio')
    .setView([0, 0], 2);

// Define an icon called cssIcon
var cssIcon = L.divIcon({
  // Specify a class name we can refer to in CSS.
  className: 'css-icon',
  // Set marker width and height
  iconSize: [60, 60]
});

// Create three markers and set their icons to cssIcon
L.marker([45, 45], {icon: cssIcon}).addTo(map);
L.marker([0, 0], {icon: cssIcon}).addTo(map);
L.marker([-45, -45], {icon: cssIcon}).addTo(map);
</script>
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