web api interface
CSSFontFaceRule
The CSSFontFaceRule interface represents an @font-face at-rule.
Instance properties
Inherits properties from its ancestor CSSRule.
styleRead only- : Returns a
CSSFontFaceDescriptorsobject that allows reading and setting the descriptors of the associated@font-faceat-rule.
- : Returns a
Instance methods
Inherits methods from its ancestor CSSRule.
Examples
Accessing @font-face properties
This example defines a @font-face rule and then iterates over the rules on the page until the associated CSSFontFaceRule is found.
It then logs some of the properties.
CSS
@font-face {
font-family: "MyHelvetica";
src:
local("Helvetica Neue Bold"), local("HelveticaNeue-Bold"),
url("MgOpenModernaBold.woff2");
font-weight: bold;
}
#log {
height: 200px;
overflow: scroll;
padding: 0.5rem;
border: 1px solid black;
}
<pre id="log"></pre>
JavaScript
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) {
log(`this: ${rule}`);
log(` cssText: ${rule.cssText}`);
log(` parentRule: ${rule.parentRule}`);
log(` parentStyleSheet: ${rule.parentStyleSheet}`);
log(` type: ${rule.type}`);
log(` style: ${rule.style}`);
}
}
Result
Interactive exampleOpen the canonical MDN source to run this embedded demo.
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.