Repository navigation
Expand file tree
/
Copy pathindex.md
More file actions
72 lines (48 loc) · 2.17 KB
/
Copy pathindex.md
File metadata and controls
72 lines (48 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
---
title: "CSSFontPaletteValuesRule: fontFamily property"
short-title: fontFamily
slug: Web/API/CSSFontPaletteValuesRule/fontFamily
page-type: web-api-instance-property
browser-compat: api.CSSFontPaletteValuesRule.fontFamily
---
{{APIRef("CSSOM")}}
The read-only **`fontFamily`** property of the {{domxref("CSSFontPaletteValuesRule")}} interface lists the font families the rule can be applied to. The font families must be _named_ families; _generic_ families like `courier` are not valid.
## Value
A string containing a space-separated list of the font families on which the rule can be applied
## Examples
### Read the associated font family
This example first defines an {{cssxref("@import")}} and an {{cssxref("@font-palette-values")}} at-rule. Then it reads the {{cssxref("@font-palette-values")}} rule and displays its name. The MDN [live sample](/en-US/docs/MDN/Writing_guidelines/Page_structures/Live_samples) infrastructure combines all the CSS blocks in the example into a single inline style with the id `css-output`, so we first use {{domxref("document.getElementById()")}} to find that sheet. The palette will be the second {{domxref("CSSRule")}} in that stylesheet. So, `rules[1]` returns a `CSSFontPaletteValuesRule` object, from which we can access `fontFamily`.
#### HTML
```html
<pre id="log">
The @font-palette-values at-rule's applies to the font families:</pre>
```
#### CSS
```css
@import "https://fonts.googleapis.com/css2?family=Bungee+Spice";
@font-palette-values --Alternate {
font-family: "Bungee Spice";
override-colors:
0 #00ffbb,
1 #007744;
}
.alternate {
font-palette: --Alternate;
}
```
#### JavaScript
```js
const log = document.getElementById("log");
const rules = document.getElementById("css-output").sheet.cssRules;
const fontPaletteValuesRule = rules[1]; // a CSSFontPaletteValuesRule interface
log.textContent += ` ${fontPaletteValuesRule.fontFamily}`;
```
#### Result
{{EmbedLiveSample("Read the associated font family", "100", "40")}}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{cssxref("@font-palette-values")}} at-rule
- {{cssxref("@font-palette-values/font-family", "font-family")}} descriptor