Skip to Content
Neshel-UI
Layout

Box

A semantic wrapper with an optional responsive display, for show/hide and landmarks.

Purpose

Box renders one element with no styling except an optional responsive display. Use it to pick a semantic element, to apply asChild, or to show and hide content per breakpoint without media queries in your CSS.

Import

import.tsx
import { Box } from "@neshel-ui/layout";

Usage

Preview: box-display
Preview theme
Always visible
Visible from md
box-display.tsx
import { Box, Inline } from "@neshel-ui/layout";
import { Tile } from "./_tile";

/** Box adds semantics and a responsive display without extra styling. */
export default function BoxDisplay() {
  return (
    <Inline space="3" align="center">
      <Box as="section" aria-label="Always visible">
        <Tile>Always visible</Tile>
      </Box>
      {/* Hidden below md, block from md (resize the window to see it). */}
      <Box display={{ base: "none", md: "block" }}>
        <Tile>Visible from md</Tile>
      </Box>
    </Inline>
  );
}

API

BoxProps

BoxProps
PropTypeDefaultDescription
asLayoutElement——
asChildboolean——
displayResponsive<BoxDisplay>——
refRef<HTMLElement>——

Also accepts the props of: React DOM attributes.

BoxDisplay

type BoxDisplay = "none" | "block" | "inline" | "inline-block"
  • Default element: div. as accepts the layout element list.
  • display values: none, block, inline, inline-block — responsive. Without display, the element keeps its native display.

Accessibility

display="none" removes content from the accessibility tree at that width, just like CSS. Do not hide the only copy of essential content at small widths.

Common mistakes

  • Using Box for spacing: it has no space prop — use Stack or Inline.
  • Expecting display="flex": use Flex, which also manages direction and alignment.
Edit on GitHub

On this page