# mapbox-to-css-font

> Utility to convert Mapbox GL Style font names to CSS font definitions

Latest version **3.2.1** (published 2026-09-09) · BSD-2-Clause license · 0 weekly downloads

## Install

```sh
npm install mapbox-to-css-font
pnpm add mapbox-to-css-font
yarn add mapbox-to-css-font
bun add mapbox-to-css-font
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.2.1 |
| Published | 2026-09-09 |
| First published | 2016-09-30 |
| Weekly downloads | 0 |
| License | BSD-2-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Andreas Hocevar |
| Maintainers | ahocevar |
| Keywords | mapbox, maplibre, font |

## Links

- npm: https://www.npmjs.com/package/mapbox-to-css-font
- Repository: https://github.com/openlayers/mapbox-to-css-font
- Homepage: https://github.com/openlayers/mapbox-to-css-font#readme
- Issues: https://github.com/openlayers/mapbox-to-css-font/issues
- npm.io page: https://npm.io/package/mapbox-to-css-font

## Alternatives

- [@fortawesome/react-fontawesome](https://npm.io/package/@fortawesome/react-fontawesome.md) — 2.2M weekly downloads
- [roboto-fontface](https://npm.io/package/roboto-fontface.md) — 196.0K weekly downloads
- [@react-native-vector-icons/common](https://npm.io/package/@react-native-vector-icons/common.md) — 150.4K weekly downloads
- [@procore/core-icons](https://npm.io/package/@procore/core-icons.md) — 4.6K weekly downloads
- [@react-md/material-icons](https://npm.io/package/@react-md/material-icons.md) — 1.6K weekly downloads

## Recent versions

- 3.2.1 (latest) — 2026-09-09
- 3.2.0 — 2025-05-15
- 3.1.2 — 2025-05-13
- 3.1.1 — 2025-05-13
- 3.1.0 — 2025-05-13
- 3.0.3 — 2025-03-31
- 3.0.2 — 2024-07-17
- 3.0.1 — 2024-07-17
- 3.0.0 — 2024-07-17
- 2.4.5 — 2024-07-11
- 2.4.4 — 2024-02-10
- 2.4.3 — 2024-02-10
- 2.4.2 — 2023-01-09
- 2.4.1 — 2022-01-18
- 2.4.0 — 2019-07-04
- … 12 more at https://npm.io/package/mapbox-to-css-font/versions

## README

# Mapbox/MapLibre to CSS Font

Utility to convert Mapbox/MapLibre GL Style fontstacks or fonts names to CSS compatible font definitions.

For fontstacks, the style and weight of the primary font (first font in the fontstack) will also be used for the fallback fonts.

Fonts commonly found in Mapbox/MapLibre styles, which are not available as systm fonts or free fonts on [Fontsource](https://fontsource.org/) or [Google Fonts](https://fonts.google.com/), will be replaced with a close match:

| Mapbox/MapLibre Font Name | Replacement Font Name |
|---------------------------|-----------------------|
| Arial Unicode MS          | Arial                 |
| DIN Pro                   | Barlow                |
| Klokantech Noto Sans      | Noto Sans             |

## Usage

```js
import parseFont from 'mapbox-to-css-font';

parseFont('Open Sans Regular', 16, 1.2);
// returns 'normal 400 16px/1.2 "Open Sans"'
```

## API

**Parameters**

-  `fonts` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)|[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)>** Mapbox GL Style fontstack or single font, e.g. `['Open Sans Regular', 'Arial Unicode MS Regular']` or `'Open Sans Regular'`.

-  `size` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Font size in pixels.

- `lineHeight` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)|[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Line height as css [line-height](https://developer.mozilla.org/en-US/docs/Web/CSS/line-height). Optional.

Returns **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** CSS font definition, e.g. `'normal 400 16px/1.2 "Open Sans"'`.

---
_Source: https://npm.io/package/mapbox-to-css-font · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
