The CSSFontFaceDescriptors interface represents a CSS declaration block for an @font-face at-rule.
Each descriptor in the body of the corresponding @font-face at-rule can be accessed using either its kebab-case property name in bracket notation or the camel-case version of the property name in dot notation. For example, you can access the font-family CSS descriptor as style["font-family"] or style.fontFamily, where style is a CSSFontFaceDescriptors instance.
Note: The CSSFontFaceRule interface represents a @font-face at-rule, and the CSSFontFaceRule.style property is an instance of this object.
Inherits properties from its ancestor CSSStyleDeclaration.
The following property names, in kebab-case (accessed using bracket notation) and camel-case (accessed using dot notation), each represent the value of a descriptor in the corresponding @font-face at-rule:
font-display or fontDisplayA string representing the value of the font-display descriptor.
font-family or fontFamilyA string representing the value of the font-family descriptor.
font-feature-settings or fontFeatureSettingsA string representing the value of the font-feature-settings descriptor.
font-stretch or fontStretchA string representing the value of the font-stretch descriptor.
font-style or fontStyleA string representing the value of the font-style descriptor.
font-weight or fontWeightA string representing the value of the font-weight descriptor.
font-width or fontWidth A string representing the value of the font-width descriptor.
size-adjust or sizeAdjustA string representing the value of the size-adjust descriptor.
srcA string representing the value of the src descriptor.
unicode-range or unicodeRangeA string representing the value of the unicode-range descriptor.
No specific methods; inherits methods from its ancestor CSSStyleDeclaration.
This example defines a @font-face rule and then uses CSSFontFaceDescriptors to read back the descriptor values.
@font-face {
font-family: "MyHelvetica";
src:
local("Helvetica Neue Bold"),
local("HelveticaNeue-Bold"),
url("MgOpenModernaBold.woff2") format("woff2");
font-weight: bold;
font-style: normal;
font-display: swap;
}const myRules = document.getElementById("css-output").sheet.cssRules;
for (const rule of myRules) {
if (rule instanceof CSSFontFaceRule) {
const style = rule.style; // a CSSFontFaceDescriptors
log(`font-family: ${style.fontFamily}`);
log(`src: ${style.src}`);
log(`font-weight: ${style["font-weight"]}`);
log(`font-style: ${style.fontStyle}`);
log(`font-display: ${style["font-display"]}`);
}
}