Skip to the content

Box

Box is the generic block container: a <div> with display: block plus the layout props. Use it wherever you would write a raw <div>. It is layout only — no background, border, shadow or typography.
Layout & Surfaces

When to use

Use when
  • You need a plain block wrapper with padding, size or position, but no flex or grid layout.
  • You would otherwise render a raw <div>.
  • You show or hide a block by the width of its slot (display + cq).
Avoid when
  • Children sit on an axis — use Flex.
  • The layout is two-dimensional — use Grid.
  • The block needs a background, border or shadow — use Paper.

Usage

Box paints nothing; the dashed outline below only shows its bounds.

A plain block box — display: block plus layout props only.
<Box p="medium">
  <Text text="…" />
</Box>

Show or hide by slot width

display defaults to block as a prop value, so an explicit display and a cq / viewportMedias display override it. The nearest ancestor with containment is the measured slot. Make the window narrower than 640px to swap the two boxes.

Narrow slot: shown at base, hidden from lg up.
Wide slot: hidden at base, shown from lg up.
<Box containment="inline-size">
  <Box cq={{ lg: { display: 'none' } }}>{phoneList}</Box>
  <Box display="none" cq={{ lg: { display: 'block' } }}>
    {table}
  </Box>
</Box>

Semantic element (as)

Render Box as another element with as. Annotate a layout object as BoxProps when it sets as.

<Box as="section" p="medium">
  <Text as="h2" text="Rendered as <section>" />
</Box>

Accessibility

  • Box renders a <div> with no role. Use as when the block has meaning (section, aside, nav).
  • display: none removes the hidden branch from the accessibility tree; collapsing it with a zero size does not.

Properties

Box takes the layout props — spacing, size, position and the cq / viewportMedias channels — plus display and the native <div> attributes.

See also