PeakUI

Typography

Headings, paragraphs and code with the type scale, weights and colors of the design system

Usage

import {Code, Heading, Paragraph, Prose, Typography} from "@peakui/react";

Anatomy

import {Code, Heading, Paragraph, Prose, Typography} from "@peakui/react";

export default () => (
  <>
    <Heading level={2}>Title</Heading>
    <Paragraph>
      Body text with <Code>code</Code>.
    </Paragraph>
    <Typography type="body-sm" color="muted">
      Any type, set directly.
    </Typography>
    <Prose>{/* plain HTML, styled */}</Prose>
  </>
);

Heading, Paragraph and Code are presets of Typography: each one fixes its type. The element rendered follows the type, so a type="h3" renders an h3. To make text look like a heading without being one, use a body type; to keep a heading level for the outline and look different, style it with a className.

Examples

Headings

Paragraphs

Code

Muted and Weights

Truncate

Prose

Prose styles the plain HTML elements inside it, for content you do not control, such as rendered markdown.

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The Typography component uses these CSS classes (view source styles):

Base & Element Classes

  • .typography - Base class
  • .typography-prose - The Prose wrapper

Type Classes

  • .typography--h1 to .typography--h6
  • .typography--body, .typography--body-sm, .typography--body-xs
  • .typography--code

Modifier Classes

  • .typography--align-start, -center, -end, -justify
  • .typography--color-default, .typography--color-muted
  • .typography--weight-normal, -medium, -semibold, -bold
  • .typography--truncate

Slots

  • [data-slot="typography"], with data-type holding the type
  • [data-slot="prose"]

API Reference

Typography

PropTypeDefaultDescription
type'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'body' | 'body-sm' | 'body-xs' | 'code''body'The style, and the element it renders
align'start' | 'center' | 'end' | 'justify''start'Text alignment
color'default' | 'muted''default'Text color
weight'normal' | 'medium' | 'semibold' | 'bold'-Font weight; the type sets one when this is omitted
truncateboolean-Cut a single line with an ellipsis
classNamestring-Additional classes
...restEvery React Aria Text attribute is accepted

Heading

Takes every Typography prop except type, plus:

PropTypeDefaultDescription
level1 | 2 | 3 | 4 | 5 | 61The heading level, which is also the element

Paragraph

Takes every Typography prop except type, plus:

PropTypeDefaultDescription
size'base' | 'sm' | 'xs''base'The body size

Code

Takes every Typography prop except type.

Prose

PropTypeDefaultDescription
childrenReactNode-The plain HTML to style
classNamestring-Additional classes
...restEvery <div> attribute is accepted

On this page