files/en-us/web/api/cssfontfacedescriptors/index.md
{{APIRef("CSSOM")}}{{SeeCompatTable}}
The CSSFontFaceDescriptors interface represents a CSS declaration block for an {{cssxref("@font-face")}} at-rule.
Each descriptor in the body of the corresponding {{cssxref("@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 {{domxref("CSSFontFaceRule")}} interface represents a {{cssxref("@font-face")}} at-rule, and the {{domxref("CSSFontFaceRule.style")}} property is an instance of this object.
{{InheritanceDiagram}}
Inherits properties from its ancestor {{domxref("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 fontDisplay {{experimental_inline}}
font-family or fontFamily {{experimental_inline}}
font-feature-settings or fontFeatureSettings {{experimental_inline}}
font-stretch or fontStretch {{experimental_inline}}
font-style or fontStyle {{experimental_inline}}
font-weight or fontWeight {{experimental_inline}}
font-width or fontWidth {{experimental_inline}}
size-adjust or sizeAdjust {{experimental_inline}}
src {{experimental_inline}}
unicode-range or unicodeRange {{experimental_inline}}
No specific methods; inherits methods from its ancestor {{domxref("CSSStyleDeclaration")}}.
This example defines a {{cssxref("@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;
}
#log {
height: 200px;
overflow: scroll;
padding: 0.5rem;
border: 1px solid black;
}
<pre id="log"></pre>
const logElement = document.querySelector("#log");
function log(text) {
logElement.innerText = `${logElement.innerText}${text}\n`;
logElement.scrollTop = logElement.scrollHeight;
}
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"]}`);
}
}
{{EmbedLiveSample("Accessing @font-face descriptor values", "100%", "250px")}}
{{Specifications}}
{{Compat}}