CSSFontFeatureValuesMap

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The CSSFontFeatureValuesMap interface of the CSS Object Model (CSSOM) represents an iterable and read-only set of the CSSFontFeatureValuesRule properties, such as swash, annotation, ornaments, etc.

An CSSFontFeatureValuesMap instance is a read-only Map-like object, in which each key is the user-defined name used to reference a font feature, and the corresponding value is the index for the font feature within the font.

Instance properties

CSSFontFeatureValuesMap.size

Returns a positive integer containing the size of the CSSFontFeatureValuesMap object.

Instance methods

CSSFontFeatureValuesMap.clear()

Removes all declarations in the CSSFontFeatureValuesMap.

CSSFontFeatureValuesMap.delete()

Removes the CSS declaration with the given property in the CSSFontFeatureValuesMap.

CSSFontFeatureValuesMap.entries()

Returns a new map iterator object that contains the [key, value] pairs for each declaration in this CSSFontFeatureValuesMap in insertion order.

CSSFontFeatureValuesMap.forEach()

Executes a provided function once per each key/value pair in this CSSFontFeatureValuesMap in insertion order.

CSSFontFeatureValuesMap.get()

Returns value corresponding to the key in this CSSFontFeatureValuesMap, or undefined if there is none.

CSSFontFeatureValuesMap.has()

Returns a boolean indicating whether an entry with the specified key exists in this CSSFontFeatureValuesMap or not.

CSSFontFeatureValuesMap.keys()

Returns a new map iterator object that contains the key for each declaration in this CSSFontFeatureValuesMap in insertion order.

CSSFontFeatureValuesMap.set()

Adds a new entry with a specified key and value to this CSSFontFeatureValuesMap, or updates an existing entry if the key already exists.

CSSFontFeatureValuesMap.values()

Returns a new map iterator object that contains the value for each declaration in this CSSFontFeatureValuesMap in insertion order.

CSSFontFeatureValuesMap.[Symbol.iterator]()

Returns the iterator object itself. This allows iterator objects to also be iterable.

Examples

Logging user-defined names

This example shows how you can log the user-defined names (and their mapped index) stored in a CSSFontFeatureValuesMap (for particular CSSFontFeatureValuesRule properties).

CSS

First we declare a @font-feature-values for the Font One font family. This includes the declaration of the names "nice-style" and "odd-style" that can be used to represent the styleset alternate glyphs for Font One and specify the index values for those alternates. It also includes the declaration of the name "swishy" that can be used to represent the swash alternate glyphs for Font One and specify the index for that alternate.

The "nice-style" alternate glyphs are then applied for any .nice-look class, using font-variant-alternates property and passing the name to the styleset() function. The same is done for the name "swishy" for the swash alternate glyphs, which is then passed to the swash() function. The "odd-style" glyphs are not used (they are just added to demonstrate that multiple values may be defined in the map.)

css
/* At-rule for "nice-style", "odd-style", and "swishy" in Font One */
@font-feature-values Font One {
  @styleset {
    nice-style: 12; /* name used to represent the alternate set of glyphs at index 12 */
    odd-style: 10; /* name used to represent the alternate set of glyphs at index 10 */
  }
  @swash {
    swishy: 1; /* name used to represent the alternate set of glyphs at index 1 */
  }
}

/* Apply the at-rules to the appropriate selectors */
.nice-look {
  font-variant-alternates: styleset(nice-style);
}
.swoosh {
  font-variant-alternates: swash(swishy);
}

JavaScript

The code below finds the corresponding CSSFontFeatureValuesRule for the CSS @font-feature-values at-rule added above. It then iterates the values of the styleset and swash properties, which are represented by CSSFontFeatureValuesMap instances, using the forEach() method. On each step it logs the user-defined names and index values.

js
const logElement = document.querySelector("#log");
function log(text) {
  logElement.innerText = `${logElement.innerText}${text}\n`;
  logElement.scrollTop = logElement.scrollHeight;
}
js
const rules = document.querySelector("#css-output").sheet.cssRules;
const fontOne = rules[0]; // A CSSFontFeatureValuesRule
if (fontOne.styleset) {
  // styleset property is supported
  log(
    "The user has defined the following name(s)/index(s) for CSSFontFeatureValuesRule.styleset:",
  );
  fontOne.styleset.forEach((value, key) => log(` ${key} : ${value}`));
} else {
  log("Browser does not support CSSFontFeatureValuesMap.styleset property.");
}

if (fontOne.swash) {
  log(
    "The user has defined the following name(s)/index(s) for CSSFontFeatureValuesRule.swash:",
  );
  fontOne.swash.forEach((value, key) => log(` ${key} : ${value}`));
} else {
  log("Browser does not support CSSFontFeatureValuesMap.swash property.");
}

Result

Specifications

