Skip to content

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

License

Notifications You must be signed in to change notification settings

openlayers/mapbox-to-css-font

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Mar 31, 2025
b7a8c9b · Mar 31, 2025

History

74 Commits
Jul 17, 2024
Jul 17, 2024
Mar 11, 2019
Mar 31, 2025
Mar 31, 2025
Mar 9, 2019
Jul 17, 2024
Jul 17, 2024
Mar 31, 2025
Mar 31, 2025
Jul 17, 2024

Repository files navigation

Mapbox to CSS Font

Utility to convert Mapbox 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.

The "Klokantech Noto Sans" font is recognized and returned as "Noto Sans", so it can be loaded as web font from Google fonts.

Usage

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|Array<string> Mapbox GL Style fontstack or single font, e.g. ['Open Sans Regular', 'Arial Unicode MS Regular'] or 'Open Sans Regular'.

  • size number Font size in pixels.

  • lineHeight string|number Line height as css line-height. Optional.

Returns string CSS font definition, e.g. 'normal 400 16px/1.2 "Open Sans"'.