Box
A generic container that provides a flexible alternative for custom designs not achievable with existing components. Use it to apply styling such as backgrounds, padding, or borders, or to nest and group other components. The contents of Box always maintain their natural size, making it especially useful within layout components that would otherwise stretch their children.
Anchor to propertiesProperties
- Anchor to accessibilityLabelaccessibilityLabelstring
A label that describes the purpose or contents of the element. When set, it will be announced to users using assistive technologies and will provide them with more context.
Only use this when the element's content is not enough context for users using assistive technologies.
- Anchor to accessibilityRoleaccessibilityRoleAccessibilityRoleDefault: 'generic'
Sets 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 accessibilityVisibilityaccessibilityVisibility"visible" | "hidden" | "exclusive"Default: 'visible'
Changes the visibility of the element.
visible: the element is visible to all users.hidden: the element is removed from the accessibility tree but remains visible.exclusive: the element is visually hidden but remains in the accessibility tree.
- Anchor to backgroundbackgroundBackgroundColorKeywordDefault: 'transparent'
Adjust the background of the component.
- Anchor to blockSizeblockSizeSizeUnitsOrAutoDefault: 'auto'
Adjust the block size.
- Anchor to borderborderBorderShorthandDefault: 'none' - equivalent to `none base auto`.
Set the border via the shorthand property.
This can be a size, optionally followed by a color, optionally followed by a style.
If the color is not specified, it will be
base.If the style is not specified, it will be
auto.Values can be overridden by
,, and.- Anchor to borderColorborderColor"" | ColorKeywordDefault: '' - meaning no override
Adjust the color of the border.
- Anchor to borderRadiusborderRadiusMaybeAllValuesShorthandProperty<BoxBorderRadii>Default: 'none'
Adjust the radius of the border.
- Anchor to borderStyleborderStyle"" | MaybeAllValuesShorthandProperty<BoxBorderStyles>Default: '' - meaning no override
Adjust the style of the border.
- Anchor to borderWidthborderWidth"" | MaybeAllValuesShorthandProperty<"small" | "small-100" | "base" | "large" | "large-100" | "none">Default: '' - meaning no override
Adjust the width of the border.
- Anchor to displaydisplayMaybeResponsive<"auto" | "none">Default: 'auto'
Sets the outer display type of the component. The outer type sets a component's participation in flow layout.
autothe component's initial value. The actual value depends on the component and context.nonehides the component from display and removes it from the accessibility tree, making it invisible to screen readers.
- Anchor to inlineSizeinlineSizeSizeUnitsOrAutoDefault: 'auto'
Adjust the inline size.
- Anchor to maxBlockSizemaxBlockSizeSizeUnitsOrNoneDefault: 'none'
Adjust the maximum block size.
- Anchor to maxInlineSizemaxInlineSizeSizeUnitsOrNoneDefault: 'none'
Adjust the maximum inline size.
- Anchor to minBlockSizeminBlockSizeSizeUnitsDefault: '0'
Adjust the minimum block size.
- Anchor to minInlineSizeminInlineSizeSizeUnitsDefault: '0'
Adjust the minimum inline size.
- Anchor to overflowoverflow"visible" | "hidden"Default: 'visible'
Sets the overflow behavior of the element.
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.visible: the content that extends beyond the element’s container is visible.
- Anchor to paddingpaddingMaybeResponsive<MaybeAllValuesShorthandProperty<PaddingKeyword>>Default: 'none'
Adjust the padding of all edges.
1-to-4-value syntax is supported. Note that, contrary to the CSS, it uses flow-relative values and the order is:
- 4 values:
block-start inline-end block-end inline-start - 3 values:
block-start inline block-end - 2 values:
block inline
For example:
largemeans block-start, inline-end, block-end and inline-start paddings arelarge.large nonemeans block-start and block-end paddings arelarge, inline-start and inline-end paddings arenone.large none largemeans block-start padding islarge, inline-end padding isnone, block-end padding islargeand inline-start padding isnone.large none large smallmeans block-start padding islarge, inline-end padding isnone, block-end padding islargeand inline-start padding issmall.
A padding value of
autowill use the default padding for the closest container that has had its usual padding removed.paddingalso accepts a responsive value string with the supported PaddingKeyword as a query value.- 4 values:
- Anchor to paddingBlockpaddingBlockMaybeResponsive<"" | MaybeTwoValuesShorthandProperty<PaddingKeyword>>Default: '' - meaning no override
Adjust the block-padding.
large nonemeans block-start padding islarge, block-end padding isnone.
This overrides the block value of
padding.also accepts a responsive value string with the supported PaddingKeyword as a query value.- Anchor to paddingBlockEndpaddingBlockEndMaybeResponsive<"" | PaddingKeyword>Default: '' - meaning no override
Adjust the block-end padding.
This overrides the block-end value of
.also accepts a responsive value string with the supported PaddingKeyword as a query value.- Anchor to paddingBlockStartpaddingBlockStartMaybeResponsive<"" | PaddingKeyword>Default: '' - meaning no override
Adjust the block-start padding.
This overrides the block-start value of
.also accepts a responsive value string with the supported PaddingKeyword as a query value.- Anchor to paddingInlinepaddingInlineMaybeResponsive<"" | MaybeTwoValuesShorthandProperty<PaddingKeyword>>Default: '' - meaning no override
Adjust the inline padding.
large nonemeans inline-start padding islarge, inline-end padding isnone.
This overrides the inline value of
padding.also accepts a responsive value string with the supported PaddingKeyword as a query value.- Anchor to paddingInlineEndpaddingInlineEndMaybeResponsive<"" | PaddingKeyword>Default: '' - meaning no override
Adjust the inline-end padding.
This overrides the inline-end value of
.also accepts a responsive value string with the supported PaddingKeyword as a query value.- Anchor to paddingInlineStartpaddingInlineStartMaybeResponsive<"" | PaddingKeyword>Default: '' - meaning no override
Adjust the inline-start padding.
This overrides the inline-start value of
.also accepts a responsive value string with the supported PaddingKeyword as a query value.
AccessibilityRole
'main' | 'header' | 'footer' | 'section' | 'aside' | 'navigation' | 'ordered-list' | 'list-item' | 'list-item-separator' | 'unordered-list' | 'separator' | 'status' | 'alert' | 'generic' | 'presentation' | 'none'BackgroundColorKeyword
'transparent' | ColorKeywordColorKeyword
'subdued' | 'base' | 'strong'SizeUnitsOrAuto
SizeUnits | 'auto'SizeUnits
`${number}px` | `${number}%` | `0`BorderShorthand
Represents a shorthand for defining a border. It can be a combination of size, optionally followed by color, optionally followed by style.
BorderSizeKeyword | `${BorderSizeKeyword} ${ColorKeyword}` | `${BorderSizeKeyword} ${ColorKeyword} ${BorderStyleKeyword}`BorderSizeKeyword
SizeKeyword | 'none'SizeKeyword
'small-500' | 'small-400' | 'small-300' | 'small-200' | 'small-100' | 'small' | 'base' | 'large' | 'large-100' | 'large-200' | 'large-300' | 'large-400' | 'large-500'BorderStyleKeyword
'none' | 'solid' | 'dashed' | 'dotted' | 'auto'MaybeAllValuesShorthandProperty
T | `${T} ${T}` | `${T} ${T} ${T}` | `${T} ${T} ${T} ${T}`BoxBorderRadii
'small' | 'small-200' | 'small-100' | 'base' | 'large' | 'large-100' | 'large-200' | 'none'BoxBorderStyles
'auto' | 'none' | 'solid' | 'dashed'MaybeResponsive
T | `@container${string}`SizeUnitsOrNone
SizeUnits | 'none'PaddingKeyword
SizeKeyword | 'none'MaybeTwoValuesShorthandProperty
T | `${T} ${T}`Anchor to slotsSlots
- Anchor to childrenchildrenHTMLElement
The content of the Box.
Code
Examples
Code
jsx
<> <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> </>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 useful-forUseful for
- Creating custom designs when you can't build what you need with the existing components.
- Setting up specific stylings such as background colors, paddings, and borders.
- Nesting with other components.
Anchor to examplesExamples
Component examples
Anchor to example-basic-usageBasic usage
Anchor to example-basic-containerBasic container
Demonstrates creating a simple container with padding, base background, border, and rounded corners to group and highlight product information.
Anchor to example-responsive-shipping-noticeResponsive shipping notice
Illustrates using a box with responsive padding to create an adaptable container for shipping information that can adjust to different screen or container sizes.
Anchor to example-accessible-status-messagesAccessible status messages
Shows how to use boxes with ARIA roles and visibility controls to create semantic, screen-reader-friendly status and informational messages.
Anchor to example-nested-hierarchical-containersNested hierarchical containers
Demonstrates creating nested, hierarchical layouts using multiple boxes, showing how boxes can be combined to organize related content sections with different styling.
Basic container
Examples
Basic container
Description
Demonstrates creating a simple container with padding, base background, border, and rounded corners to group and highlight product information.
jsx
<s-box padding="base" background="base" borderWidth="base" borderColor="base" borderRadius="base" > <s-paragraph>Product information</s-paragraph> </s-box>html
<s-box padding="base" background="base" borderWidth="base" borderColor="base" borderRadius="base" > <s-paragraph>Product information</s-paragraph> </s-box>Responsive shipping notice
Description
Illustrates using a box with responsive padding to create an adaptable container for shipping information that can adjust to different screen or container sizes.
jsx
<s-query-container> <s-box padding="@container (inline-size > 400px) base, large-200" background="base" borderWidth="base" borderColor="base" > <s-text>Your order will be processed within 2-3 business days</s-text> </s-box> </s-query-container>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>Accessible status messages
Description
Shows how to use boxes with ARIA roles and visibility controls to create semantic, screen-reader-friendly status and informational messages.
jsx
<s-stack gap="base"> <s-box accessibilityRole="status" padding="base" background="strong" borderRadius="base" > <s-paragraph>Payment failed</s-paragraph> </s-box> <s-box accessibilityVisibility="exclusive"> <s-paragraph>Price includes tax and shipping</s-paragraph> </s-box> </s-stack>html
<s-stack gap="base"> <s-box accessibilityRole="status" padding="base" background="strong" borderRadius="base" > <s-paragraph>Payment failed</s-paragraph> </s-box> <s-box accessibilityVisibility="exclusive"> <s-paragraph>Price includes tax and shipping</s-paragraph> </s-box> </s-stack>Nested hierarchical containers
Description
Demonstrates creating nested, hierarchical layouts using multiple boxes, showing how boxes can be combined to organize related content sections with different styling.
jsx
<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>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>