Navigated to /docs/ui/components/box

Box

Generic token-backed layout and surface primitive.

Preview

A live, theme-aware example rendered with the published component.

Loading preview…

Import

Import the component from its dedicated entry point to keep the dependency and generated bundle explicit.

TSX
tsximport { Box } from "@tavojs/ui/box";

Normal Tavo.js applications load component styles through the Tavo.js UI plugin. If the application manages component CSS manually, also import @tavojs/ui/css/box.

When to use

Use it when

Use `Box` for generic token-backed surfaces, page width constraints, and one-off layout wrappers

Choose something else when

Avoid Box when for interactive form state; combine with form, feedback, or data components instead.

Examples

Box example

TSX
tsximport { Box } from "@tavojs/ui/box";

export function BoxExample1() {
  return (
    <>
      <Box surface="raised" padding="lg" radius="lg" border>
        Content
      </Box>
      
      <Box as="main" maxWidth="lg" paddingInline="lg" center fullWidth>
        Page content
      </Box>
    </>
  );
}

Common props and defaults

PropTypeDefaultDescription
classNamestring

Optional class hook applied to the public root element owned by the component.
asstring | Component<Record<string, unknown>>

Changes the rendered root element or component while preserving Tavo.js UI styling and public props.
surface"default" | "raised" | "subtle" | "primary" | "secondary" | "neutral"

Configures surface for this component.
padding"none" | "sm" | "md" | "lg"

Configures padding for this component.
paddingInline"none" | "sm" | "md" | "lg"

Configures paddingInline for this component.
maxWidth"sm" | "md" | "lg" | "xl" | "full"

Configures maxWidth for this component.
centerboolean

Configures center for this component.
fullWidthboolean

Configures fullWidth for this component.
radius"none" | "sm" | "md" | "lg"

Configures radius for this component.
shadowboolean

Configures shadow for this component.

Complete TypeScript API

Import from @tavojs/ui/box. Published exports: Box, BoxProps.

BoxProps

PropertyTypeRequiredDescription
childrenChild

No

Inherited children attribute accepted by Box.

classNamestring

No

Optional class hook applied to the public root element owned by the component.

sxSx

No

Inherited sx attribute accepted by Box.

idstring

No

Inherited id attribute accepted by Box.

rolestring

No

Inherited role attribute accepted by Box.

styleRecord<string, unknown>

No

Inherited style attribute accepted by Box.

titlestring

No

Inherited title attribute accepted by Box.

tabIndexnumber

No

Inherited tabIndex attribute accepted by Box.

hiddenboolean

No

Inherited hidden attribute accepted by Box.

disabledboolean

No

Inherited disabled attribute accepted by Box.

onClickTavoEventHandler<MouseEvent>

No

Inherited onClick attribute accepted by Box.

onChangeTavoEventHandler<Event>

No

Inherited onChange attribute accepted by Box.

onInputTavoEventHandler<Event>

No

Inherited onInput attribute accepted by Box.

onKeyDownTavoEventHandler<KeyboardEvent>

No

Inherited onKeyDown attribute accepted by Box.

onFocusTavoEventHandler<FocusEvent>

No

Inherited onFocus attribute accepted by Box.

onBlurTavoEventHandler<FocusEvent>

No

Inherited onBlur attribute accepted by Box.

asPolymorphicAs

No

Changes the rendered root element or component while preserving Tavo.js UI styling and public props.

surface"none" | "default" | "raised" | "subtle" | "neutral" | "primary" | "secondary"

No

Configures surface for this component.

paddingResponsiveValue<"none" | Spacing>

No

Configures padding for this component.

paddingInlineResponsiveValue<"none" | Spacing>

No

Configures paddingInline for this component.

maxWidthResponsiveValue<"sm" | "md" | "lg" | "xl" | "full">

No

Configures maxWidth for this component.

centerboolean

No

Configures center for this component.

fullWidthboolean

No

Configures fullWidth for this component.

radiusResponsiveValue<"sm" | "md" | "lg" | "none" | "surface">

No

Configures radius for this component.

borderboolean | "strong"

No

Inherited border attribute accepted by Box.

shadowboolean

No

Configures shadow for this component.

minHeightstring

No

Inherited minHeight attribute accepted by Box.

State ownership and DOM target

ConcernContract
StateNo component state contract is exposed; the application owns the rendered content and surrounding behavior.
DOM targetThe public root follows the as/component prop. Root attributes, className, style, and supported events are forwarded there.

Anatomy and related components

This component exposes one public component root rather than a compound member API.

Limitations

Avoid Box when for interactive form state; combine with form, feedback, or data components instead.

Use only the documented props, entry points, and compound members. Internal DOM nesting and CSS class names can change without becoming part of the public component contract.

Accessibility

Layout primitives are semantic-neutral unless a component prop selects an element role.

  • Choose semantic elements such as main, nav, aside, or section when the region has document meaning.

  • Keep heading order and landmark labels app-owned.

Component status

ContractCurrent value
Maturitystable
Categorylayout
Component import@tavojs/ui/box
Explicit CSS import@tavojs/ui/css/box
PreviewInteractive preview available on this page