How to Create a Mapbox Access Token
Official Mapbox Pages
Steps to Create a Mapbox Access Token
- Sign in to your Mapbox account.
- Open your Access Tokens page in the Mapbox account dashboard.
- You will already see a default public token available in your account.
- To create a new token, click Create a token.
- Enter a name for the token so you can identify where it will be used.
- Select the required scopes for the token.
- For most frontend map applications, a public token is used.
- Public tokens usually start with
pk.
- Secret tokens usually start with
sk and should only be used on the server side.
- Save or create the token.
- Copy the token and store it securely.
Token Types
- Public token (
pk)
Use this in websites, browser apps, and mobile apps.
- Secret token (
sk)
Use this only in backend or server-side applications.
- Temporary token (
tk)
Can be created programmatically for short-lived access through the Tokens API.
Important Recommendations
- Create separate tokens for different environments such as:
- local development
- testing
- production
- Only enable the minimum scopes required.
- Never expose a secret token in frontend code.
- If a token is exposed publicly and you suspect misuse, rotate it by creating a new one and deleting the old one.
Example for Mapbox GL JS
<script src="https://api.mapbox.com/mapbox-gl-js/v3.15.0/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v3.15.0/mapbox-gl.css" rel="stylesheet" />
<script>
mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v12',
center: [77.2090, 28.6139],
zoom: 10
});
</script>
Notes
- Every request to Mapbox APIs requires an access token.
- Your account includes a default public token by default.
- For advanced automation, you can create and manage tokens using the Tokens API.