Skip to main content

Box

The box component provides a generic, flexible container for custom designs and layouts. Use box to apply styling like backgrounds, padding, borders, or border radius when existing components don't meet your needs, or to nest and group other components.

Box contents maintain their natural size, making it especially useful within layout components that would otherwise stretch their children. For structured layouts, use stack or grid.


Configure the following properties on the box component.

Anchor to accessibilityRole
accessibilityRole
Default: 'generic'
required

The semantic meaning of the component’s content. When set, the role will be used by assistive technologies to help users navigate the page.

Anchor to background
background
Default: 'transparent'
required

The background color of the component.

Anchor to blockSize
blockSize
Default: 'auto'
required

The vertical size of the element in standard layouts (height in left-to-right or right-to-left writing modes).

Block size adjusts based on the writing direction: in horizontal layouts, it controls the height; in vertical layouts, it controls the width. This ensures consistent behavior across different text directions.

Learn more about block-size.

Anchor to minBlockSize
minBlockSize
Default: '0'
required

The minimum height in horizontal writing modes, or minimum width in vertical writing modes. Prevents the element from shrinking below this size.

Learn more about min-block-size.

Anchor to maxBlockSize
maxBlockSize
Default: 'none'
required

The maximum height in horizontal writing modes, or maximum width in vertical writing modes. Prevents the element from growing beyond this size.

Learn more about max-block-size.

Anchor to inlineSize
inlineSize
Default: 'auto'
required

The width in horizontal writing modes, or height in vertical writing modes. Use this for flow-relative sizing that adapts to text direction. Learn more about inline-size.

Anchor to minInlineSize
minInlineSize
Default: '0'
required

The minimum width in horizontal writing modes, or minimum height in vertical writing modes. Prevents the element from shrinking below this size.

Learn more about min-inline-size.

Anchor to maxInlineSize
maxInlineSize
Default: 'none'
required

The maximum width in horizontal writing modes, or maximum height in vertical writing modes. Prevents the element from growing beyond this size.

Learn more about max-inline-size.

Anchor to overflow
overflow
"visible" | "hidden"
Default: 'visible'
required

The overflow behavior of the element.

  • visible: the content that extends beyond the element’s container is visible.
  • hidden: clips the content when it is larger than the element’s container. The element will not be scrollable and the users will not be able to access the clipped content by dragging or using a scroll wheel on a mouse.
Anchor to padding
padding
<<>>
Default: 'none'
required

The padding applied to all edges of the component.

Supports 1-to-4-value syntax using flow-relative values:

  • 1 value applies to all sides
  • 2 values apply to block (top/bottom) and inline (left/right)
  • 3 values apply to block-start (top), inline (left/right), and block-end (bottom)
  • 4 values apply to block-start (top), inline-end (right), block-end (bottom), and inline-start (left)

Examples: base, large none, base large-100 base small

Use auto to inherit padding from the nearest container with removed padding. Also accepts a responsive value string with the supported PaddingKeyword as a query value.

Anchor to paddingBlock
paddingBlock
<"" | <>>
Default: '' - meaning no override
required

The block-direction padding (top and bottom in horizontal writing modes).

Accepts a single value for both sides or two space-separated values for block-start and block-end.

Example: large none applies large to the top and none to the bottom.

Overrides the block value from padding. Also accepts a responsive value string with the supported PaddingKeyword as a query value.

Anchor to paddingBlockStart
paddingBlockStart
<"" | >
Default: '' - meaning no override
required

The block-start padding (top in horizontal writing modes).

Overrides the block-start value from paddingBlock. Also accepts a responsive value string with the supported PaddingKeyword as a query value.

Anchor to paddingBlockEnd
paddingBlockEnd
<"" | >
Default: '' - meaning no override
required

The block-end padding (bottom in horizontal writing modes).

Overrides the block-end value from paddingBlock. Also accepts a responsive value string with the supported PaddingKeyword as a query value.

Anchor to paddingInline
paddingInline
<"" | <>>
Default: '' - meaning no override
required

The inline-direction padding (left and right in horizontal writing modes).

Accepts a single value for both sides or two space-separated values for inline-start and inline-end.

Example: large none applies large to the left and none to the right.

Overrides the inline value from padding. Also accepts a responsive value string with the supported PaddingKeyword as a query value.

Anchor to paddingInlineStart
paddingInlineStart
<"" | >
Default: '' - meaning no override
required

The inline-start padding (left in LTR writing modes, right in RTL).

Overrides the inline-start value from paddingInline. Also accepts a responsive value string with the supported PaddingKeyword as a query value.

Anchor to paddingInlineEnd
paddingInlineEnd
<"" | >
Default: '' - meaning no override
required

The inline-end padding (right in LTR writing modes, left in RTL).

Overrides the inline-end value from paddingInline. Also accepts a responsive value string with the supported PaddingKeyword as a query value.

Anchor to border
border
Default: 'none' - equivalent to `none base auto`.
required

A border applied using shorthand syntax to specify width, color, and style in a single property.

Anchor to borderWidth
borderWidth
"" | <"small" | "small-100" | "base" | "large" | "large-100" | "none">
Default: '' - meaning no override
required

The thickness of the border on all sides. When set, this overrides the width value specified in the border property.

