Skip to main content

Box

The Box component is the primary wrapper for grouping content. It uses a synchronized semantic scale and a strict 4px/8px grid for visual rhythm and pixel-perfect rendering. Backgrounds, padding, and corner radius are all driven by design tokens.

Import

// with @dhl-official/react-library:
import { DhlBox } from "@dhl-official/react-library"
// with @dhl-official/ui-libraries/react-library:
import { DhlBox } from "@dhl-official/ui-libraries/react-library"

Code

<DhlBox variant="primary" padding="standard" radius="standard">
<DhlHeadline designLevel="4" noMargin>Box heading</DhlHeadline>
<DhlText>Box content</DhlText>
</DhlBox>

Layering

Every page begins with --dui-colors-background-base as the canvas. The box's variant prop selects the surface that sits on that canvas:

variantBackground tokenUse
primary--dui-colors-background-primaryMain boxes sitting on the page base
secondary--dui-colors-background-secondaryNested boxes / internal grouping
tertiary--dui-colors-background-tertiaryDeeper nested grouping
brand--dui-colors-background-functional-post-yellowBrand-specific highlight surface

Spacing tokens

paddingTokenValue
extra-roomy--dui-box-padding-extra-roomy40px
roomy--dui-box-padding-roomy32px
relaxed--dui-box-padding-relaxed24px
standard--dui-box-padding-standard16px
compact--dui-box-padding-compact12px
tight--dui-box-padding-tight8px
extra-tight--dui-box-padding-extra-tight4px
none--dui-box-padding-none0px

Radius tokens

radiusTokenValue
display--dui-box-radius-display32px
hero--dui-box-radius-hero24px
standard--dui-box-radius-standard16px
compact--dui-box-radius-compact12px
tight--dui-box-radius-tight8px

Concentric nesting

When boxes are nested, choose the inner radius so the inner corner stays concentric with the outer corner:

inner_radius = outer_radius − inner_padding

For example, an outer box with radius="hero" (24px) and padding="tight" (8px) wrapping an inner box produces a concentric corner when the inner radius="standard" (16px), since 16 = 24 − 8.

<DhlBox variant="secondary" padding="tight" radius="hero">
<DhlBox variant="primary" padding="standard" radius="standard">
<DhlText>Inner content</DhlText>
</DhlBox>
</DhlBox>

Interactive Demo

Readme

Properties

PropertyAttributeDescriptionTypeDefault
dataAriaLabeldata-aria-labelAn optional prop defining the text read by the screen reader to represent the component; use this if you need different text to be read from label.stringundefined
dataClassNamedata-class-nameAn optional class name prop for the component.stringundefined
dataIddata-idAn optional prop. Gives a valid HTML ID attribute value for the component.string`dhl-box-${getRandomString()}`
dataRoledata-roleAn optional prop defining the role attribute of the component.stringundefined
dataTestiddata-testidAn optional prop. The test id attached to the component as a data-testid attribute.stringundefined
paddingpaddingAn optional prop defining the inner padding of the box using the 4px/8px grid spacing tokens."compact" | "extra-roomy" | "extra-tight" | "none" | "relaxed" | "roomy" | "standard" | "tight"DHL_BOX.PADDING.STANDARD
radiusradiusAn optional prop defining the corner radius of the box."compact" | "display" | "hero" | "standard" | "tight"DHL_BOX.RADIUS.STANDARD
tagtagAn optional prop defining the rendered semantic HTML tag."article" | "aside" | "div" | "section"DHL_BOX.TAG.DIV
variantvariantAn optional prop defining the background variant of the box. primary sits on the page base, secondary/tertiary are for nested or internal grouping, and brand uses the post-yellow functional highlight."brand" | "primary" | "secondary" | "tertiary"DHL_BOX.VARIANT.PRIMARY

Slots

SlotDescription
"unnamed"unnamed children slot for DhlBox content

Built by DHL User Interface Library Team!