# Container

Constrains content width and provides responsive inline gutters.

`Container` establishes the horizontal reading boundary for a page or section. It fills the available width, centers itself, stops growing at a selected maximum width, and adds inline gutters so content does not touch the viewport edge.

It does not add vertical spacing, arrange children, or create a visual surface. Compose it with `Section` for page rhythm, `Stack` or `Grid` for child layout, and `Box` for elevation or decoration.

```tsx
import { Badge, Button, Container, Cluster, Section, Stack, Text } from "@zentara-co/zenos-ui";

function ContainerExample() {
  return (
    <Section
      as="section"
      paddingY={{ base: "6", md: "8" }}
      className="w-full rounded-2xl bg-elevation-surface-sunken"
    >
      <Container size="lg" paddingX={{ base: "4", md: "6", lg: "8" }}>
        <Stack gap="4">
          <Stack gap="2" className="max-w-2xl">
            <Badge variant="default" color="information" className="self-start">
              Quarterly review
            </Badge>
            <Text type="heading" size="h4">
              Workspace activity
            </Text>
            <Text color="subtle">
              The section background spans the available width while Container keeps the content
              centered, readable, and clear of the viewport edge.
            </Text>
          </Stack>
          <Cluster gap="2">
            <Button>View report</Button>
            <Button variant="primary">Export data</Button>
          </Cluster>
        </Stack>
      </Container>
    </Section>
  );
}
```

In this pattern, `Section` owns the full-width background and block padding. `Container` owns only the centered content measure and responsive inline gutters.

## Import

```tsx
import { Container } from "@zentara-co/zenos-ui";
```

## Default behavior

Without props, Container renders a `div` with four behaviors:

- `width: 100%` lets it contract with its parent.
- `max-width: 64rem` applies the default `lg` preset.
- automatic inline margins center it when extra space is available.
- `1rem` inline padding, represented by `paddingX="4"`, provides the default gutter.

```tsx
<Container>
  <PageContent />
</Container>
```

The maximum width includes the inline padding. On a narrow viewport, the container fills the available width and the padding becomes the visible gutter. On a wide viewport, the maximum width limits the complete content region.

## Sizes

The five semantic sizes change the maximum width while retaining full available width and automatic centering. The default is `lg`.

```tsx
import { Container, Stack, Text } from "@zentara-co/zenos-ui";

function ContainerSizesExample() {
  const sizes = [
    { value: "sm", ceiling: "36rem", use: "Focused reading" },
    { value: "md", ceiling: "48rem", use: "Forms and articles" },
    { value: "lg", ceiling: "64rem", use: "Standard application pages" },
    { value: "xl", ceiling: "80rem", use: "Dashboards and dense grids" },
    { value: "full", ceiling: "100%", use: "No maximum width" },
  ] as const;

  return (
    <Stack gap="4" className="w-full">
      {sizes.map(({ value, ceiling, use }) => (
        <Stack key={value} gap="2">
          <div className="flex items-baseline justify-between gap-3">
            <Text size="s" weight="bold">
              {value}
            </Text>
            <Text size="s" color="subtle">
              {ceiling} · {use}
            </Text>
          </div>
          <div className="w-full rounded-lg bg-elevation-surface-sunken py-2">
            <Container size={value} paddingX="0">
              <div className="h-6 rounded-md bg-background-brand-bold-default" />
            </Container>
          </div>
        </Stack>
      ))}
    </Stack>
  );
}
```

| Size   | Maximum width | Good starting point for                 |
| ------ | ------------- | --------------------------------------- |
| `sm`   | `36rem`       | Focused reading and narrow flows        |
| `md`   | `48rem`       | Forms, articles, and settings pages     |
| `lg`   | `64rem`       | Standard application pages              |
| `xl`   | `80rem`       | Dashboards, data views, and wide grids  |
| `full` | `100%`        | Surfaces that should not be constrained |

Choose a size from the content, not the viewport name. A settings form may remain `sm` on a large monitor, while a dense data table may need `xl`.

`size` is a semantic preset rather than a responsive prop. The container already responds naturally: it stays fluid below its ceiling and becomes fixed only when enough width is available.

## Responsive gutters

`paddingX` accepts a spacing token or a mobile-first responsive object. Use smaller gutters where space is scarce and increase them only when the wider composition benefits from more breathing room.

```tsx
<Container size="xl" paddingX={{ base: "4", md: "6", xl: "8" }}>
  <Dashboard />
</Container>
```

