網站導覽

v2.1.0
文字排版

標題

以頁面的高對比文字色呈現標題,搭配上方的前導標籤與下方的引言。

本頁內容

標題使用頁面的高對比文字色。所有尺寸都採略偏輕的中字重,靠字級和文字色呈現層級,無須加粗。換行時會平衡各行長度,避免最後一行只剩一個字詞,字級越大,字距也越緊。在任一標題元素上使用 .heading,由類別決定外觀,由元素決定層級。

標題

<header class="flex flex-col gap-sm max-w(520)">  <p class="eyebrow">Changelog</p>  <h1 class="heading heading-2xl">Faster cold builds, and comments on previews</h1>  <p class="lead">    Dependency caches are restored before the install step, and anyone can leave a note on a preview, pinned to the element they clicked.  </p></header>
<header className="flex flex-col gap-sm max-w(520)">  <p className="eyebrow">Changelog</p>  <h1 className="heading heading-2xl">Faster cold builds, and comments on previews</h1>  <p className="lead">    Dependency caches are restored before the install step, and anyone can leave a note on a preview, pinned to the element they clicked.  </p></header>
<header class="flex flex-col gap-sm max-w(520)">  <p class="eyebrow">Changelog</p>  <h1 class="heading heading-2xl">Faster cold builds, and comments on previews</h1>  <p class="lead">    Dependency caches are restored before the install step, and anyone can leave a note on a preview, pinned to the element they clicked.  </p></header>
<template>  <header class="flex flex-col gap-sm max-w(520)">    <p class="eyebrow">Changelog</p>    <h1 class="heading heading-2xl">Faster cold builds, and comments on previews</h1>    <p class="lead">      Dependency caches are restored before the install step, and anyone can leave a note on a preview, pinned to the element they clicked.    </p>  </header></template>

標題有兩個搭配項目。eyebrow 是標題上方的簡短標籤,用來交代接下來的內容類型。lead 是標題下方的引言,字級比內文大一階。

#尺寸

七種尺寸沿用全站的尺寸命名。依標題在頁面上的位置選擇字級,再依文件大綱選擇元素。同樣是 <h2>,在卡片中可以用 heading-sm,在區段開頭則可以用 heading-2xl。

尺寸

<div class="flex flex-col gap-md w-full">  <p class="heading heading-display">Display</p>  <p class="heading heading-2xl">Two extra large</p>  <p class="heading heading-xl">Extra large</p>  <p class="heading heading-lg">Large</p>  <p class="heading">Medium, the default</p>  <p class="heading heading-sm">Small</p>  <p class="heading heading-xs">Extra small</p></div>
<div className="flex flex-col gap-md w-full">  <p className="heading heading-display">Display</p>  <p className="heading heading-2xl">Two extra large</p>  <p className="heading heading-xl">Extra large</p>  <p className="heading heading-lg">Large</p>  <p className="heading">Medium, the default</p>  <p className="heading heading-sm">Small</p>  <p className="heading heading-xs">Extra small</p></div>
<div class="flex flex-col gap-md w-full">  <p class="heading heading-display">Display</p>  <p class="heading heading-2xl">Two extra large</p>  <p class="heading heading-xl">Extra large</p>  <p class="heading heading-lg">Large</p>  <p class="heading">Medium, the default</p>  <p class="heading heading-sm">Small</p>  <p class="heading heading-xs">Extra small</p></div>
<template>  <div class="flex flex-col gap-md w-full">    <p class="heading heading-display">Display</p>    <p class="heading heading-2xl">Two extra large</p>    <p class="heading heading-xl">Extra large</p>    <p class="heading heading-lg">Large</p>    <p class="heading">Medium, the default</p>    <p class="heading heading-sm">Small</p>    <p class="heading heading-xs">Extra small</p>  </div></template>
類別尺寸用途
heading-display2.5 至 4.25rem登陸頁唯一的主標題
heading-2xl2 至 2.5rem頁面標題、登陸頁的區段標題
heading-xl1.625 至 2rem應用程式中的頁面標題
heading-lg1.5rem區段標題
heading1.25rem子區段、對話框大小的面板標題
heading-sm1.0625rem卡片、橫列標題
heading-xs0.9375rem連結群組、資訊密集的面板標題

#隨可用寬度調整的尺寸

最大的三種尺寸使用容器查詢單位,以最近的尺寸容器為基準,找不到尺寸容器時則以檢視區為基準。主標題在手機的窄欄中為 2.5rem,在寬欄中可達 4.25rem,中間會隨欄寬連續縮放,無須斷點。

