Components / Feedback and display
Heading
A section or page heading. level sets the element (h1 to h6) and size sets how it looks, so the page outline stays correct whatever the design asks for. For text that is not a heading, use Text.
When to useLink to "When to use"
- A page title:
level={1}, once per page. Addsize="display"for a hero title. - A section or panel title:
levelfrom the page structure (a section inside a level 2 section is level 3), thensizeif the default looks too large or too small there. - A compact heading in dense UI: a small
sizewithtone="muted", still at the rightlevel.
Use something else when:
- the text is not a heading (body copy, captions, labels): Text
- it is rendered Markdown or other plain HTML: Prose, which styles the headings inside it
- it is the title of an empty view with an icon and a next step: EmptyState
- it labels a form control: Field
UsageLink to "Usage"
import { Heading } from "@arshad-shah/cynosure";
<Heading level={1}>Projects</Heading>
<Heading>Recent exports</Heading>
<Heading level={2} size="sm" tone="muted">Filters</Heading>
<Heading level={1} size="display" align="center">Capture anything</Heading>
<Heading level={3} truncate>{file.name}</Heading>Level and sizeLink to "Level and size"
Without size, each level takes its own step of the type scale: level 1 is 2xl, 2 is xl, 3 is lg, 4 is md, 5 is sm and 6 is xs. Setting size changes the look only. Every heading below is an h3. display grows with the viewport and stays between 1.25 and 2 times 2xl.
Tone, weight and alignmentLink to "Tone, weight and alignment"
tone is neutral (the ink colour), muted, accent or inherit (the colour of whatever the heading sits in). weight is bold or medium. align is start, center or end. Left unset, the heading follows its parent's alignment.
TruncationLink to "Truncation"
truncate keeps the heading on one line and ends it with an ellipsis. A number cuts it after that many lines. Text that fits is left alone.
PropsLink to "Props"
| Prop | What it does | Type | Default |
|---|---|---|---|
level | The element rendered (h1 to h6) and so the heading's place in the page outline. Default 2. | HeadingLevel | 2 |
size | How large it looks, whatever its level. Defaults to the level's size: 1 is "2xl", 2 is "xl", 3 is "lg", 4 is "md", 5 is "sm" and 6 is "xs". "3xl" is 1.4 times "2xl" at every width; "display" is larger still and grows with the viewport, for a page's hero title. | HeadingSize | |
tone | Text colour: the ink colour, muted, the accent, or whatever the parent uses. Default "neutral". | "accent" | "neutral" | "inherit" | "muted" | "neutral" |
weight | Font weight. Default "bold". | "medium" | "bold" | "bold" |
align | Text alignment, RTL aware. Left unset, it follows the parent. | "start" | "end" | "center" | |
truncate | true keeps it on one line and ends it with an ellipsis; a number cuts it after that many lines. Default false. | number | boolean | false |
id | Set on the heading element, for aria-labelledby and links to the section. | string | |
className | Added to the heading element, for layout. | string | |
style | Layout only. Restyle through --cy-heading-* tokens. | CSSProperties | |
children | The heading's text. | ReactNode |
Generated from the type definitions in @arshad-shah/cynosure 0.5.0.
Behaviour and accessibilityLink to "Behaviour and accessibility"
Heading is not interactive: it has no keyboard or pointer behaviour.
- Outline: it renders a real
h1toh6, so it appears in the page outline and in screen reader heading lists atlevel. Choose the level from the page structure and the size from the design. - Naming a region: pass
idand pointaria-labelledbyat it. - Truncated text: the full text stays the heading's accessible name.
- Wrapping: lines are balanced (
text-wrap: balance), and long words break instead of overflowing. - No margins: space headings with Stack or the layout around them.
- Right to left:
startandendswap sides, and a truncated heading keeps the start of its text. - Ref: the forwarded ref is the heading element.
TouchLink to "Touch"
Nothing in Heading is pressable, so it has no hit area.
ThemingLink to "Theming"
Tokens: --cy-heading-size-{xs,sm,md,lg,xl,2xl,display}, --cy-heading-font-family, --cy-heading-font-weight and --cy-heading-line-height.
| Token | Changes | Falls back to |
|---|---|---|
--cy-heading-size-xs to --cy-heading-size-2xl | Font size of each size | --cy-font-size-xs to --cy-font-size-2xl |
--cy-heading-size-display | Font size of size="display" | 5% of the viewport width, between 1.25 and 2 times --cy-font-size-2xl |
--cy-heading-font-family | Font family | --cy-font-display |
--cy-heading-font-weight | Weight of bold headings | --cy-font-weight-bold |
--cy-heading-line-height | Line height, as a number | 1.2 |
createTheme({ components: { heading: { sizeXl: "1.5rem", "size-2xl": "2rem", lineHeight: "1.15" } } });className and style are for layout only (margin, placement, width). Change the look through tokens so every product stays consistent.
RelatedLink to "Related"
Prose · Stack · EmptyState
These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.