Components / Structure
Container
The page column. It centres its content, caps how wide it gets and adds side gutters, so every page of an app lines up. It is layout only: no background, border or text styles.
When to useLink to "When to use"
- The content of a page or screen: wrap it once, usually inside AppShell's main area, so headings and content share the same edges on every page.
- A reading column:
size="sm"orsize="md"keeps lines of text short on wide screens.
Use something else when:
- you only need padding around a group of items:
paddingon Stack, Inline or Grid - you want a visible box with a surface and border: Card
- you are laying out items in columns: Grid, inside the Container
UsageLink to "Usage"
import { Container, Stack } from "@arshad-shah/cynosure";
<Container as="main" paddingBlock="8">
<Stack gap="6">
<PageHeader title="Tasks" />
<TaskList />
</Stack>
</Container>
<Container size="sm">…</Container>
<Container size="full" padding="8">…</Container>SizesLink to "Sizes"
size sets the widest the column gets, gutters included: sm 640px, md 768px, lg 1024px (the default) and xl 1280px. full has no cap and keeps the gutters. Below its cap the column is exactly as wide as its parent, so it never overflows a narrow one.
GuttersLink to "Gutters"
padding is the space token for the two side gutters (the default is space 6, 16px). paddingBlock adds padding above and below. padding="0" removes the gutters.
Not centredLink to "Not centred"
center={false} keeps the column at the inline start: the left edge, or the right edge in right-to-left text.
PropsLink to "Props"
| Prop | What it does | Type | Default |
|---|---|---|---|
size | Widest the column gets, gutters included; full has no limit. Default "lg". | "sm" | "md" | "lg" | "full" | "xl" | "lg" |
padding | Space token for the gutters at the inline start and end. They never get narrower than the device's safe area (a phone's notch or rounded corners). Default: the --cy-container-padding token (space 6). | Space | |
paddingBlock | Space token of padding at the block start and end (top and bottom). Default: none. | Space | none |
center | Centre the column in the space around it. false keeps it at the inline start. Default true. | boolean | true |
as | Element to render: main for the page's main content, once per page. Default "div". | "div" | "section" | "article" | "main" | "div" |
className | Added to the root element, for layout. | string | |
style | Layout only. Change the widths through the --cy-container-* tokens. | CSSProperties | |
children | The page content. | ReactNode | |
data-testid | Set on the root element, for tests. | string | |
hideBelow | Hidden while the window is narrower than this breakpoint (md: below 45rem). | "sm" | "md" | "lg" | "xl" | |
hideAbove | Hidden from this breakpoint upwards (md: 45rem and wider). | "sm" | "md" | "lg" | "xl" |
Generated from the type definitions in @arshad-shah/cynosure 0.5.0.
Behaviour and accessibilityLink to "Behaviour and accessibility"
| Setting | Element and what assistive technology gets |
|---|---|
as="div" (default) | A div: no role |
as="main" | The page's main landmark. Use it once per page |
as="section" | A section: a region landmark only when you give it a name (aria-label or aria-labelledby) |
as="article" | An article |
- Width: fills its parent up to the cap, also inside a flex row or a Stack that centres its children.
- Safe area: each gutter is at least the device's safe-area inset on that side, so content clears a phone's notch or rounded corners in landscape. Browsers only report insets when the page's viewport meta tag has
viewport-fit=cover. - Right to left: the gutters are equal on both sides and the column stays centred.
- Nesting: a nested Container has its own default gutters and inherits no padding from its parent.
- Text: font, size and colour are inherited from the page.
- Keyboard: none. A Container is never focusable.
TouchLink to "Touch"
Nothing in a Container can be pressed, so it has no hit area. On phones the gutters keep content off the screen edges and the safe-area insets.
ThemingLink to "Theming"
| Token | Default | What it sets |
|---|---|---|
--cy-container-size-sm | 640px | Widest a size="sm" container gets |
--cy-container-size-md | 768px | Widest a size="md" container gets |
--cy-container-size-lg | 1024px | Widest a size="lg" container gets |
--cy-container-size-xl | 1280px | Widest a size="xl" container gets |
--cy-container-padding | --cy-space-6 | Side gutters when padding is not set |
createTheme({ components: { container: { sizeLg: "1100px", padding: "24px" } } });className and style are for layout only (margin, placement, a minimum height).
RelatedLink to "Related"
These examples run Cynosure 0.5.0 (commit 50ce30b), the version on npm.