导航

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。

#类名

类名说明
heading字号为 1.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;      }    }  }}