CKTIS / CSS
@font-face — defining a font source
The @font-face rule registers a font face and its descriptors so the browser can match and load the proper resource.
Version: CSS modules; structured CSSWG indexes reconciled with pinned MDN BCD; Chromium 152 scope gate, per-example verification still required
Syntax
@font-face { <font-face-descriptor-list> }@font-face describes one font face. The font-family and src descriptors give it a name and ordered source list; font-style, font-weight, unicode-range, and font-display constrain matching and loading. These are rule descriptors, not properties inherited by elements.
The example exposes local("Arial") as LocalProbe, applies it to text, and requests the matching face through FontFaceSet. Its result confirms a loaded font, a CSSFontFaceRule object, and a metric change from monospace, exercising selection and use rather than parser retention alone.
Entries in src are tried in order; an unsupported format, CORS failure, or failed download advances to the next source. unicode-range can split a family into subsets, while a synthetic face can appear when no described face matches the requested style or weight. font-display changes block and swap timing but cannot repair an unavailable file.
Inside src, format() is an optional format hint attached to a url() source. If the named format is unsupported, the user agent skips that source without downloading it; without the hint, it should fetch the resource. Current CSS Fonts Levels 4/5 grammar prefers a keyword such as format(woff2), while the CSS Fonts 3 string form format("woff2") remains accepted for compatibility. The hint neither checks the font bytes nor guarantees loading: it is a function within the src descriptor, not a descriptor itself and not the separate font-format() support condition.
Examples
const style=document.createElement('style');
style.textContent='@font-face { font-family: "LocalProbe"; src: local("Arial"); font-style: normal; font-weight: 400; unicode-range: U+0041-005A; font-display: swap; } .probe { font: 400 32px "LocalProbe", monospace; }';
document.head.append(style);
const probe=document.createElement('span'); probe.className='probe'; probe.textContent='CKTIS'; document.body.append(probe);
const loaded=await document.fonts.load('400 32px "LocalProbe"','CKTIS');
const canvas=document.createElement('canvas'); const context=canvas.getContext('2d');
context.font='400 32px "LocalProbe"'; const localWidth=context.measureText('CKTIS').width;
context.font='400 32px monospace'; const monoWidth=context.measureText('CKTIS').width;
const rule=style.sheet.cssRules[0];
console.log('rule='+rule.constructor.name+'; loaded='+loaded.length+'; status='+loaded[0].status+'; family='+rule.style.getPropertyValue('font-family')+'; metric-diff='+(Math.abs(localWidth-monoWidth)>0.01));Result
rule=CSSFontFaceRule; loaded=1; status=loaded; family=LocalProbe; metric-diff=true
The @font-face rule registers a font face and its descriptors so the browser can match and load the proper resource.