Divider
A line that separates two regions of content, announced as a separator or left out of the accessibility tree.
Billing
Invoices are issued on the first business day of each month.Members
Eleven people in the Northwind operations team can approve orders.import { Divider } from '@slotted/react/divider';import { Stack } from '@slotted/react/stack';import { Heading, Text } from '@slotted/react/typography';export default function DividerBasic() { return ( <Stack gap={4}> <Stack gap={1}> <Heading level={2} size="sm"> Billing </Heading> <Text size="sm" tone="muted"> Invoices are issued on the first business day of each month. </Text> </Stack> <Divider /> <Stack gap={1}> <Heading level={2} size="sm"> Members </Heading> <Text size="sm" tone="muted"> Eleven people in the Northwind operations team can approve orders. </Text> </Stack> </Stack> );}Installation
The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.
pnpm add @slotted/react @slotted/theme @slotted/themesSeparating two regions
A divider marks the boundary between two regions of content with one line. The plain rule is an hr, which already carries the separator role, so a screen reader announces the boundary without any attribute from the component. Use it where the content on each side is of the same kind, as in the example above. To space two blocks without a line, set the gap of a Stack instead.
Orientation
orientation sets the direction of the rule: horizontal, the default, or vertical. A horizontal rule takes the width of its container. A vertical rule stretches to the height of its row, whatever the alignment of the other items. A vertical rule sets aria-orientation="vertical", because a separator is horizontal unless it says otherwise.
17 shipped today
17 shipped today
import { Divider } from '@slotted/react/divider';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function DividerOrientation() { return ( <Stack gap={6}> <Stack gap={3}> <Text size="sm" tone="muted"> horizontal </Text> <Text>42 open orders</Text> <Divider orientation="horizontal" /> <Text>17 shipped today</Text> </Stack> <Stack gap={3}> <Text size="sm" tone="muted"> vertical </Text> <Inline gap={4}> <Text>42 open orders</Text> <Divider orientation="vertical" /> <Text>17 shipped today</Text> </Inline> </Stack> </Stack> );}Label
label interrupts the rule with a short text. A labelled rule is a div, because an hr takes no content, and it writes role="separator". React renders that element; in Angular, slDivider goes on a div you write. The text also becomes the accessible name through aria-label: the separator role makes its children presentational, so the visible text alone would leave the rule announced as empty. An aria-label of your own replaces it.
import { Divider } from '@slotted/react/divider';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function DividerLabel() { return ( <Stack gap={4}> <Text>Pay with the card on file, ending in 4242.</Text> <Divider label="Or" /> <Text>Send a bank transfer to Northwind Freight, reference INV-20418.</Text> </Stack> );}Label position
align places the label along the rule: start, center or end, in logical terms, so start is the right end in a right-to-left layout. The default is center. A label at one end keeps one half of the rule. It applies only to a rule that has a label.
import { Divider } from '@slotted/react/divider';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function DividerAlign() { return ( <Stack gap={3}> <Divider align="start" label="Today" /> <Text size="sm">3 shipments left the Rotterdam warehouse.</Text> <Divider align="center" label="Yesterday" /> <Text size="sm">5 shipments left, 1 was returned.</Text> <Divider align="end" label="Earlier this week" /> <Text size="sm">11 shipments left, all delivered.</Text> </Stack> );}Vertical label
A vertical rule takes a label too. The text sits between two halves of the rule, and align places it along the height of the rule.
import { Divider } from '@slotted/react/divider';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';export default function DividerVerticalLabel() { return ( <Inline gap={4}> <Stack gap={1}> <Text weight="semibold">Pay by card</Text> <Text size="sm" tone="muted"> Charged today </Text> <Text size="sm" tone="muted"> Receipt by email </Text> </Stack> <Divider label="Or" orientation="vertical" /> <Stack gap={1}> <Text weight="semibold">Pay by transfer</Text> <Text size="sm" tone="muted"> Due in 30 days </Text> <Text size="sm" tone="muted"> Reference INV-20418 </Text> </Stack> </Inline> );}Inset
inset stops the rule short of both ends of its container. The margin is the inline padding of a control, so a rule inside a list of rows lines up with their text. It applies to both orientations: a horizontal rule gains margin at its inline ends, a vertical rule at its block ends. Each card below holds rows of buttons: in the second, the rule starts where the text of the rows starts.
Full length
inset
import { Button } from '@slotted/react/button';import { Card, CardBody, CardHeader } from '@slotted/react/card';import { Divider } from '@slotted/react/divider';import { Stack } from '@slotted/react/stack';import { Heading } from '@slotted/react/typography';const CARRIERS = ['Northwind Freight', 'Harbor Line', 'Alpine Express'];export default function DividerInset() { return ( <Stack gap={4}> {[false, true].map((inset) => ( <Card key={String(inset)}> <CardHeader> <Heading level={2} size="sm"> {inset ? 'inset' : 'Full length'} </Heading> </CardHeader> <CardBody> <Stack gap={2}> {CARRIERS.map((carrier, index) => [ index > 0 && <Divider inset={inset} key={`rule-${carrier}`} />, <Button fullWidth justify="between" key={carrier} tone="secondary" variant="ghost"> {carrier} </Button>, ])} </Stack> </CardBody> </Card> ))} </Stack> );}Decorative
decorative removes the rule from the accessibility tree: the element takes role="none", so a screen reader announces no separator. Use it when the line groups content visually and a listener loses nothing by not hearing it. A rule without decorative is announced as a separator, and a labelled one is announced with its label as the name. A decorative labelled rule has no name; its text is read in document order, like any other text.
Announced
Order 20418 was handed to the carrier.
decorative
Order 20418 was handed to the carrier.
import { Card, CardBody, CardHeader } from '@slotted/react/card';import { Divider } from '@slotted/react/divider';import { Stack } from '@slotted/react/stack';import { Heading, Text } from '@slotted/react/typography';export default function DividerDecorative() { return ( <Stack gap={4}> {[false, true].map((decorative) => ( <Card key={String(decorative)}> <CardHeader> <Heading level={2} size="sm"> {decorative ? 'decorative' : 'Announced'} </Heading> </CardHeader> <CardBody> <Stack gap={3}> <Text>Order 20418 was packed.</Text> <Divider decorative={decorative} /> <Text>Order 20418 was handed to the carrier.</Text> <Divider decorative={decorative} label="Delivery" /> <Text>Order 20418 is due on Thursday.</Text> </Stack> </CardBody> </Card> ))} </Stack> );}Between values
A row of figures separated by vertical rules is the common use of a vertical divider. The rules are decorative because the figures already carry their own labels. Each rule is as tall as the row.
import { Card, CardBody } from '@slotted/react/card';import { Divider } from '@slotted/react/divider';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const FIGURES = [ { label: 'Orders', value: '1,284' }, { label: 'Revenue', value: '$48,200' }, { label: 'Returns', value: '2.1%' },];export default function DividerValues() { return ( <Card> <CardBody> <Inline gap={6}> {FIGURES.flatMap((figure, index) => [ index > 0 ? ( <Divider decorative key={`rule-${figure.label}`} orientation="vertical" /> ) : null, <Stack gap={1} key={figure.label}> <Text size="sm" tone="muted"> {figure.label} </Text> <Text numeric="tabular" size="3xl" weight="semibold"> {figure.value} </Text> </Stack>, ])} </Inline> </CardBody> </Card> );}Accessibility
- The plain rule is an hr, which already exposes the separator role, so the component writes no role of its own.
- A vertical rule receives aria-orientation, because a separator is horizontal unless it says otherwise.
- decorative sets role="none". Use it when the rule groups content visually and a screen reader user loses nothing by not hearing it.
- A labelled rule renders a div, because an hr takes no content. Its name comes from aria-label: the separator role makes its children presentational, so the visible label alone would leave the rule announced as empty.
- A decorative rule carries no name, because role="none" prohibits one. Its label is read in document order, like any other text.
- A rule rendered into another element — the li a menu separator has to be — receives role="separator", because only the hr carries that meaning by itself.
- A role or an aria-label you pass is kept, so a rule that has to say something else keeps saying it.
API
divider
Props
orientation'horizontal' | 'vertical'Defaulthorizontal- Sets the direction the rule runs in.
decorativebooleanDefaultfalse- Removes the rule from the accessibility tree.
insetbooleanDefaultfalse- Stops the rule short of both ends of its container.
labelstring- Short text that interrupts the rule. It is also the rule’s accessible name.
align'start' | 'center' | 'end'Defaultcenter- Sets the position of the label along the rule.
render(props) => ReactNode- Renders a different root element from the props it receives.
Theming
Each token is a CSS custom property: set it in a theme, or on any element to retune every divider inside it.
Divider tokens
| Token | Default |
|---|---|
--slotted-divider-color | var(--slotted-border-subtle, ButtonBorder) |
--slotted-divider-gap | var(--slotted-space-4, 0.5rem) |
--slotted-divider-inset | var(--slotted-control-padding-inline-md, 13px) |
--slotted-divider-label-color | var(--slotted-text-muted, GrayText) |
--slotted-divider-min-length | 1em |
--slotted-divider-thickness | var(--slotted-border-width-thin, 1px) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-border-subtle | Set per scheme by the theme |
--slotted-border-width-thin | 1px |
--slotted-control-padding-inline-md | comfortable 13px · compact 10px · dense 8px |
--slotted-font-family-sans | 'Geist Variable', ui-sans-serif, system-ui, sans-serif |
--slotted-font-size-xs | 0.75rem |
--slotted-font-weight-medium | 500 |
--slotted-line-height-xs | 1.4 |
--slotted-space-4 | 0.5rem |
--slotted-space-5 | 0.75rem |
--slotted-text-muted | Set per scheme by the theme |