# テキスト

フォントサイズ、行の高さ、文字間隔をまとめて設定するテキストスタイル。

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

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

## クラス

| クラス | プロパティ | 宣言 |
| --- | --- | --- |
| [`text-<name>`](/ja/reference/tokens/families#family-text) | `font-size, line-height, letter-spacing` | `font-size: var(--text-<name>);` `line-height: var(--text-<name>--line-height, normal);` `letter-spacing: var(--text-<name>--letter-spacing, normal);` |

主要な `--text-<name>` トークンがクラスを作ります。付随する `--line-height` と `--letter-spacing` は任意で、省略時は `normal` を使います。ファミリー、ウェイト、色は別のクラスで指定します。

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

## 値

各行は、1 つのクラスが参照する 3 つの値を示します。プリセットのサイズは対応する font-size トークンを参照し、表では読みやすいように参照を解決しています。すべてのプリセットスタイルに、両方の付随トークンが含まれます。

| クラス | 変数 | サイズ | 行の高さ | 文字間隔 |
| --- | --- | --- | --- | --- |
| `text-3xs` | `--text-3xs` | `var(--font-size-3xs)` | `1.5` | `0` |
| `text-2xs` | `--text-2xs` | `var(--font-size-2xs)` | `1.5` | `0` |
| `text-xs` | `--text-xs` | `var(--font-size-xs)` | `1.5` | `0` |
| `text-sm` | `--text-sm` | `var(--font-size-sm)` | `1.5` | `0` |
| `text-md` | `--text-md` | `var(--font-size-md)` | `1.6` | `0` |
| `text-lg` | `--text-lg` | `var(--font-size-lg)` | `1.5` | `0` |
| `text-xl` | `--text-xl` | `var(--font-size-xl)` | `1.4` | `-.01em` |
| `text-2xl` | `--text-2xl` | `var(--font-size-2xl)` | `1.35` | `-.015em` |
| `text-3xl` | `--text-3xl` | `var(--font-size-3xl)` | `1.25` | `-.02em` |
| `text-4xl` | `--text-4xl` | `var(--font-size-4xl)` | `1.2` | `-.025em` |
| `text-5xl` | `--text-5xl` | `var(--font-size-5xl)` | `1.15` | `-.03em` |
| `text-6xl` | `--text-6xl` | `var(--font-size-6xl)` | `1.1` | `-.035em` |
| `text-7xl` | `--text-7xl` | `var(--font-size-7xl)` | `1.05` | `-.04em` |
| `text-8xl` | `--text-8xl` | `var(--font-size-8xl)` | `1.05` | `-.04em` |
| `text-9xl` | `--text-9xl` | `var(--font-size-9xl)` | `1` | `-.045em` |
| `text-10xl` | `--text-10xl` | `var(--font-size-10xl)` | `1` | `-.05em` |

<a id="primary-and-companions"></a>

## 1 つの主要トークンから 3 つの宣言

`--text-card` は `text-card` を登録します。このクラスは常にフォントサイズ、行の高さ、文字間隔を出力します。`--text-card--line-height` または `--text-card--letter-spacing` がない場合、その宣言には `normal` を使い、継承した値は保持しません。

**テキストスタイルは常に 3 つのプロパティを設定する**

ここでは主要な --text-card トークンだけを定義しています。付随する 2 つの宣言も生成され、normal を使って、継承した行の高さや文字間隔を置き換えます。

- 独自のテーマは --text-card を 1.5rem と定義し、付随トークンはどちらも定義しません。
- text-card は font-size: var(--text-card)、line-height: var(--text-card--line-height, normal)、letter-spacing: var(--text-card--letter-spacing, normal) を出力します。
- 3 本の実線の分岐は、すべて出力される宣言です。付随値がない場合は normal にフォールバックし、別の行の高さや文字間隔を継承するのではありません。
- 付随トークンだけでは text-card は登録されません。ファミリー、ウェイト、色は、この組み合わせスタイルの対象外です。

付随トークンだけではテキストスタイルは登録されません。変更したい値が行の高さや文字間隔だけでも、主要なサイズトークンを追加してください。

付随トークンは、この組み合わせスタイルが使う値であり、別のクラス名ではありません。個別に調整するには、`font-<size>`、`leading-<name>`、`tracking-<name>` を使います。同じ条件では、これらの単一プロパティのユーティリティはテキストの組み合わせスタイルより後になり、対応する宣言を上書きできます。class 属性での順序は結果を決めません。

この組み合わせスタイルは、フォントの読み込み、ファミリーやウェイトの選択、マージンの追加、段落幅の決定は行いません。スタイルを選んで組み合わせ、階層を作る方法はタイポグラフィガイドで説明しています。

関連項目： [フォント](/ja/reference/tokens/font)、[行の高さ](/ja/reference/tokens/leading)、[文字間隔](/ja/reference/tokens/tracking)、[生成ルールの順序](/ja/reference/rules/layers).

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

## 使用例

段落に 1 つのテキストスタイルを適用します。ファミリー、ウェイト、色は引き続き独立して指定できます。

```html
<p class="… text-lg">A paragraph keeps its size,…</p>
```

```css disclosure=generated-css
@layer theme{:root,:host{--font-size-lg:1.125rem;--text-lg:var(--font-size-lg);--text-lg--line-height:1.5;--text-lg--letter-spacing:0}}@layer utilities{.text-lg{font-size:var(--text-lg);line-height:var(--text-lg--line-height, normal);letter-spacing:var(--text-lg--letter-spacing, normal)}}
```

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

## カスタマイズ

付随トークンとともにテキストスタイルを追加します。`--text-display` を定義すると `text-display` が使えるようになります。

```css
@theme {
  --text-display: 3.5rem;
  --text-display--line-height: 1.1;
  --text-display--letter-spacing: -.03em;
}
```

```css disclosure=generated-css
@layer theme{:root,:host{--text-display:3.5rem;--text-display--line-height:1.1;--text-display--letter-spacing:-.03em}}@layer utilities{.text-display{font-size:var(--text-display);line-height:var(--text-display--line-height, normal);letter-spacing:var(--text-display--letter-spacing, normal)}}
```

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

## 関連リファレンス

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