Skip to main content
Brand and assets
Build
Monitor and contribute
/
Component library
  • All components
  • Buttons & actions
  • Forms & inputs
  • Layout & containers
    • Anchors
    • Box
    • Col
    • Container
    • ContainerNext
    • FullPageLayout
    • Grid
    • HStack
    • Header
    • Header
    • LayoutGrid
    • Navigation
    • Pagination
    • Row
    • Section
    • Spacer
    • TabList
    • TabList
    • Tabs
    • VStack
  • Overlays
  • Feedback & status
  • Data display
  • Typography
  • Accessibility
  • Contrib
  • Deprecated
  • Layout & containers
  • Box

Box

The primitive every other component is built on. Renders a `div` on web and a `View` on mobile. Use when nothing more specific fits.

Health
Component health
Source
View on Github
Storybook
View in Storybook
Playground
No Example
Accessibility

compliant

Platform
Universal
  • Overview
  • Props

Box is the most abstract component on top of which other components are built. By default, it renders a div element on the web (with some default styles, see Web behavior drift section) and a View on mobile.

Box

Styling​

It is a good building block for styling.

Box

Shadows​

Predefined shadows can be set through the shadowPreset sx prop.

xs

sm

md

lg

It's also possible to invert the direction of the shadow by suffixing the preset with -inverted.

Polymorphic​

You can use the asChild prop. Instead of rendering its own element, it will pass all props to that child, merging together any event handling props.

Hello

Web Behavior Drift​

It renders a div but not an unstyled raw div. It has some standard react-native-web flex styles to get the same behavior on the web and mobile. Its default styles are:

display: 'flex'
alignItems: 'stretch'
flexDirection: 'column'
flexBasis: 'auto'
boxSizing: 'border-box'
position: 'relative'
minHeight: 0
minWidth: 0
flexShrink: 0

In some web-only cases, especially when you don't know the composition of the children in your components, you may want to restore the default div behavior.

<Box sx={{ display: "block", flexShrink: 1, flexGrow: 1 }}>{/* ... */}</Box>

Playground​

Loading...
tip
This component is universal, its usage is the same in murray and murray/mobile.

Box props

NameTypeDefault ValueDescriptionUsage count
cssInterpolation<Theme>
onKeyDown(e: KeyboardEvent) => void
sx
2 possibilitiesStackStyle & { shadowPreset?: ShadowPresetShadowPresetInverted }

Undocumented props

NameTypeDefault ValueDescriptionUsage count
$platform-webany
accessibilityRoleany
accessibilityStateany
accessibleany
aria-checkedany
aria-disabledany
aria-hiddenany
aria-labelany
aria-labelledbyany
aria-liveany
aria-orientationany
aria-pressedany
aria-selectedany
aria-valuemaxany
aria-valueminany
aria-valuenowany
asChildany
classNameany
collapsableany
data-animation-stateany
data-brand-iconany
data-caretany
data-phone-frameany
data-pillany
data-productany
data-revealany
data-shift-slot-keyany
data-tabany
data-tool-details-triggerany
disabledany
idany
importantForAccessibilityany
inertany
onBlurany
onClickany
onFocusany
onHoverInany
onHoverOutany
onLayoutany
onMouseDownany
onMouseEnterany
onMouseLeaveany
onPointerLeaveany
onPressany
onPressInany
onPressOutany
onTouchStartany
refany
roleany
styleany
tabIndexany
tagany
testIDany

Style API​

Use sx for one-off adjustments. It accepts these style keys:

alignContentalignItemsalignSelfanimateOnlyanimatePresenceanimationaspectRatiobackdropFilterbackfaceVisibilitybackgroundbackgroundAttachmentbackgroundBlendModebackgroundClipbackgroundColorbackgroundImagebackgroundOriginbackgroundPositionbackgroundRepeatbackgroundSizeblockSizeborderBlockColorborderBlockEndColorborderBlockEndStyleborderBlockEndWidthborderBlockStartColorborderBlockStartStyleborderBlockStartWidthborderBlockStyleborderBlockWidthborderBottomColorborderBottomEndRadiusborderBottomStartRadiusborderBottomWidthborderColorborderCurveborderEndColorborderEndEndRadiusborderEndStartRadiusborderEndWidthborderImageborderInlineColorborderInlineEndColorborderInlineEndStyleborderInlineEndWidthborderInlineStartColorborderInlineStartStyleborderInlineStartWidthborderInlineStyleborderInlineWidthborderRadiusborderStartColorborderStartEndRadiusborderStartStartRadiusborderStartWidthborderStyleborderTopColorborderTopEndRadiusborderTopStartRadiusborderTopWidthborderWidthbottomboxShadowboxSizingcaretColorclipPathcolumnGapcontaincontainerTypecontentcursordirectiondisabledStyledisplayendenterStyleexitStyleexperimental_backgroundImageexperimental_backgroundPositionexperimental_backgroundRepeatexperimental_backgroundSizefilterflexflexBasisflexDirectionflexGrowflexShrinkflexWrapfloatfocusStylefocusVisibleStylefocusWithinStylegapgridColumngridColumnEndgridColumnGapgridColumnStartgridRowgridRowEndgridRowGapgridRowStartgridTemplateAreasgridTemplateColumnsheighthoverStyleinlineSizeinsetinsetBlockinsetBlockEndinsetBlockStartinsetInlineinsetInlineEndinsetInlineStartisolationjustifyContentmarginmarginBlockmarginBlockEndmarginBlockStartmarginBottommarginEndmarginHorizontalmarginInlinemarginInlineEndmarginInlineStartmarginStartmarginTopmarginVerticalmaskmaskBordermaskBorderModemaskBorderOutsetmaskBorderRepeatmaskBorderSlicemaskBorderSourcemaskBorderWidthmaskClipmaskCompositemaskImagemaskModemaskOriginmaskPositionmaskRepeatmaskSizemaskTypematrixmaxBlockSizemaxHeightmaxInlineSizemaxWidthminBlockSizeminHeightminInlineSizeminWidthmixBlendModeobjectFitopacityoutlineColoroutlineOffsetoutlineStyleoutlineWidthoverflowoverflowBlockoverflowInlinepaddingpaddingBlockpaddingBlockEndpaddingBlockStartpaddingBottompaddingEndpaddingHorizontalpaddingInlinepaddingInlineEndpaddingInlineStartpaddingStartpaddingToppaddingVerticalpassThroughperspectivepointerEventspositionpressStylerotaterotateXrotateYrotateZrotationrowGapscalescaleXscaleYscrollbarWidthseparatorshadowColorshadowOffsetshadowOpacityshadowPresetshadowRadiusskewXskewYspacespaceDirectionstarttextEmphasistextWraptoptouchActiontransformtransformMatrixtransformOrigintransformStyletransitiontranslateXtranslateYuserSelectverticalAlignwidthxyzIndex

Each can be overridden per breakpoint with:

$group-focus$group-focusVisible$group-focusWithin$group-hover$group-lg$group-lg-focus$group-lg-focusVisible$group-lg-focusWithin$group-lg-hover$group-lg-press$group-ltLg$group-ltLg-focus$group-ltLg-focusVisible$group-ltLg-focusWithin$group-ltLg-hover$group-ltLg-press$group-ltMd$group-ltMd-focus$group-ltMd-focusVisible$group-ltMd-focusWithin$group-ltMd-hover$group-ltMd-press$group-ltSm$group-ltSm-focus$group-ltSm-focusVisible$group-ltSm-focusWithin$group-ltSm-hover$group-ltSm-press$group-ltVs$group-ltVs-focus$group-ltVs-focusVisible$group-ltVs-focusWithin$group-ltVs-hover$group-ltVs-press$group-ltXl$group-ltXl-focus$group-ltXl-focusVisible$group-ltXl-focusWithin$group-ltXl-hover$group-ltXl-press$group-ltXxl$group-ltXxl-focus$group-ltXxl-focusVisible$group-ltXxl-focusWithin$group-ltXxl-hover$group-ltXxl-press$group-md$group-md-focus$group-md-focusVisible$group-md-focusWithin$group-md-hover$group-md-press$group-press$group-sm$group-sm-focus$group-sm-focusVisible$group-sm-focusWithin$group-sm-hover$group-sm-press$group-vs$group-vs-focus$group-vs-focusVisible$group-vs-focusWithin$group-vs-hover$group-vs-press$group-xl$group-xl-focus$group-xl-focusVisible$group-xl-focusWithin$group-xl-hover$group-xl-press$group-xs$group-xs-focus$group-xs-focusVisible$group-xs-focusWithin$group-xs-hover$group-xs-press$group-xxl$group-xxl-focus$group-xxl-focusVisible$group-xxl-focusWithin$group-xxl-hover$group-xxl-press$lg$ltLg$ltMd$ltSm$ltVs$ltXl$ltXxl$md$platform-android$platform-ios$platform-native$platform-web$sm$vs$xl$xs$xxl
Edit this page
Previous
Anchors
Next
Col
  • Styling
    • Shadows
  • Polymorphic
  • Web Behavior Drift
  • Playground