Skip to main content

Installation

Before you get started with Mapbox Search JS, you need to have an access token. Add Mapbox Search JS to your project using either the Mapbox CDN or relevant NPM packages.

Account requirements

To use Mapbox Search JS, you need to have a Mapbox access token.

This access token associates your search requests with a Mapbox account for billing. For more information on creating and using access tokens, see our token management documentation.

Quickstart

To use Mapbox Search JS in your project, you need to import it using either the Mapbox CDN or relevant NPM packages.

Web

Include the following code in the <head> of your HTML file.


<script id="search-js" defer src="https://api.mapbox.com/search-js/v1.0.0-beta.19/web.js"></script>
<script>
undefinedconst accessToken = 'undefined';

const script = document.getElementById('search-js');
script.onload = function() {
mapboxsearch.autofill({
accessToken
});
};
</script>

React

Search JS React is not available on the Mapbox CDN. If you're using React, you can install the NPM package by selecting "Module bundler" above.

Core

Installing Core is not required to use Web. This is only necessary if you wish to call the framework directly without a user interface.

Include the following code in the <head> of your HTML file.


<script src="https://api.mapbox.com/search-js/v1.0.0-beta.19/core.js"></script>
<script>
const {
MapboxSearch,
SearchSession
} = mapboxsearchcore;

undefinedconst search = new MapboxSearch({
accessToken: 'undefined'
})

const session = new SearchSession(search);
</script>

Browser support

Mapbox Search JS is supported in most modern browsers. We officially support:

  • Versions of Google Chrome, Mozilla Firefox, and Microsoft Edge (Chromium)
  • Safari, Mobile Safari 12.0 or higher

Mapbox Search JS is not compatible with any version of Internet Explorer.

If these constraints do not work for your project, consider using Mapbox GL Geocoder or accessing Mapbox Search APIs directly.

Transpiling

Mapbox Search JS is distributed as an ES6 compatible JavaScript bundle.

Was this page helpful?