Skip to content

Type to search the docs, API, and blog.

↑↓ navigate↵ openesc close
  • Zazz 0.16 alpha

    API

    Font

    Typography roles: a step of the type scale on any element.

    Installation

    pnpm dlx zazz-ui add font
    npx zazz-ui add font
    yarn dlx zazz-ui add font
    bunx zazz-ui add font

    Run zazz-ui init first if the project has no zazz/ folder yet.

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- Paint the right theme (background, form controls, scrollbars) before CSS loads -->
    <meta name="color-scheme" content="light dark">
    <!-- Zazz styles: base layers, then font in cascade order -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_layers.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_variables.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_shadows.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_breakpoints.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_reset.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_typography.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_view-transitions.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/primitives/font/font.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-sm.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-md.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-lg.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-2xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-disabled.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-active.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-focus-visible.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-focus-within.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-hover.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-checked.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-current.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-open.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-stuck.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_properties-starting.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-sm.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-md.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-lg.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-2xl.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-disabled.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-active.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-focus-visible.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-focus-within.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-hover.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-checked.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-current.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-open.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-stuck.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-tier-starting.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-flow.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-grid.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-spacing.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-margin.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-sizing.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-typography.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-color.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-effects.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-box.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-pseudo.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_defaults.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/_utilities-sr.css">
    <!-- Import map: bare specifiers in Zazz scripts resolve to pinned, SRI-checked files -->
    <script type="importmap">
    {
      "imports": {
        "signal-polyfill": "https://cdn.jsdelivr.net/npm/signal-polyfill@0.2.2/dist/index.js"
      },
      "integrity": {
        "https://cdn.jsdelivr.net/npm/signal-polyfill@0.2.2/dist/index.js": "sha384-0OqM7OXGT6Oz1z98u/geiFn/FUyz4iWexkXHCvbIGXRRDXl6bp6IKc0j78AQ6DEK"
      }
    }
    </script>
    <!-- Polyfill: Interest Invokers (interestfor) — native in Chromium only -->
    <script type="module" src="https://cdn.jsdelivr.net/npm/invokers@2.2.2/dist/esm/production/interest.js" integrity="sha384-hR2BVNtsS7fIIMwOm+f7MY0JZfuByGhQQfevCBB6evFATKzBsTw0JzH/RxD94z2T" crossorigin="anonymous"></script>
    <!-- Zazz behavior: side-effect modules by tag; the rest via module imports -->
    <script type="module" src="https://cdn.jsdelivr.net/npm/@zazz-ui/core@0.16.0/src/base/dialog-lifecycle.js"></script>
    <!-- Theme: apply the persisted (or preferred) scheme before first paint -->
    <script>
      (() => {
        try {
          // A stored choice pins the scheme with data-theme; with no choice the
          // page follows the system scheme.
          const storedTheme = localStorage.getItem("theme");
          if (storedTheme === "dark" || storedTheme === "light") {
            document.documentElement.dataset.theme = storedTheme;
          }
        } catch {
          /* no storage access: follow the system scheme */
        }
      })();
    </script>

    A <head> that loads the base layers and font from jsDelivr, pinned to 0.16.0. To load the whole kit in two requests, see the CDN install.

    Examples

    Release notes

    Type roles on any element

    A role sets the size, leading, and tracking of one step in the type scale.

    Heading roles also set the heading family and weight; body roles leave them alone.

    <div
      style="
        --display: flex-col;
        --gap: 4;
        --max-w: 96;
      "
    >
      <span data-font="eyebrow" style="--text: var(--color-muted-foreground)">Release notes</span>
      <p data-font="h3">Type roles on any element</p>
      <p data-font="lg">A role sets the size, leading, and tracking of one step in the type scale.</p>
      <p data-font="sm" style="--text: var(--color-muted-foreground)">
        Heading roles also set the heading family and weight; body roles leave them alone.
      </p>
    </div>
    /**
     * font.css: Typography roles ([data-font])
     *
     * @layer      components
     * @requires   _layers.css, _variables.css, _typography.css (the native headings
     *             these roles restyle); loads after every primitive that sets a font
     * @uses       data-font="display | h1–h6 | 2xl–2xs | eyebrow": one role per element;
     *             each sets the size, leading, and tracking of its step in the type scale
     * @uses       font-optical-sizing: heading optical size
     * @uses       text-wrap: pretty (h4–h6), @supports gated (Firefox lacks it; wrap fallback)
     * @uses       Type tokens: consumes --font-size-*, --leading-*, --tracking-*,
     *             --font-family-*, --font-weight-*, and the per-group OpenType controls
     *             (--font-<feature>-heading | -body) from _variables.css
     * @uses       Bare attribute selectors, no :where(): a role is an explicit choice, so it
     *             carries one attribute of specificity. That beats a primitive's zero-specificity
     *             root and prose's scoped rules, and ties a slot rule, which it follows in
     *             load order. Utilities sit in a later layer and still win.
     */
    
    @layer ui.components {
      /* ===========================================================================
      FONT ROLES: a step of the type scale on any element
      - Heading roles (display, h1–h6) match the native headings in _typography.css
        and also set the heading family and weight.
      - Body roles (2xl–2xs) leave family and weight alone, so <h3 data-font="lg">
        is a smaller heading, not body text. The eyebrow sets its own weight.
      - A utility (--font-size, --font-weight, …) overrides one property of a role.
      =========================================================================== */
    
      [data-font="display"],
      [data-font="h1"],
      [data-font="h2"],
      [data-font="h3"],
      [data-font="h4"],
      [data-font="h5"],
      [data-font="h6"] {
        font-family: var(--font-family-heading);
        font-weight: var(--font-weight-heading);
        font-feature-settings: var(--font-feature-heading);
        font-kerning: var(--font-kerning-heading);
        font-language-override: var(--font-language-heading);
        font-optical-sizing: var(--font-optical-sizing-heading, auto);
        font-size-adjust: var(--font-size-adjust-heading);
        font-variant-alternates: var(--font-alternates-heading);
        font-variant-caps: var(--font-caps-heading);
        font-variant-east-asian: var(--font-east-asian-heading);
        font-variant-emoji: var(--font-emoji-heading);
        font-variant-ligatures: var(--font-ligatures-heading);
        font-variant-numeric: var(--font-numeric-heading);
        font-variant-position: var(--font-position-heading);
        font-variation-settings: var(--font-settings-heading);
      }
    
      [data-font="display"],
      [data-font="h1"],
      [data-font="h2"],
      [data-font="h3"] {
        text-wrap: var(--text-wrap-heading, balance);
      }
    
      [data-font="h4"],
      [data-font="h5"],
      [data-font="h6"] {
        text-wrap: var(--text-wrap-heading, wrap);
        /* pretty can't be a var() fallback: a var() value is only checked at
           computed-value time, so Firefox (no pretty) would reset text-wrap.
           Drop the gate once web-features text-wrap-pretty is Baseline widely
           available (not yet Baseline as of 2026-11). */
        @supports (text-wrap: pretty) {
          text-wrap: var(--text-wrap-heading, pretty);
        }
      }
    
      [data-font="2xl"],
      [data-font="xl"],
      [data-font="lg"],
      [data-font="md"],
      [data-font="sm"],
      [data-font="xs"],
      [data-font="2xs"],
      [data-font="eyebrow"] {
        font-feature-settings: var(--font-feature-body);
        font-kerning: var(--font-kerning-body);
        font-language-override: var(--font-language-body);
        font-optical-sizing: var(--font-optical-sizing-body, auto);
        font-size-adjust: var(--font-size-adjust-body);
        font-variant-alternates: var(--font-alternates-body);
        font-variant-caps: var(--font-caps-body);
        font-variant-east-asian: var(--font-east-asian-body);
        font-variant-emoji: var(--font-emoji-body);
        font-variant-ligatures: var(--font-ligatures-body);
        font-variant-numeric: var(--font-numeric-body);
        font-variant-position: var(--font-position-body);
        font-variation-settings: var(--font-settings-body);
      }
    
      [data-font="display"] {
        font-size: var(--font-size-display);
        line-height: var(--leading-display);
        letter-spacing: var(--tracking-display);
      }
    
      [data-font="h1"] {
        font-size: var(--font-size-h1);
        line-height: var(--leading-h1);
        letter-spacing: var(--tracking-h1);
      }
    
      [data-font="h2"] {
        font-size: var(--font-size-h2);
        line-height: var(--leading-h2);
        letter-spacing: var(--tracking-h2);
      }
    
      [data-font="h3"] {
        font-size: var(--font-size-h3);
        line-height: var(--leading-h3);
        letter-spacing: var(--tracking-h3);
      }
    
      [data-font="h4"] {
        font-size: var(--font-size-h4);
        line-height: var(--leading-h4);
        letter-spacing: var(--tracking-h4);
      }
    
      [data-font="h5"] {
        font-size: var(--font-size-h5);
        line-height: var(--leading-h5);
        letter-spacing: var(--tracking-h5);
      }
    
      [data-font="h6"] {
        font-size: var(--font-size-h6);
        line-height: var(--leading-h6);
        letter-spacing: var(--tracking-h6);
      }
    
      [data-font="2xl"] {
        font-size: var(--font-size-2xl);
        line-height: var(--leading-2xl);
        letter-spacing: var(--tracking-2xl);
      }
    
      [data-font="xl"] {
        font-size: var(--font-size-xl);
        line-height: var(--leading-xl);
        letter-spacing: var(--tracking-xl);
      }
    
      [data-font="lg"] {
        font-size: var(--font-size-lg);
        line-height: var(--leading-lg);
        letter-spacing: var(--tracking-lg);
      }
    
      [data-font="md"] {
        font-size: var(--font-size-md);
        line-height: var(--leading-md);
        letter-spacing: var(--tracking-md);
      }
    
      [data-font="sm"] {
        font-size: var(--font-size-sm);
        line-height: var(--leading-sm);
        letter-spacing: var(--tracking-sm);
      }
    
      [data-font="xs"] {
        font-size: var(--font-size-xs);
        line-height: var(--leading-xs);
        letter-spacing: var(--tracking-xs);
      }
    
      [data-font="2xs"] {
        font-size: var(--font-size-2xs);
        line-height: var(--leading-2xs);
        letter-spacing: var(--tracking-2xs);
      }
    
      [data-font="eyebrow"] {
        font-size: var(--font-size-eyebrow);
        line-height: var(--leading-eyebrow);
        font-weight: var(--font-weight-eyebrow);
        letter-spacing: var(--tracking-eyebrow);
        text-transform: uppercase;
      }
    }

    Roles

    data-font takes one role. Each sets the size, leading, and tracking of its step in the type scale. The heading roles (display, h1–h6) also set the heading family and weight, and match the native headings. The body sizes leave family and weight alone, so <h3 data-font="lg"> is a smaller heading and not body text. The eyebrow sets its own weight.

    data-font="display"The quick brown fox
    data-font="h1"The quick brown fox
    data-font="h2"The quick brown fox
    data-font="h3"The quick brown fox
    data-font="h4"The quick brown fox
    data-font="h5"The quick brown fox
    data-font="h6"The quick brown fox
    data-font="eyebrow"The quick brown fox
    data-font="2xl"The quick brown fox
    data-font="xl"The quick brown fox
    data-font="lg"The quick brown fox
    data-font="md"The quick brown fox
    data-font="sm"The quick brown fox
    data-font="xs"The quick brown fox
    data-font="2xs"The quick brown fox

    A role beats the font of the primitive or slot it sits on: <span data-ui="badge" data-font="sm"> is a badge with larger text. A utility still overrides one property of a role (--font-size, --leading, --font-weight).

    <span data-font="eyebrow">Release notes</span>
    <h2 data-font="h4">A second-level heading at the h4 size</h2>
    <p data-font="sm" style="--text: var(--color-muted-foreground)">Supporting text.</p>

    The sizes, leading, and tracking behind each role are tokens. Tune them on the typography page.

    Attributes

    font attributes
    AttributeKindValuesNotes
    data-fontConfig2xl 2xs display eyebrow h1 h2 h3 h4 h5 h6 lg md sm xl xsConfiguration the kit's script reads.

    API