隨可用寬度調整的尺寸

<section class="container-inline p-xl bg-surface-base">  <h1 class="heading heading-display">Every push gets an address.</h1>  <p class="lead mt-md max-w(480)">    Choose Tablet, then Phone: the title is set smaller as its container narrows, and its lines are balanced again at each size.  </p></section>
<section className="container-inline p-xl bg-surface-base">  <h1 className="heading heading-display">Every push gets an address.</h1>  <p className="lead mt-md max-w(480)">    Choose Tablet, then Phone: the title is set smaller as its container narrows, and its lines are balanced again at each size.  </p></section>
<section class="container-inline p-xl bg-surface-base">  <h1 class="heading heading-display">Every push gets an address.</h1>  <p class="lead mt-md max-w(480)">    Choose Tablet, then Phone: the title is set smaller as its container narrows, and its lines are balanced again at each size.  </p></section>
<template>  <section class="container-inline p-xl bg-surface-base">    <h1 class="heading heading-display">Every push gets an address.</h1>    <p class="lead mt-md max-w(480)">      Choose Tablet, then Phone: the title is set smaller as its container narrows, and its lines are balanced again at each size.    </p>  </section></template>

若要讓標題隨面板寬度調整,請在面板上加上 container-inline,將它設為尺寸容器。

#平衡換行

標題使用 text-wrap: balance 換行,瀏覽器會讓各行長度接近,所以兩行標題會排得較均勻。引言使用 text-wrap: pretty,避免最後一行只剩一個字詞。如果瀏覽器兩者都不支援,文字會照常換行。

標題放在寬欄中時,可用 max-w(560) 等方式限制行寬。平衡換行只會調整各行的長度,行數仍由可用寬度和文字內容決定。

#前導標籤與引言

前導標籤與引言

<div class="flex flex-col gap-lg max-w(520)">  <div class="flex flex-col gap-xs">    <p class="eyebrow">Pricing</p>    <h2 class="heading heading-xl">Free to start. Fair when you grow.</h2>  </div>  <p class="lead lead-sm">A small lead, for a card or a narrow column.</p>  <p class="lead">The default lead, under a page's title.</p>  <p class="lead lead-lg">A large lead, under a display heading.</p></div>
<div className="flex flex-col gap-lg max-w(520)">  <div className="flex flex-col gap-xs">    <p className="eyebrow">Pricing</p>    <h2 className="heading heading-xl">Free to start. Fair when you grow.</h2>  </div>  <p className="lead lead-sm">A small lead, for a card or a narrow column.</p>  <p className="lead">The default lead, under a page's title.</p>  <p className="lead lead-lg">A large lead, under a display heading.</p></div>
<div class="flex flex-col gap-lg max-w(520)">  <div class="flex flex-col gap-xs">    <p class="eyebrow">Pricing</p>    <h2 class="heading heading-xl">Free to start. Fair when you grow.</h2>  </div>  <p class="lead lead-sm">A small lead, for a card or a narrow column.</p>  <p class="lead">The default lead, under a page's title.</p>  <p class="lead lead-lg">A large lead, under a display heading.</p></div>
<template>  <div class="flex flex-col gap-lg max-w(520)">    <div class="flex flex-col gap-xs">      <p class="eyebrow">Pricing</p>      <h2 class="heading heading-xl">Free to start. Fair when you grow.</h2>    </div>    <p class="lead lead-sm">A small lead, for a card or a narrow column.</p>    <p class="lead">The default lead, under a page's title.</p>    <p class="lead lead-lg">A large lead, under a display heading.</p>  </div></template>

#無障礙

  • 類別只設定外觀。請依序使用 <h1> 到 <h6>,避免跳級,並依各標題所在的位置選擇合適的尺寸。
  • 每個頁面使用一個 <h1>。
  • 前導標籤使用 <p>。螢幕閱讀器會先讀出前導標籤,再讀出標題。請勿將前導標籤設為標題,讓標題清單從標題本身開始。
  • 無論背景為何,標題都使用高對比文字色。在反色面板上,請加上 fg-text-inverse。

#類別

