Layout & primitives
Box
Free2.2 KB gzippedBox: the polymorphic base building block. Renders as (default div) with token-based spacing, surfaces, tints, radius, shadow, and border.
Accessibility: WCAG 2.2 AA · No A or AA violations in light or dark mode · No keyboard interaction of its own · Full report
Import
import { Box } from "@vjdesigns/vjdesigns-ui";
Importing only Box adds about 2.2 KB of minified, gzipped JavaScript to your app (React not included). The stylesheet is shared by every component and loaded once: 75.1 KB gzipped.
Examples
Surfaces
surface, tone, radius, shadow and border style a box with tokens, so it follows the theme.
Raised
Sunken
Primary soft
Success solid
import { Box, Flex, Text } from "@vjdesigns/vjdesigns-ui";
export function Surfaces() {
return (
<Flex gap={4} wrap="wrap" justify="center">
<Box surface="raised" shadow="md" radius="lg" p={5}>
<Text weight="semibold">Raised</Text>
</Box>
<Box surface="sunken" radius="lg" p={5} border>
<Text weight="semibold">Sunken</Text>
</Box>
<Box tone="primary" radius="lg" p={5}>
<Text weight="semibold" tone="inherit">
Primary soft
</Text>
</Box>
<Box tone="success" variant="solid" radius="lg" p={5}>
<Text weight="semibold" tone="inherit">
Success solid
</Text>
</Box>
</Flex>
);
}
Spacing and element
Spacing props (p, px, m, mt…) take steps of the spacing scale. as changes the element.
px={4} py={2} mb={4}
This section has p={8}: 2rem of padding on every side.
import { Box, Text } from "@vjdesigns/vjdesigns-ui";
export function SpacingAndElement() {
return (
<Box as="section" aria-label="Spacing demo" border="strong" radius="xl" p={8} style={{ width: "100%", maxWidth: "26rem" }}>
<Box tone="accent" radius="md" px={4} py={2} mb={4}>
<Text size="sm" weight="semibold" tone="inherit">
px={"{4}"} py={"{2}"} mb={"{4}"}
</Text>
</Box>
<Text tone="muted">This section has p={"{8}"}: 2rem of padding on every side.</Text>
</Box>
);
}
Accessibility
Box is a <div> unless you say otherwise. Give it the element that matches its role with as (section, aside, nav…) so the structure comes from HTML, and name a region with the heading inside it.
Shipping address
Ana Ruiz, 12 Calle Mayor, Madrid
import { Box, Text, Heading } from "@vjdesigns/vjdesigns-ui";
export function Accessibility() {
return (
<Box as="section" aria-labelledby="box-a11y-title" surface="raised" border radius="lg" p={5} style={{ width: "100%", maxWidth: "26rem" }}>
<Heading id="box-a11y-title" level={3} size="md">
Shipping address
</Heading>
<Text tone="muted">Ana Ruiz, 12 Calle Mayor, Madrid</Text>
</Box>
);
}
Translated
Alignment values like textAlign="start" are logical, so in Arabic "start" is the right edge. Your own styles mirror too when they use logical properties such as padding-inline-start.
عنوان الشحن
شارع النيل 12، القاهرة
import { Box, Text, LocaleProvider } from "@vjdesigns/vjdesigns-ui";
import ar from "@vjdesigns/vjdesigns-ui/locales/ar";
export function Translated() {
return (
<LocaleProvider locale="ar" messages={ar}>
<Box surface="raised" border radius="lg" p={5} textAlign="start" style={{ width: "100%", maxWidth: "26rem" }}>
<Text weight="semibold">عنوان الشحن</Text>
<Text tone="muted">شارع النيل 12، القاهرة</Text>
</Box>
</LocaleProvider>
);
}
Usage notes
Box adds no semantics. When rendering an interactive element (as="a" with href, as="button"), you own its accessible name, keyboard behavior, and states; prefer the dedicated components.
API reference
Box
| Prop | Type | Default |
|---|---|---|
surfaceNeutral surface background, paired with | "bg""surface""raised""sunken" | — |
toneSemantic tint. | "neutral""primary""accent""success""warning""danger""info" | — |
variantHow | "soft""solid" | "soft" |
radiusCorner rounding ( | "none""xs""sm""md""lg""xl""2xl""pill" | — |
shadowSoft drop shadow ( | "none""xs""sm""md""lg""xl" | — |
borderBorder. | falsetrue"strong""default" | — |
displayCSS display. | "block""inline""inline-block""flex""inline-flex""grid""inline-grid""contents""none" | — |
positionCSS position. | "static""relative""absolute""fixed""sticky" | — |
overflowCSS overflow. | "visible""hidden""auto""scroll""clip" | — |
textAlignText alignment (logical: | "start""center""end""justify" | — |
pPadding on all sides ( | SpaceValue | — |
pxHorizontal padding (inline start and end). Overrides | SpaceValue | — |
pyVertical padding (block start and end). Overrides | SpaceValue | — |
ptTop padding. Overrides | SpaceValue | — |
prEnd padding (right in left-to-right, left in right-to-left). Overrides | SpaceValue | — |
pbBottom padding. Overrides | SpaceValue | — |
plStart padding (left in left-to-right, right in right-to-left). Overrides | SpaceValue | — |
mMargin on all sides ( | MarginValue | — |
mxHorizontal margin. Overrides | MarginValue | — |
myVertical margin. Overrides | MarginValue | — |
mtTop margin. Overrides | MarginValue | — |
mrEnd margin (right in left-to-right). Overrides | MarginValue | — |
mbBottom margin. Overrides | MarginValue | — |
mlStart margin (left in left-to-right). Overrides | MarginValue | — |
widthCSS width. Numbers are px. On a media element ( | SizeValue | — |
heightCSS height. Numbers are px. On a media element a number is also the HTML | SizeValue | — |
minWidthCSS min-width. Numbers are px. | SizeValue | — |
maxWidthCSS max-width. Numbers are px. | SizeValue | — |
minHeightCSS min-height. Numbers are px. | SizeValue | — |
maxHeightCSS max-height. Numbers are px. | SizeValue | — |
asElement or component to render. | ElementType | "div" |
See what changed in each version in the Changelog.
Accessibility report
Box targets WCAG 2.2 AA. Below: a live axe-core audit of this page's examples, Lighthouse scores for the page in both modes, the accessibility behavior built into the component, and the checks only a person can do.
axe-core audit (live)
Checking the examples above…
Lighthouse audit
Light mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Dark mode
Score 10035 passed · 0 failed · 30 not applicable · 10 to check by hand
Lighthouse 13.5.0 audits the whole docs page (header and sidebar included), not just the examples, in English. Last run 11/27/2026. Some failed audits carry no weight in the score, so a page can score 100 and still list one.
Built-in behavior
Keyboard
Not focusable, so there's no keyboard interaction of its own.
Roles and states
| Element | Role | States and properties |
|---|---|---|
<div>, or the element in as | Native role of that element | Use as="section" with a name for a landmark |
Manual checks
Automated tools find roughly a third of accessibility issues. Test these in your app, with your content.
| Check | What to test | WCAG 2.2 |
|---|---|---|
| Keyboard | Every action works with Tab, Shift+Tab, Enter, Space and the arrow keys, and focus never gets stuck. | 2.1.1 (A), 2.1.2 (A) |
| Focus | Focus moves in a logical order, is always visible, and isn't hidden behind sticky headers. | 2.4.3 (A), 2.4.7 (AA), 2.4.11 (AA), 2.4.13 (AAA) |
| Screen readers | Names, roles and states are announced correctly, and status changes are announced without moving focus. | 1.3.1 (A), 4.1.2 (A), 4.1.3 (AA) |
| Color | Meaning never depends on color alone; your own colors meet contrast in both modes. | 1.4.1 (A), 1.4.3 (AA), 1.4.11 (AA), 1.4.6 (AAA) |
| Zoom and reflow | At 200% text size and at 320px wide (400% zoom), nothing is cut off and no sideways scrolling is needed. | 1.4.4 (AA), 1.4.10 (AA), 1.4.12 (AA) |
| Pointer targets | Click and tap targets are at least 24×24px (44×44px for AAA), or spaced so they don't overlap. | 2.5.8 (AA), 2.5.5 (AAA) |
| Motion | Animations respect the reduced-motion setting. | 2.3.3 (AAA) |