Anchor to borderStyle
borderStyle
"" | <>
Default: '' - meaning no override
required

The visual style of the border on all sides, such as solid, dashed, or dotted. When set, this overrides the style value specified in the border property.

Anchor to borderColor
borderColor
"" |
Default: '' - meaning no override
required

The color of the border using the design system's color scale. When set, this overrides the color value specified in the border property.

Anchor to borderRadius
borderRadius
<>
Default: 'none'
required

The roundedness of the element's corners using the design system's radius scale.

Anchor to accessibilityLabel
accessibilityLabel
string
required

A label that describes the purpose or content of the component for assistive technologies like screen readers. Use this to provide additional context when the visible content alone doesn't clearly convey the component's purpose.

Anchor to accessibilityVisibility
accessibilityVisibility
"visible" | "hidden" | "exclusive"
Default: 'visible'
required

The visibility mode of the element for both visual and assistive technology users.

  • visible: The element is visible to all users (both sighted users and screen readers).
  • hidden: The element is visually visible but hidden from screen readers. Use this for decorative elements that don't provide meaningful information.
  • exclusive: The element is visually hidden but announced by screen readers. Use this for screen-reader-only content like skip links or additional context.
Anchor to display
display
<"auto" | "none">
Default: 'auto'
required

The outer display type of the component. The outer type sets a component's participation in flow layout.

  • auto the component's initial value. The actual value depends on the component and context.
  • none hides the component from display and removes it from the accessibility tree, making it invisible to screen readers.

The box component supports slots for additional content placement within the component. Learn more about using slots.

Anchor to children
children
HTMLElement

The content displayed within the box component, which serves as a flexible container for organizing and styling other components.


Anchor to Add a content containerAdd a content container

Create a container with padding and optional visual styling. This example shows a plain box and a styled box with background, border, and rounded corners.

Preview

html

<s-box padding="base">Available for iPad, iPhone, and Android.</s-box>

<s-box padding="base" background="subdued" border="base" borderRadius="base">
Available for iPad, iPhone, and Android.
</s-box>

Anchor to Adapt spacing with responsive paddingAdapt spacing with responsive padding

Use responsive padding values with container queries to adapt spacing based on available width. This example shows a shipping notice that adjusts its padding depending on the container size.

Preview

html

<s-query-container>
<s-box
padding="@container (inline-size > 400px) base, large-200"
background="base"
borderWidth="base"
borderColor="base"
>
<s-paragraph>Your order will be processed within 2-3 business days</s-paragraph>
</s-box>
</s-query-container>

Anchor to Announce dynamic updates with a live regionAnnounce dynamic updates with a live region

Set the accessibilityRole property to status to create a live region. When your code updates the text inside this box , screen readers automatically announce the new content. Use this for any content that updates dynamically.

Preview

html

<s-box
accessibilityRole="status"
padding="base"
background="strong"
borderRadius="base"
>
<s-paragraph>Syncing inventory: 3 of 10 products updated</s-paragraph>
</s-box>

Anchor to Add screen-reader-only contentAdd screen-reader-only content

Set the accessibilityVisibility property to exclusive to hide content visually while keeping it available to screen readers. This example shows a box with pricing context that only assistive technology users can access.

Preview

html

<s-box accessibilityVisibility="exclusive">
<s-paragraph>Price includes tax and shipping</s-paragraph>
</s-box>

Anchor to Build nested card layoutsBuild nested card layouts

Nest boxes to create hierarchical layouts with distinct visual sections. This example shows an inventory status section and a product sales section organized as cards within a vertical stack.

Preview

html

<s-stack gap="base">
<!-- Inventory status section -->
<s-box
padding="base"
background="base"
borderRadius="base"
borderWidth="base"
borderColor="base"
>
<s-stack gap="base">
<s-box padding="small-100" background="subdued" borderRadius="small">
<s-paragraph>In stock: 45 units</s-paragraph>
</s-box>
<s-box padding="small-100" background="subdued" borderRadius="small">
<s-paragraph>Low stock alert: 5 units</s-paragraph>
</s-box>
</s-stack>
</s-box>

<!-- Product information section -->
<s-box
padding="base"
background="base"
borderRadius="base"
borderWidth="base"
borderColor="base"
>
<s-stack gap="base">
<s-heading>Product sales</s-heading>
<s-paragraph color="subdued">No recent sales of this product</s-paragraph>
<s-link>View details</s-link>
</s-stack>
</s-box>
</s-stack>

  • Use for layout and grouping: The component provides spacing, borders, and backgrounds for organizing content. When you need specific layout patterns like rows or columns, use stack or grid instead. The component works best as a general-purpose container.
  • Consider semantic alternatives first: Before using the component, check whether a more specific component like section or banner better describes your content's purpose. Semantic components provide better accessibility and clearer intent.
  • Design for different screen sizes: Layouts that work on desktop might not work on mobile. Use responsive properties to adjust spacing and layout based on available space rather than creating fixed layouts.
  • Make interactive containers accessible: When boxes contain interactive content or represent distinct regions, provide appropriate ARIA roles and labels so screen reader users can navigate and understand the interface structure.
  • Avoid excessive nesting: Deep nesting of boxes creates complex DOM structures and makes styling harder to manage. Look for opportunities to simplify your layout or use more appropriate layout components.

Was this page helpful?