Specification
CSS Fonts Module Level 4
# cssfontfeaturevaluesmap

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
CSSFontFeatureValuesMap
Experimental
Chrome – Full support
Chrome 111 (Release date: 2023-03-07)
footnote Full support
Edge – Full support
Edge 111 (Release date: 2023-03-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 97 (Release date: 2023-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 111 (Release date: 2023-03-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 75 (Release date: 2023-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 22 (Release date: 2023-07-14)
footnote Full support
WebView Android – Full support
WebView Android 111 (Release date: 2023-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
@@iterator
Experimental
Chrome – Full support
Chrome 111 (Release date: 2023-03-07)
footnote Full support
Edge – Full support
Edge 111 (Release date: 2023-03-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 97 (Release date: 2023-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 111 (Release date: 2023-03-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 75 (Release date: 2023-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 22 (Release date: 2023-07-14)
footnote Full support
WebView Android – Full support
WebView Android 111 (Release date: 2023-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
clear
Experimental
Chrome – Full support
Chrome 111 (Release date: 2023-03-07)
footnote Full support
Edge – Full support
Edge 111 (Release date: 2023-03-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 97 (Release date: 2023-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 111 (Release date: 2023-03-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 75 (Release date: 2023-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 22 (Release date: 2023-07-14)
footnote Full support
WebView Android – Full support
WebView Android 111 (Release date: 2023-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
delete
Experimental
Chrome – Full support
Chrome 111 (Release date: 2023-03-07)
footnote Full support
Edge – Full support
Edge 111 (Release date: 2023-03-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 97 (Release date: 2023-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 111 (Release date: 2023-03-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 75 (Release date: 2023-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 22 (Release date: 2023-07-14)
footnote Full support
WebView Android – Full support
WebView Android 111 (Release date: 2023-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
entries
Experimental
Chrome – Full support
Chrome 111 (Release date: 2023-03-07)
footnote Full support
Edge – Full support
Edge 111 (Release date: 2023-03-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 97 (Release date: 2023-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 111 (Release date: 2023-03-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 75 (Release date: 2023-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 22 (Release date: 2023-07-14)
footnote Full support
WebView Android – Full support
WebView Android 111 (Release date: 2023-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
forEach
Experimental
Chrome – Full support
Chrome 111 (Release date: 2023-03-07)
footnote Full support
Edge – Full support
Edge 111 (Release date: 2023-03-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 97 (Release date: 2023-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 111 (Release date: 2023-03-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 75 (Release date: 2023-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 22 (Release date: 2023-07-14)
footnote Full support
WebView Android – Full support
WebView Android 111 (Release date: 2023-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
get
Experimental
Chrome – Full support
Chrome 111 (Release date: 2023-03-07)
footnote Full support
Edge – Full support
Edge 111 (Release date: 2023-03-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 97 (Release date: 2023-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 111 (Release date: 2023-03-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 75 (Release date: 2023-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 22 (Release date: 2023-07-14)
footnote Full support
WebView Android – Full support
WebView Android 111 (Release date: 2023-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
has
Experimental
Chrome – Full support
Chrome 111 (Release date: 2023-03-07)
footnote Full support
Edge – Full support
Edge 111 (Release date: 2023-03-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 97 (Release date: 2023-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 111 (Release date: 2023-03-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 75 (Release date: 2023-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 22 (Release date: 2023-07-14)
footnote Full support
WebView Android – Full support
WebView Android 111 (Release date: 2023-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
keys
Experimental
Chrome – Full support
Chrome 111 (Release date: 2023-03-07)
footnote Full support
Edge – Full support
Edge 111 (Release date: 2023-03-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 97 (Release date: 2023-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 111 (Release date: 2023-03-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 75 (Release date: 2023-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 22 (Release date: 2023-07-14)
footnote Full support
WebView Android – Full support
WebView Android 111 (Release date: 2023-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
set
Experimental
Chrome – Full support
Chrome 111 (Release date: 2023-03-07)
footnote Full support
Edge – Full support
Edge 111 (Release date: 2023-03-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 97 (Release date: 2023-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 111 (Release date: 2023-03-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 75 (Release date: 2023-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 22 (Release date: 2023-07-14)
footnote Full support
WebView Android – Full support
WebView Android 111 (Release date: 2023-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
size
Experimental
Chrome – Full support
Chrome 111 (Release date: 2023-03-07)
footnote Full support
Edge – Full support
Edge 111 (Release date: 2023-03-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 97 (Release date: 2023-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 111 (Release date: 2023-03-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 75 (Release date: 2023-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 22 (Release date: 2023-07-14)
footnote Full support
WebView Android – Full support
WebView Android 111 (Release date: 2023-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
values
Experimental
Chrome – Full support
Chrome 111 (Release date: 2023-03-07)
footnote Full support
Edge – Full support
Edge 111 (Release date: 2023-03-13)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 97 (Release date: 2023-03-22)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 111 (Release date: 2023-03-07)
footnote Full support
Firefox for Android – No support
Firefox for Android
footnote No support
Opera Android – Full support
Opera Android 75 (Release date: 2023-05-17)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 22 (Release date: 2023-07-14)
footnote Full support
WebView Android – Full support
WebView Android 111 (Release date: 2023-03-01)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.

See also