Overview
Box is a primitive component that provides direct access to Paste design tokens through props. It’s the fundamental building block that underlies most Paste components and gives you complete control over layout, spacing, colors, borders, and other style properties using design tokens. Use Box when you need:- Fine-grained control over styling using design tokens
- To create custom layouts or components
- Access to responsive design capabilities
- To render any HTML element with Paste design token styling
Installation
Basic Usage
Props
Controls the HTML element that will be rendered in the DOM. Can be any valid HTML element like ‘div’, ‘span’, ‘section’, ‘article’, etc.
Overrides the default element name to apply unique styles with the Customization Provider. Used for customization and theming.
Used to style custom variants via customization.
Layout Props
Sets the CSS display property. Common values: ‘block’, ‘inline’, ‘flex’, ‘inline-flex’, ‘grid’, ‘none’.
Sets width using design tokens. Can use size tokens or CSS values.
Sets minimum width using design tokens.
Sets maximum width using design tokens.
Sets height using design tokens.
Sets minimum height using design tokens.
Sets maximum height using design tokens.
Sets both width and height to the same value using design tokens.
Sets the CSS overflow property. Values: ‘visible’, ‘hidden’, ‘scroll’, ‘auto’.
Spacing Props
Sets margin on all sides using space design tokens (e.g., ‘space40’, ‘space80’).
Sets top margin using space design tokens.
Sets right margin using space design tokens.
Sets bottom margin using space design tokens.
Sets left margin using space design tokens.
Sets horizontal (left and right) margin using space design tokens.
Sets vertical (top and bottom) margin using space design tokens.
Sets padding on all sides using space design tokens.
Sets top padding using space design tokens.
Sets right padding using space design tokens.
Sets bottom padding using space design tokens.
Sets left padding using space design tokens.
Sets horizontal (left and right) padding using space design tokens.
Sets vertical (top and bottom) padding using space design tokens.
Background Props
Sets background color using color design tokens (e.g., ‘colorBackgroundPrimaryWeak’).
Border Props
Sets border style. Values: ‘solid’, ‘dashed’, ‘dotted’, ‘none’.
Sets border color using color design tokens (e.g., ‘colorBorderPrimary’).
Sets border width on all sides using border width tokens (e.g., ‘borderWidth10’).
Sets top border width using border width tokens.
Sets right border width using border width tokens.
Sets bottom border width using border width tokens.
Sets left border width using border width tokens.
Sets border radius on all corners using border radius tokens (e.g., ‘borderRadius20’).
Sets top-left border radius using border radius tokens.
Sets top-right border radius using border radius tokens.
Sets bottom-left border radius using border radius tokens.
Sets bottom-right border radius using border radius tokens.
Position Props
Sets CSS position property. Values: ‘static’, ‘relative’, ‘absolute’, ‘fixed’, ‘sticky’.
Sets top position offset.
Sets right position offset.
Sets bottom position offset.
Sets left position offset.
Sets z-index using design tokens.
Shadow Props
Sets box shadow using shadow design tokens (e.g., ‘shadow’).
Flexbox Props
Box includes all flexbox properties when used as a flex container or flex item:Controls flex item alignment on the cross axis.
Controls flex item alignment on the main axis.
Sets flex direction. Values: ‘row’, ‘column’, ‘row-reverse’, ‘column-reverse’.
Sets flex wrapping behavior. Values: ‘nowrap’, ‘wrap’, ‘wrap-reverse’.
Sets the flex shorthand property.
Sets flex grow factor.
Sets flex shrink factor.
Sets flex basis.
Grid Props
Box includes grid properties when used as a grid container:Sets grid template columns.
Sets grid template rows.
Sets gap between grid items.
Sets gap between grid columns.
Sets gap between grid rows.
Pseudo-class Props
Box supports pseudo-class styling through special props:Styles applied on hover state. Accepts any Box style props.
Styles applied on focus state. Accepts any Box style props.
Styles applied on active state. Accepts any Box style props.
Styles applied when disabled. Accepts any Box style props.
Responsive Design
Many Box props support responsive values by passing an array of values. Each value in the array corresponds to a breakpoint:Examples
Card-like Container
Flex Container
As Different HTML Elements
With Pseudo States
Best Practices
Use Design Tokens
Always use design tokens for styling rather than arbitrary CSS values. This ensures consistency and makes your UI themeable:Choose the Right Abstraction
While Box is powerful, consider using higher-level layout components for common patterns:- Use Flex for flexbox layouts
- Use Grid for grid layouts
- Use Stack for simple stacking layouts
- Use Box when you need fine-grained control or these don’t fit your needs
Semantic HTML
Use theas prop to render semantically appropriate HTML elements:
Responsive Design
Leverage responsive prop arrays for mobile-first design:Accessibility
- Use semantic HTML elements via the
asprop when appropriate - Ensure sufficient color contrast when setting custom background and text colors
- Don’t rely solely on color to convey information
- When creating interactive elements, ensure they’re keyboard accessible
Related Components
- Flex - Simplified flexbox layouts
- Grid - 12-column grid system
- Stack - Vertical or horizontal stacking
- Media Object - Media object pattern