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

CSSFontPaletteValuesRule: basePalette property

· 52CE 我爱测

The read-only **`basePalette`** property of the CSSFontPaletteValuesRule interface indicates the base palette associated with the rule.

CSSOM

The read-only basePalette property of the CSSFontPaletteValuesRule interface indicates the base palette associated with the rule.

Value

A string that can be one of the following color values:

  • light
    • : Matches the first palette in the font file that is marked as applicable to a light background, that is, close to white. If there is no palette in the font or if no palette has the required metadata, the value is equivalent to "0", that is, the first palette in the font.
  • dark
    • : Matches the first palette in the font file that is marked as applicable to a dark background, that is, close to black. If there is no palette in the font or if no palette has the required metadata, the value is equivalent to "0", that is, the first palette in the font.
  • a string containing an index (like "0", "1", …)
    • : Matches the palette corresponding to the index. The first palette corresponds to "0".

Examples

Read the associated base palette

The MDN live sample infrastructure combines all the CSS blocks in the example into a single inline style with the id css-output, so we first use document.getElementById() to find that sheet. rules[2] returns the first CSSFontPaletteValuesRule object, and rules[3] the second one.

HTML

<h2>default base-palette</h2>
<h2 class="two">base-palette at index 2</h2>
<h2 class="five">base-palette at index 5</h2>
<pre id="log"></pre>

CSS

@import "https://fonts.googleapis.com/css2?family=Nabla&display=swap";

h2 {
  font-family: "Nabla", fantasy;
}

@font-palette-values --two {
  font-family: "Nabla";
  base-palette: 2;
}

@font-palette-values --five {
  font-family: "Nabla";
  base-palette: 5;
}

.two {
  font-palette: --two;
}

.five {
  font-palette: --five;
}

JavaScript

const log = document.getElementById("log");

const rules = document.getElementById("css-output").sheet.cssRules;
const twoRule = rules[2]; // A CSSFontPaletteValuesRule interface
const fiveRule = rules[3]; // A CSSFontPaletteValuesRule interface

log.textContent = `The ${twoRule.name} @font-palette-values base palette is: ${twoRule.basePalette}\n`;
log.textContent += `The ${fiveRule.name} @font-palette-values base palette is: ${fiveRule.basePalette}`;

Result

Read the associated base palette

Specifications

Browser compatibility

See also

  • @font-palette-values at-rule
  • @font-palette-values/base-palette descriptor

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

资料来源与适用范围

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

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

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