CSSFontFeatureValuesRule

Baseline 2023 *
Newly available

Since March 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

* Some parts of this feature may have varying levels of support.

CSSFontFeatureValuesRule インターフェイスは @font-feature-values アットルールを表し、開発者が開発者が各フォントフェイスに対して、 font-variant-alternates で使用する機能インデックスを指定するための共通の名前を割り当てることができます。

CSSRule CSSFontFeatureValuesRule

インスタンスプロパティ

祖先である CSSRule から継承したプロパティがあります。

CSSFontFeatureValuesRule.fontFamily

このルールが適用されるフォントファミリを示す文字列です。

インスタンスメソッド

祖先である CSSRule から継承したメソッドがあります。

フォントファミリーの読み取り

この例では、 2 つの @font-feature-values を宣言しています。 1 つは Font One フォントファミリー用、他の 1 つは Font Two フォントファミリ用です。そして、 CSSOM を使用して、これらのフォントファミリーを読み取り、ログに出力しています。

HTML

html
<pre id="log"></pre>

CSS

css
/* Font One の "nice-style" のアットルール */
@font-feature-values Font One {
  @styleset {
    nice-style: 12;
  }
}

/* Font Two の "nice-style" のアットルール */
@font-feature-values Font Two {
  @styleset {
    nice-style: 4;
  }
}

/* 単一の宣言でアットルールを適用 */
.nice-look {
  font-variant-alternates: styleset(nice-style);
}

JavaScript

js
const log = document.getElementById("log");
const rules = document.styleSheets[document.styleSheets.length - 1].cssRules;

const fontOne = rules[0]; // CSSFontFeatureValuesRule
log.textContent = `1 つ目の '@font-feature-values' ファミリー: "${fontOne.fontFamily}"\n`;

const fontTwo = rules[1]; // もう一つの CSSFontFeatureValuesRule
log.textContent += `2 つ目の '@font-feature-values' ファミリー: "${fontTwo.fontFamily}"`;

仕様書

Specification
CSS Fonts Module Level 4
# cssfontfeaturevaluesrule

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
CSSFontFeatureValuesRule
annotation
Experimental
characterVariant
Experimental
fontFamily
ornaments
Experimental
styleset
Experimental
stylistic
Experimental
swash
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.

関連情報