---
title: "Get started with Leaflet | Leaflet"
description: "Quickly get started with Leaflet JS web mapping library."
---

> For AI agents: a documentation index is available at [/llms.txt](https://docs.maptiler.com/llms.txt). Markdown versions of all pages are available by appending .md to any URL.

# Get started with Leaflet

This Quickstart Leaflet example is the easiest and fastest way to use your MapTiler maps in Leaflet JS. Simply use the code below the map.

1.  Copy the following code, paste it into your favorite text editor, and save it as a `.html` file.
    
    ```html
    <!DOCTYPE html>
     <html>
       <head>
         <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
         <title>Display a map</title>
         <link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
         <script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
         <style>
           #map {position: absolute; top: 0; right: 0; bottom: 0; left: 0;}
         </style>
       </head>
       <body>
         <div id="map">
           <a href="https://www.maptiler.com" style="position:absolute;left:10px;bottom:10px;z-index:999;"><img src="https://api.maptiler.com/resources/logo.svg" alt="MapTiler logo"></a>
         </div>
         <p><a href="https://www.maptiler.com/copyright/" target="_blank" rel="noopener">&copy; MapTiler</a> <a href="https://www.openstreetmap.org/copyright" target="_blank" rel="noopener">&copy; OpenStreetMap contributors</a></p>
         <script>
           const key = 'YOUR_MAPTILER_API_KEY_HERE';
           const map = L.map('map').setView([49.2125578, 16.62662018], 14); //starting position
           L.tileLayer(`https://api.maptiler.com/maps/streets-v4/{z}/{x}/{y}.png?key=${key}`,{ //style URL
             tileSize: 512,
             zoomOffset: -1,
             minZoom: 1,
             attribution: "\u003ca href=\"https://www.maptiler.com/copyright/\" target=\"_blank\"\u003e\u0026copy; MapTiler\u003c/a\u003e \u003ca href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\"\u003e\u0026copy; OpenStreetMap contributors\u003c/a\u003e",
             crossOrigin: true
           }).addTo(map);
         </script>
       </body>
     </html>
    ```
    

1.  Install the npm package.
    
    ```bash
    npm install --save leaflet
    ```
    
2.  Include the CSS file.
    
    If you have a bundler that can handle CSS, you can [`import`](#) the CSS or include it with a [`<link>`](#) in the head of the document via the CDN
    
    ```js
    import "leaflet/dist/leaflet.css";
    ```
    
    ```html
    <link href='https://unpkg.com/leaflet@1.9.4/dist/leaflet.css' rel='stylesheet' />
    ```
    
3.  Include the following code in your JavaScript file (Example: main.js).
    
    ```js
    import L from 'leaflet';
        
    const key = 'YOUR_MAPTILER_API_KEY_HERE';
    const map = L.map('map').setView([49.2125578, 16.62662018], 14); //starting position
    L.tileLayer(`https://api.maptiler.com/maps/streets-v4/{z}/{x}/{y}.png?key=${key}`,{ //style URL
      tileSize: 512,
      zoomOffset: -1,
      minZoom: 1,
      attribution: "\u003ca href=\"https://www.maptiler.com/copyright/\" target=\"_blank\"\u003e\u0026copy; MapTiler\u003c/a\u003e \u003ca href=\"https://www.openstreetmap.org/copyright\" target=\"_blank\"\u003e\u0026copy; OpenStreetMap contributors\u003c/a\u003e",
      crossOrigin: true
    }).addTo(map);
    ```
    

1.  Replace `YOUR_MAPTILER_API_KEY_HERE` with [your own API key](https://cloud.maptiler.com/account/keys/). Make sure to [secure the key](https://docs.maptiler.com/guides/credentials/api-key/#secure-key) before you publish it.
    
2.  The next is up to you. You can center your map wherever you desire (modifying the `starting position`) and set an appropriate zoom level (modifying the `starting zoom`) to match your users’ needs. Additionally, you can change the map’s look (by updating the `source URL`); choose from a range of visually appealing map styles from our extensive [MapTiler standard maps](https://cloud.maptiler.com/maps/), or create your own to truly differentiate your application.
    

## Learn more

If you want to learn how to initialize a map and load the style see the [How to use Leaflet JS](../how-to-use-leaflet/) tutorial.

## Related examples

### [How to use Leaflet](https://docs.maptiler.com/leaflet/examples/how-to-use-leaflet/)

Tutorials

Create and display Leaflet maps on web pages with MapTiler.

### [Display Marker](https://docs.maptiler.com/leaflet/examples/default-marker/)

Tutorials

Add default map markers using Leaflet JS web mapping library.

### [Vector Tiles in Leaflet](https://docs.maptiler.com/leaflet/examples/vector-tiles-in-leaflet-js/)

Tutorials

Display MapTiler vector tiles in Leaflet using maptilersdk plugin.
