1 | ---
|
2 | title: Heading
|
3 | storybookPath: typography-heading--default
|
4 | isExperimentalPackage: false
|
5 | ---
|
6 |
|
7 | Constrained, purposeful heading styles as a component.
|
8 |
|
9 | ## Level
|
10 |
|
11 | Controls 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`
|
13 | prop.
|
14 |
|
15 | ```jsx live
|
16 | const headingLevels = ['1', '2', '3', '4'];
|
17 |
|
18 | return (
|
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 |
|
31 | Headings 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 |
|
46 | Text 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 |
|
64 | Truncate text to a single line using the `truncate` prop. Useful for displaying
|
65 | user-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 |
|
77 | To ensure headings have sufficient contrast, when on a dark background the
|
78 | foreground 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 |
|
90 | Extra props are passed into the underlying [`Box`](/package/box) component.
|