類別說明
heading1.25rem 的標題,採用高對比文字色、偏輕的中等字重,並讓各行長度均衡
heading-xs0.9375rem,適用於一組連結或內容密集的面板搭配 heading 使用
heading-sm1.0625rem,適用於卡片或橫列搭配 heading 使用
heading-lg1.5rem,適用於區段搭配 heading 使用
heading-xl依容器寬度在 1.625 至 2rem 之間調整,適用於應用程式的頁面標題搭配 heading 使用
heading-2xl依容器寬度在 2 至 2.5rem 之間調整,適用於頁面標題或到達頁的區段搭配 heading 使用
heading-display依容器寬度在 2.5 至 4.25rem 之間調整,適用於到達頁唯一的主標題搭配 heading 使用
eyebrow標題上方的一行小字級大寫文字,用來說明接下來的內容類型,使用 p 元素呈現為段落
lead標題下方的段落,字級為 1.125rem,換行時避免最後一行只剩一個詞。
lead-sm1rem,適用於卡片或窄欄搭配 lead 使用
lead-lg1.25rem,適用於大型標題下方搭配 lead 使用

#自訂屬性

屬性預設值說明
--heading-size1.25rem字級
--heading-leading1.3行高
--heading-tracking-.012em字距

#原始碼

@master/ui/components/heading.css
/* * Heading: a title, the short line over it and the paragraph under it. * A heading is set in the ink of the page at a light medium weight: size and ink carry the hierarchy, not * boldness. Its lines are balanced, so a title never leaves one word alone on the last line, and its Latin * tracking tightens as it grows; Chinese, Japanese and Korean keep their own spacing. The three largest sizes follow the room they are given: they are sized in container * units, which measure the nearest size container and, where there is none, the viewport. */@layer components.ui {  .heading {    --heading-size: 1.25rem;    --heading-leading: 1.3;    --heading-tracking: -.012em;    margin: 0;    color: var(--color-text-strong);    font: var(--font-weight-control) var(--heading-size)/var(--heading-leading) var(--font-family-sans);    font-feature-settings: inherit;    letter-spacing: var(--heading-tracking);    text-wrap: balance;    overflow-wrap: anywhere;    &.heading-xs {      --heading-size: .9375rem;      --heading-leading: 1.4;      --heading-tracking: -.004em;    }    &.heading-sm {      --heading-size: 1.0625rem;      --heading-leading: 1.35;      --heading-tracking: -.008em;    }    &.heading-lg {      --heading-size: 1.5rem;      --heading-leading: 1.25;      --heading-tracking: -.018em;    }    &.heading-xl {      --heading-size: clamp(1.625rem, 1.3rem + 1.6cqi, 2rem);      --heading-leading: 1.18;      --heading-tracking: -.024em;    }    &.heading-2xl {      --heading-size: clamp(2rem, 1.4rem + 2.6cqi, 2.5rem);      --heading-leading: 1.12;      --heading-tracking: -.03em;    }    /* Display: the one title of a page, from 2.5rem in a phone's column to 4.25rem in a wide one. */    &.heading-display {      --heading-size: clamp(2.5rem, 1.5rem + 4.4cqi, 4.25rem);      --heading-leading: 1.04;      --heading-tracking: -.038em;    }    /*     * Han, kana and Hangul keep their own spacing at every size: tracking that tightens Latin as it grows would     * crowd square glyphs. It follows the content's language, so a CJK title in an English page is spaced too.     */    &:is(:lang(zh), :lang(ja), :lang(ko)) {      --heading-tracking: 0em;    }  }  /* Eyebrow: the few words over a heading that say what kind of thing follows. */  .eyebrow {    margin: 0;    color: var(--color-text-muted);    font: var(--font-weight-control) .75rem/1.4 var(--font-family-sans);    font-feature-settings: inherit;    letter-spacing: .06em;    text-transform: uppercase;    /* A long word in capitals, spaced out, breaks rather than run out of a narrow card. */    overflow-wrap: break-word;    /* The spacing is for Latin capitals; scripts without case are set as they are. */    &:is(:lang(zh), :lang(ja), :lang(ko)) {      letter-spacing: 0;    }  }  /* Lead: the paragraph under a heading, a step larger than body text and wrapped without orphans. */  .lead {    margin: 0;    color: var(--color-text-body);    font-size: 1.125rem;    line-height: 1.6;    text-wrap: pretty;    /* A long address or name breaks rather than run out of the column. */    overflow-wrap: break-word;    &.lead-sm {      font-size: 1rem;    }    &.lead-lg {      font-size: 1.25rem;      line-height: 1.5;      letter-spacing: -.006em;      &:is(:lang(zh), :lang(ja), :lang(ko)) {        letter-spacing: 0;      }    }  }}