UNPKG

1.88 kBMarkdownView Raw
1---
2title: Heading
3storybookPath: typography-heading--default
4isExperimentalPackage: false
5---
6
7Constrained, purposeful heading styles as a component.
8
9## Level
10
11Controls the size of the heading and maps to the appropriate heading element
12(`h1`, `h2`, `h3` or `h4`). The rendered element can be overridden with the `as`
13prop.
14
15```jsx live
16const headingLevels = ['1', '2', '3', '4'];
17
18return (
19 <Stack gap="large">
20 {headingLevels.map(headingLevel => (
21 <Heading key={headingLevel} as="h4" level={headingLevel} tone="neutral">
22 Heading level {headingLevel}
23 </Heading>
24 ))}
25 </Stack>
26);
27```
28
29## Tone
30
31Headings can be either "neutral" or "primary".
32
33```jsx live
34<Stack gap="large">
35 <Heading level="1" tone="neutral">
36 Heading neutral
37 </Heading>
38 <Heading level="1" tone="primary">
39 Heading primary
40 </Heading>
41</Stack>
42```
43
44## Alignment
45
46Text can be aligned with the `align` prop.
47
48```jsx live
49<Stack gap="small" dividers>
50 <Heading level="3" align="left">
51 Left (default)
52 </Heading>
53 <Heading level="3" align="center">
54 Center
55 </Heading>
56 <Heading level="3" align="right">
57 Right
58 </Heading>
59</Stack>
60```
61
62## Truncation
63
64Truncate text to a single line using the `truncate` prop. Useful for displaying
65user-generated content that may not fit within your layout.
66
67```jsx live
68<Stack gap="large" style={{ width: 200 }}>
69 <Heading level="3" truncate>
70 The quick brown fox jumps over the lazy
71 </Heading>
72</Stack>
73```
74
75## Contrast
76
77To ensure headings have sufficient contrast, when on a dark background the
78foreground colour is inverted.
79
80```jsx live
81<Box background="neutral" padding="large" borderRadius="small">
82 <Heading level="3">This Heading is inverted to improve contrast.</Heading>
83</Box>
84```
85
86## Props
87
88<PropsTable displayName="Heading" />
89
90Extra props are passed into the underlying [`Box`](/package/box) component.