Tonic UI
Getting StartedColor ModeColor StyleContributing
THEME
BordersBreakpointsColorsPositionsSpacingSizesShadowsTypography
BUILDING BLOCKS
BoxControlBox
UTILITIES

Box

The Box component serves as a wrapper component for most of the CSS utility needs. It allows you to control styles using style props for building UI components with Styled System.

Dark Mode
Box
Tonic UI

Import

Usage

EDITABLE EXAMPLE

The as prop and custom component

By default, the Box component renders a div element. There might be cases where you want to render a different element, you can use the as prop to do that.

EDITABLE EXAMPLE

Using pseudo props

Box also provides useful props to style common CSS pseudo-class and pseudo-element selectors.

A pseudo-class selector targets elements depending on their state rather than on information from the document tree. For example, the selector :hover matches when the user interacts with an element with a pointing device, but does not necessary activate it.

A pseudo-element selector applies styles to parts of your document content in scenarios where there isn't a specific HTML element to select. For example, ::before creates a pseudo-element that is the first child of the selected element. It is often used to add cosmetic content to an element with the content property.

NameSelector
_active&:active
_checked&:checked
_disabled&:disabled
_empty&:empty
_enabled&:enabled
_firstChild&:first-child
_firstOfType&:first-of-type
_fullscreen&:fullscreen
_focus&:focus
_focusWithin&:focus-within
_hover&:hover
_indeterminate&:indeterminate
_invalid&:invalid
_lastChild&:last-child
_lastOfType&:last-of-type
_nthOfType&:nth-of-type()
_readOnly&:read-only
_visited&:visited
__after&::after
__backdrop&::backdrop
__before&::before
__cue&::cue
__firstLetter&::first-letter
__firstLine&::first-line
__placeholder&::placeholder
__selection&::selection

:hover

Add the _hover prop to apply style props on hover.

EDITABLE EXAMPLE

:active

Add the _active prop to apply style props on active.

EDITABLE EXAMPLE

:focus

Add the _focus prop to apply style props on focus.

EDITABLE EXAMPLE

:disabled

Add the _disabled prop to style an element which is disabled.

EDITABLE EXAMPLE

:visited

Add the _visited prop to style a visited link.

EDITABLE EXAMPLE

:first-child

Add the _firstChild prop to style an element that is the first element among its siblings.

EDITABLE EXAMPLE

:last-child

Add the _lastChild prop to style an element that is the last element among its siblings.

EDITABLE EXAMPLE

:nth-of-type()

Add the _nthOfType prop to match elements of a given type, based on their position among a group of siblings. The value can be represented as an array or an object in the following form:

EDITABLE EXAMPLE

:nth-of-type(odd)

EDITABLE EXAMPLE

:nth-of-type(even)

EDITABLE EXAMPLE

Examples

Let's take a look at some examples of how to use Box to style elements.

Responsive layout

EDITABLE EXAMPLE