大网数据广告活动
Web 标准与前端开发

CSSFontFaceDescriptors

· 52CE 我爱测

The **`CSSFontFaceDescriptors`** interface represents a CSS declaration block for an @font-face at-rule.

CSSOM

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.

Instance properties

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 fontDisplay
    • : A string representing the value of the @font-face/font-display descriptor.
  • font-family or fontFamily
    • : A string representing the value of the @font-face/font-family descriptor.
  • font-feature-settings or fontFeatureSettings
    • : A string representing the value of the @font-face/font-feature-settings descriptor.
  • font-stretch or fontStretch
    • : A string representing the value of the @font-face/font-stretch descriptor.
  • font-style or fontStyle
    • : A string representing the value of the @font-face/font-style descriptor.
  • font-weight or fontWeight
    • : A string representing the value of the @font-face/font-weight descriptor.
  • font-width or fontWidth
    • : A string representing the value of the @font-face/font-width descriptor.
  • size-adjust or sizeAdjust
    • : A string representing the value of the @font-face/size-adjust descriptor.
  • src
    • : A string representing the value of the @font-face/src descriptor.
  • unicode-range or unicodeRange
    • : A string representing the value of the @font-face/unicode-range descriptor.

Instance methods

No specific methods; inherits methods from its ancestor CSSStyleDeclaration.

Examples

Accessing @font-face descriptor values

This example defines a @font-face rule and then uses CSSFontFaceDescriptors to read back the descriptor values.

CSS

@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;
}

JavaScript

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"]}`);
  }
}

Result

Accessing @font-face descriptor values

Specifications

Browser compatibility

See also

  • CSSFontFaceRule
  • CSSFontFaceRule.style
  • @font-face

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。