# フォント

ファミリー、サイズ、ウェイトを、いずれも font-* 形式で指定します。

- ID: tokens/font
- Type: tokens
- Canonical: /ja/reference/tokens/font
- Version: 2.1.8
- Source revision: 09fc2350ea80ed137ba7ca62c8e5926744b5a5dc (revision)
- Source: packages/preset/src/theme.css
- Content digest: 6f909b98b776c95d8dd542331f41b7eae401c1b97dc17319ebfeb550d7eee4ef
- Semantic digest: 83962260d6d56817dd052d2beebf7999a75804215dac050c47b26353145c099a
- Language: ja

<a id="consumers"></a>

## クラス

| クラス | プロパティ | 宣言 |
| --- | --- | --- |
| [`font-<family>`](/ja/reference/tokens/families#family-font) | `font-family` | `font-family: var(--font-family-<family>)` |
| [`font-<size>`](/ja/reference/tokens/families#family-font) | `font-size` | `font-size: var(--font-size-<size>)` |
| [`font-<weight>`](/ja/reference/tokens/families#family-font) | `font-weight` | `font-weight: var(--font-weight-<weight>)` |

3 つの名前空間が `font-` 接頭辞を共有するため、名前はその間で一意でなければなりません。複数の名前空間に同じ名前を定義すると、`AMBIGUOUS_TOKEN` が報告され、CSS は生成されません。

<a id="values"></a>

## 値

ファミリーは順序付きのフォールバックリスト、サイズは rem 単位の長さ、ウェイトは数値による指定です。ピクセル換算はルートのフォントサイズを 16px と仮定しています。実際の書体と利用可能なウェイトは、ページに読み込まれたフォントによって決まります。

<a id="font-family"></a>

### ファミリー

| クラス | 変数 | 値 |
| --- | --- | --- |
| `font-sans` | `--font-family-sans` | `var(--font-sans, ui-sans-serif), system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"` |
| `font-mono` | `--font-family-mono` | `var(--font-mono, ui-monospace), SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace` |
| `font-serif` | `--font-family-serif` | `var(--font-serif, ui-serif), Georgia, Cambria, "Times New Roman", Times, serif` |

<a id="font-size"></a>

### サイズ

| クラス | 変数 | 値 |
| --- | --- | --- |
| `font-3xs` | `--font-size-3xs` | `.5rem` |
| `font-2xs` | `--font-size-2xs` | `.625rem` |
| `font-xs` | `--font-size-xs` | `.75rem` |
| `font-sm` | `--font-size-sm` | `.875rem` |
| `font-md` | `--font-size-md` | `1rem` |
| `font-lg` | `--font-size-lg` | `1.125rem` |
| `font-xl` | `--font-size-xl` | `1.25rem` |
| `font-2xl` | `--font-size-2xl` | `1.5rem` |
| `font-3xl` | `--font-size-3xl` | `2rem` |
| `font-4xl` | `--font-size-4xl` | `2.25rem` |
| `font-5xl` | `--font-size-5xl` | `2.5rem` |
| `font-6xl` | `--font-size-6xl` | `3rem` |
| `font-7xl` | `--font-size-7xl` | `3.75rem` |
| `font-8xl` | `--font-size-8xl` | `4.5rem` |
| `font-9xl` | `--font-size-9xl` | `6rem` |
| `font-10xl` | `--font-size-10xl` | `8rem` |

<a id="font-weight"></a>

### ウェイト

| クラス | 変数 | 値 |
| --- | --- | --- |
| `font-thin` | `--font-weight-thin` | `100` |
| `font-extralight` | `--font-weight-extralight` | `200` |
| `font-light` | `--font-weight-light` | `300` |
| `font-regular` | `--font-weight-regular` | `400` |
| `font-medium` | `--font-weight-medium` | `500` |
| `font-semibold` | `--font-weight-semibold` | `600` |
| `font-bold` | `--font-weight-bold` | `700` |
| `font-extrabold` | `--font-weight-extrabold` | `800` |
| `font-heavy` | `--font-weight-heavy` | `900` |

<a id="independent-properties"></a>

## 接頭辞は共通でもプロパティは独立

`font-serif`、`font-4xl`、`font-semibold` は、それぞれ `font-family`、`font-size`、`font-weight` を設定します。異なるプロパティなので併用できますが、いずれも完全なテキストスタイルではありません。

**font 接頭辞は独立した 3 つのプロパティを変える**

各行は font-sans、font-2xl、font-regular から始まり、結果では対象のプロパティのクラスだけを置き換えます。実際の書体は利用可能なフォントによって決まります。

- 基準のテキストは sans ファミリー、1.5rem のサイズ、400 のウェイトを使い、ルートのフォントサイズは 16px です。
- font-serif の行は font-family だけを変えます。font-4xl の行は font-size だけを 2.25rem に変え、font-semibold の行は font-weight だけを 600 に変えます。
- 各結果は同じ言葉を使います。共通の単位なしの line-height 1.5 で読みやすさを保っていますが、これらの font クラスが line-height を設定するわけではありません。
- 見本は実際のプリセット CSS と利用可能なシステムフォントで描画しています。ファミリーのクラスがフォントファイルをダウンロードするという意味ではありません。

サイズのクラスは、行の高さと文字間隔をそれぞれの宣言や継承に委ねます。3 つの寸法を 1 つのスタイルから指定したい場合は、`text-<name>` を使います。どちらの形式でも、ファミリーとウェイトは独立しています。

ファミリートークンはフォント名を指定するだけで、ダウンロードは行いません。プリセットの sans、mono、serif のスタックは、それぞれ任意のフック `--font-sans`、`--font-mono`、`--font-serif` から始まります。フォントの読み込みとサイト全体のスタック選択は、タイポグラフィガイドで説明しています。

独自のキーは 3 つの名前空間の間で重複させないでください。`--font-family-brand` と `--font-size-brand` が両方あると、`font-brand` は曖昧になります。`(font-size:var(--font-size-brand))` のような明示的なネイティブ宣言なら、目的のプロパティと変数を指定できます。

関連項目： [テキストスタイル](/ja/reference/tokens/text)、[名前空間の解決](/ja/reference/rules/modes#namespace-resolution)、[ネイティブのフォント選択](https://www.w3.org/TR/css-fonts-4/#font-family-prop).

<a id="usage"></a>

## 使用例

見出しに大きめのサイズと中程度のウェイトを指定し、コード例には等幅のファミリーを使います。

```html
<h3 class="… font-2xl font-medium">Release notes</h3>
<p class="… font-sm">Install the new version with <code class="… font-mono font-xs">npm i @master/css</code>.</p>
```

```css disclosure=generated-css
@layer theme{:root,:host{--font-family-mono:var(--font-mono, ui-monospace), SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;--font-weight-medium:500;--font-size-xs:.75rem;--font-size-sm:.875rem;--font-size-2xl:1.5rem}}@layer utilities{.font-mono{font-family:var(--font-family-mono)}.font-2xl{font-size:var(--font-size-2xl)}.font-sm{font-size:var(--font-size-sm)}.font-xs{font-size:var(--font-size-xs)}.font-medium{font-weight:var(--font-weight-medium)}}
```

<a id="customize"></a>

## カスタマイズ

各名前空間はそれぞれのトークンを受け付けます。`--font-family-display` は `font-display` を、`--font-size-hero` は `font-hero` を利用可能にします。

```css
@theme {
  --font-family-display: "Inter Display", var(--font-family-sans);
  --font-size-hero: 4rem;
}
```

```css disclosure=generated-css
@layer theme{:root,:host{--font-family-sans:var(--font-sans, ui-sans-serif), system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"}:root,:host{--font-family-display:"Inter Display", var(--font-family-sans);--font-size-hero:4rem}}@layer utilities{.font-display{font-family:var(--font-family-display)}.font-hero{font-size:var(--font-size-hero)}}
```

関連項目： [テーマのディレクティブ](/ja/reference/directives/theme)、[タイポグラフィ](/ja/guide/typography).

## 関連リファレンス

- [rules/modes](/ja/reference/rules/modes.md)
- [directives/theme](/ja/reference/directives/theme.md)
