Box

Primitive layout component for applying spacing, backgrounds, and borders. A flexible container for building custom layouts.

Setup

import { Box } from '@fragments-sdk/ui';

Examples

Default

Basic box with padding

Loading preview...

With Border

Bordered container

Loading preview...

Directional Padding

Different horizontal and vertical padding

Loading preview...

Centered with Auto Margin

Centered content using margin auto

Loading preview...

Directional Borders

Individual border sides

Loading preview...

With Shadow

Box with shadow elevation

Loading preview...

Overflow Hidden

Content overflow clipped

Loading preview...

Text Colors

Text color variants

Loading preview...

Props

PropTypeDefaultDescription
childrennodeNot setContent to render inside the box
asenumdivsectionarticleasidemainheaderfooternavspandivHTML element to render
paddingenumnonexssmmdlgxlNot setPadding on all sides
paddingXenumnonexssmmdlgxlNot setHorizontal padding
paddingYenumnonexssmmdlgxlNot setVertical padding
marginenumnonexssmmdlgxlautoNot setMargin on all sides
marginXenumnonexssmmdlgxlautoNot setHorizontal margin
marginYenumnonexssmmdlgxlautoNot setVertical margin
backgroundenumnoneprimarysecondarytertiaryelevatedNot setBackground color
roundedenumnonesmmdlgfullNot setBorder radius
borderbooleanfalseShow border
borderTopbooleanfalseShow top border only
borderBottombooleanfalseShow bottom border only
borderLeftbooleanfalseShow left border only
borderRightbooleanfalseShow right border only
borderColorenumdefaultstrongaccentdangerNot setBorder color variant (requires border or directional border)
shadowenumnonesmmdlgNot setBox shadow
overflowenumhiddenautoscrollvisibleNot setOverflow behavior
colorenumprimarysecondarytertiaryaccentinverseNot setText color
displayenumnoneblockinlineinline-blockflexinline-flexgridNot setDisplay type
widthunionNot setWidth (CSS value, e.g. "100%", "300px", or number for px)
minWidthunionNot setMin width
maxWidthunionNot setMax width
heightunionNot setHeight (CSS value)
minHeightunionNot setMin height
maxHeightunionNot setMax height
classNamestringNot setAdditional class name
styleobjectNot setInline styles

Usage Guidelines

When to use

  • Applying consistent padding or margin to content sections
  • Creating bordered or elevated containers
  • Wrapping content with semantic HTML elements
  • Building custom layouts not covered by Stack or Grid

When not to use

  • Horizontal or vertical stacking (use Stack)
  • Grid-based layouts (use Grid)
  • Card-like containers with header/body/footer (use Card)
  • Simple text styling (use Text)

Best practices

  • Use padding props instead of inline styles for consistency
  • Choose semantic HTML elements (section, article) where appropriate
  • Combine with Stack or Grid for complex layouts
  • Use background variants from the design system, not custom colors
  • Box forwards DOM props (id, role, aria-*, data-*, event handlers) to the rendered element
Accessibility
  • Choose semantic as prop values for proper document structure
  • Avoid div-soup; use meaningful elements like section, article
  • Ensure proper heading hierarchy within Box containers