Omitted breakpoints inherit the last applicable value. In this example, `4` applies by default, `6` begins at `md`, and `8` begins at `xl`.

Set `paddingX="0"` when another boundary already owns the gutter. This is useful when Container sits inside a padded panel, but it should be intentional—removing the only viewport gutter can make content touch the screen edge.

## Container and Section

The order determines which boundary spans the available width.

Place Container inside Section when backgrounds, borders, or dividers should extend beyond the constrained content:

```tsx
<Section as="section" paddingY={{ base: "8", lg: "12" }} className="bg-elevation-surface-sunken">
  <Container size="lg">
    <Stack gap="6">...</Stack>
  </Container>
</Section>
```

Place Section inside Container when the semantic region and its visual treatment should both remain constrained:

```tsx
<Container size="lg">
  <Section as="section" padding="6" className="rounded-xl border border-border-default">
    ...
  </Section>
</Container>
```

See the [Composition Guide](/layout/composition/) for the complete outside-in layout model.

## Explicit constraints

Use `width` and `maxWidth` when a product surface needs a tokenized constraint outside the semantic presets.

```tsx
import { Container, Divider, Stack, Text } from "@zentara-co/zenos-ui";

function ContainerOverrideExample() {
  return (
    <Container
      as="article"
      size="full"
      width="full"
      maxWidth="3xl"
      paddingX={{ base: "4", md: "6" }}
      aria-labelledby="container-override-title"
      className="py-4"
    >
      <Stack gap="3">
        <Text id="container-override-title" type="heading" size="h5">
          A 48rem editorial measure
        </Text>
        <Text color="subtle">
          Use an explicit maximum when a product surface needs a content width that does not match
          one of the five semantic presets. The responsive inline padding remains independent.
        </Text>
        <Divider />
        <Text size="s" color="subtle">
          size=&quot;full&quot; · width=&quot;full&quot; · maxWidth=&quot;3xl&quot;
        </Text>
      </Stack>
    </Container>
  );
}
```

The three width props have different jobs:

- `size` selects one of the five Container-specific maximum widths.
- `width` sets the element's preferred width from the shared size-token scale.
- `maxWidth` replaces the preset ceiling with a value from the shared size-token scale.

`width` and `maxWidth` are direct token values, not responsive objects. Prefer a semantic `size` for standard page structure. Reach for explicit constraints when a real product requirement falls between presets or reuses a shared width token.

```tsx
<Container size="full" width="full" maxWidth="3xl" paddingX={{ base: "4", md: "6" }}>
  <Article />
</Container>
```

Here `size="full"` removes the semantic ceiling, `width="full"` keeps the region fluid, and `maxWidth="3xl"` establishes a `48rem` maximum.

## Child layout

Container does not set display, direction, gap, or alignment for its children. Put a layout primitive inside it:

```tsx
<Container size="xl">
  <Grid columns={{ base: 1, md: 2, xl: 3 }} gap="6">
    {projects.map((project) => (
      <ProjectCard key={project.id} project={project} />
    ))}
  </Grid>
</Container>
```

Avoid nested Containers by default. They can create duplicate gutters and competing maximum widths. If an inner reading column must be narrower than a wide page container, either give the inner content an intentional `maxWidth` or set the inner Container's `paddingX` to `0` so only one boundary owns the gutter.

## When not to use Container

- Do not use it as a card. Use `Box` or `Card` for a bordered or elevated surface.
- Do not use it only to center one child on an axis. Use `Center`.
- Do not use it to arrange siblings. Use `Stack`, `Cluster`, or `Grid`.
- Do not wrap every component in its own Container. One page or section boundary should usually own the shared measure.

## Sizes

sm, md, lg, xl, full

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| as | ElementType | div | Rendered semantic element. |
| size | ContainerSize | lg | Preset content max-width. |
| width / maxWidth | SizeToken | — | Explicit structural constraints. |
| paddingX | Responsive<Spacing> | 4 | Responsive inline padding. |
| native props | React.HTMLAttributes<HTMLElement> | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Container is a `div` by default and adds no landmark or accessible name. Use `as="main"` only when it is the document's single main region. Choose `article`, `section`, `nav`, or another semantic element only when the contained content has that meaning.

Do not introduce a semantic wrapper solely because Container is present. It can remain a `div` inside an already meaningful `main` or `section`. At narrow widths and high zoom, verify that inline gutters do not leave too little room for controls, tables, or long translated text.

Source: https://zenos-ui.pages.dev/layout/container/