Typography

Text and Heading share one type scale. This chapter covers its steps, its weights and its fonts.

Typography system with a nine-step scale (1-9) and three font weights. The token structure is from Radix Themes; the values are Womp UI's own.

Installation

npm install @kushagradhawan/kookie-ui

Usage

Use Text and Heading components to render titles and body copy. These components share size and weight props for consistent typography.

import { Text, Heading } from '@kushagradhawan/kookie-ui';
 
<Heading as="h1" size="4">Page Title</Heading>
<Text size="3">Body text content</Text>

Type Scale

Each step sets a font size, line height and letter spacing. Text, Heading, Link, Code, Kbd and Blockquote take sizes 1-9.

SizeFont sizeLine heightLetter spacing
112px16px0
214px20px0
316px24px0
418px26px-0.005em
520px28px-0.0075em
624px32px-0.01em
732px40px-0.015em
844px52px-0.02em
964px70px-0.025em
var(--font-size-3)       /* 16px */
var(--line-height-3)     /* 24px */
var(--letter-spacing-3)  /* 0 */

Heading uses the same line heights as Text.

Font Weight

Three weights: regular (400), medium (500) and semibold (600). Heading defaults to medium.

<Text weight="regular">Regular text</Text>
<Text weight="medium">Medium text</Text>
<Text weight="semibold">Semibold text</Text>

Emphasis

Use emphasis to rank text by colour. Text, Heading, Blockquote and Code take it.

  • loud is the strong ink, and the default once a colour is set.
  • medium is for secondary copy.
  • quiet is for the least important text, like hints and timestamps.
<Text>Invoice #1042</Text>
<Text emphasis="medium">Sent to finance on 12 March</Text>
<Text emphasis="quiet">Edited 2 minutes ago</Text>

With no color, emphasis uses the gray scale. With a color, it fades that colour. Text with neither inherits its colour from its parent.

Formatting

Use the native <em> and <strong> inside Text for emphasis:

<Text>
  The <em>most</em> important thing to remember is,{' '}
  <strong>stay positive</strong>.
</Text>
<Text>
  Use <Code>inline code</Code> for technical terms.
</Text>

Font Family

Every typeface decision lives in two tiers, and nowhere else.

Stacks — which typefaces exist. Three of them, declared on :root:

--font-sans   /* backs font="sans", and body text by default */
--font-mono   /* backs font="mono" and Code */
--font-serif  /* backs font="serif" */

Roles — which stack each kind of text uses. Declared on .kui-theme:

--font-body     /* Text, inputs, buttons, and anything that does not opt out */
--font-heading  /* Heading — follows --font-body unless you set it */
--font-code     /* Code */

Change a stack and every role using it moves with it. Change a role and only that role moves.

The Radix Themes names (--default-font-family, --heading-font-family, --code-font-family) are aliases of the roles above, kept so Radix documentation still applies. Overriding either spelling works.

Loading Fonts

Womp UI's stylesheet loads no webfonts. The defaults are system stacks, so importing the library costs zero font requests.

To use Womp UI's own typefaces — Inter, JetBrains Mono, Playfair Display — import the opt-in stylesheet:

import '@kushagradhawan/kookie-ui/styles.css';
import '@kushagradhawan/kookie-ui/fonts.css';

If you already load fonts yourself, skip that file and point the stacks at your faces instead. With next/font:

import { Inter } from 'next/font/google';
 
const inter = Inter({ subsets: ['latin'], variable: '--app-sans' });
 
export default function RootLayout({ children }) {
  return (
    <html className={inter.variable}>
      <body>{children}</body>
    </html>
  );
}
:root {
  --font-sans: var(--app-sans), system-ui, sans-serif;
}

Custom Fonts

Swap a typeface everywhere it is used by overriding a stack at :root:

:root {
  --font-sans: 'Poppins', system-ui, sans-serif;
  --font-mono: 'Fira Code', 'Menlo', monospace;
  --font-serif: 'Georgia', 'Times New Roman', serif;
}

Give a single role its own typeface by overriding it at .kui-theme:

/* Serif headings over a sans body */
.kui-theme {
  --font-heading: var(--font-serif);
}

Roles are declared on .kui-theme rather than :root because <Theme> switches them per subtree — an override at :root sits on an ancestor and would be overruled. Stacks are the opposite: declare those at :root.

Theme Props

fontFamily sets the body role for a subtree:

<Theme fontFamily="sans"><YourApp /></Theme>

headingFontFamily sets the heading role independently:

<Theme fontFamily="sans" headingFontFamily="serif">
  <Heading>Set in the serif stack</Heading>
  <Text>Set in the sans stack</Text>
</Theme>

Leave headingFontFamily off and headings follow the body font — including when fontFamily changes, and including when you have set --font-heading yourself.

Individual pieces of text opt out with the font prop, which reads the stacks directly:

<Text font="mono">v1.4.2</Text>

Defaults

VariableDefault
--font-sansSystem sans stack (-apple-system, Segoe UI, Roboto, …)
--font-monoSystem mono stack (Menlo, Consolas, …)
--font-serifSystem serif stack (Times New Roman, Georgia, …)
--font-bodyvar(--font-sans)
--font-headingvar(--font-body)
--font-codevar(--font-mono)

With @kushagradhawan/kookie-ui/fonts.css imported, the three stacks become Inter, JetBrains Mono and Playfair Display.

Credits

The typography token structure is from Radix Themes by WorkOS. However, Womp UI uses custom typography values that have been modified from the original Radix Themes values. The typography system structure and approach credit goes to Radix Themes, while the specific typography values are custom to Womp UI.