Skip to main content

Description

The Box component is a versatile container component that provides a foundation for building layouts. It’s a simple wrapper around a div element with consistent box-sizing behavior, allowing you to pass any standard HTML attributes and custom styling.

Props

Box extends all standard HTML div attributes and accepts the following props:
React.ReactNode
The content to be rendered inside the Box component
string
Additional CSS class names to apply to the Box
React.RefObject<HTMLDivElement>
A ref object to access the underlying div element
HTMLAttributes<HTMLDivElement>
All standard HTML div attributes are supported including:
  • id - Element ID
  • role - ARIA role attribute
  • aria-label - Accessibility label
  • aria-labelledby - ID of the labeling element
  • data-* - Data attributes
  • Event handlers (onClick, onMouseEnter, etc.)

Usage examples

Basic usage

With custom className

With multiple children

Nested boxes

With ref

With ARIA attributes

With dynamic children

Styling notes

The Box component applies a single CSS property by default:
  • box-sizing: border-box - Ensures padding and border are included in the element’s total width and height
This ensures consistent sizing behavior across all Box instances. You can apply additional styles through the className prop or inline styles.
  • Flex - For flexbox layouts
  • Grid - For grid layouts
  • Container - For constrained-width containers