# Container

> Manages the main content area by centering it and applying a max-width. It ensures a consistent and readable layout across different screen sizes.

Source: https://vaneui.com/docs/layout-components/container

Import: `import { Container, Col, PageTitle, Section, Text, Title } from "@vaneui/ui"`

Container sets the width of a page's content column: it renders a `<div>` that fills its parent's width until it reaches the max-width set by its size. The full-width background behind it and the vertical spacing around it belong to a [Section](/docs/layout-components/section) wrapped around the Container. For a bordered box around a single piece of content, use [Card](/docs/layout-components/card).

## Basic usage

A centered, full-width wrapper that caps content at a readable max-width. `md`, `wFull`, `flex`, `column`, `itemsCenter`, `gap`, `noPadding`, `outline`, and `sharp` are defaults.

```tsx demo
<Container border>
  <Title>Page Content</Title>
  <Text>Container centers content and constrains width for optimal readability.</Text>
</Container>
```

## Sizes

Sizes (`xs`, `sm`, `md` default, `lg`, `xl`) control the max-width: `max-w-3xl` through `max-w-7xl`. Resize the viewport to see narrower containers stop growing before wider ones do.

```tsx demo
<Col>
  <Container xs border>
    <Text fontSemibold>xs: max-w-3xl</Text>
  </Container>
  <Container sm border>
    <Text fontSemibold>sm: max-w-4xl</Text>
  </Container>
  <Container border>
    <Text fontSemibold>md (default): max-w-5xl</Text>
  </Container>
  <Container lg border>
    <Text fontSemibold>lg: max-w-6xl</Text>
  </Container>
  <Container xl border>
    <Text fontSemibold>xl: max-w-7xl</Text>
  </Container>
</Col>
```

## Padding

Container defaults to `noPadding`: the parent Section usually owns vertical rhythm. Pass `padding` to opt in to size-driven internal padding.

```tsx demo
<Col>
  <Container border>
    <Text fontSemibold>noPadding (default)</Text>
    <Text>Edges sit flush with the container box.</Text>
  </Container>
  <Container padding border>
    <Text fontSemibold>padding</Text>
    <Text>Internal padding scales with the size prop.</Text>
  </Container>
</Col>
```

## Appearances

Containers support color appearances: `primary`, `secondary`, `success`, `danger`, etc.

```tsx demo
<Col>
  <Container primary border>
    <Text fontSemibold>Primary Container</Text>
    <Text>Highlighted content area</Text>
  </Container>
  <Container success border>
    <Text fontSemibold>Success Container</Text>
    <Text>Positive feedback area</Text>
  </Container>
</Col>
```

## Variants

Use `filled` for solid backgrounds. `outline` is the default. Add `shadow` for elevation.

```tsx demo
<Col>
  <Container filled primary padding>
    <Title filled primary>Filled Container</Title>
    <Text filled primary>Solid background with primary color</Text>
  </Container>
  <Container secondary border padding>
    <Title secondary>Outline Container (default)</Title>
    <Text secondary>Border only styling</Text>
  </Container>
  <Container shadow padding>
    <Title>Shadow Container</Title>
    <Text>Elevated with drop shadow</Text>
  </Container>
</Col>
```

## Shapes

Containers support different border radius styles. `sharp` is the default (no radius).

```tsx demo
<Col>
  <Container border>
    <Text fontSemibold>Sharp (default)</Text>
  </Container>
  <Container rounded border>
    <Text fontSemibold>Rounded corners</Text>
  </Container>
  <Container pill border padding>
    <Text fontSemibold>Pill shape</Text>
  </Container>
</Col>
```

## Responsive breakpoints

Container is a flex column by default. Use `row` to flow horizontally on desktop and `mobileStack` / `tabletStack` to stack on smaller screens.

```tsx demo
<Container row tabletStack border padding>
  <Col>
    <Title>Left Content</Title>
    <Text>Switches to stacked layout on tablets and below.</Text>
  </Col>
  <Col>
    <Title>Right Content</Title>
    <Text>Resize your browser to see the responsive behavior.</Text>
  </Col>
</Container>
```

## Page layout pattern

The canonical page layout: a Section owns vertical padding and full-width background, the Container nested inside caps reading width and centers the content.

```tsx demo
<Section secondary>
  <Container>
    <PageTitle>Getting Started</PageTitle>
    <Text>The Section handles the full-bleed background and outer padding. The Container constrains the inner content to a comfortable reading width.</Text>
  </Container>
</Section>
```

## Frequently asked questions

### Why are the children of my Container narrower than it is?

Container centers its children on the cross axis (`itemsCenter` is a default), so each child shrinks to its content width and sits in the middle. Add `itemsStretch` to the Container to make every child full width, or `wFull` to one child. Text alignment is separate: the lines inside a centered `Text` still start at the left unless it has `textCenter`.

### Why does my content touch the screen edges on a phone?

Container has no padding by default: it only caps the width. The [Section](/docs/layout-components/section) around it supplies the padding and scales it down on tablet and mobile, as in the [page layout pattern](#page-layout-pattern). Without a Section, add `padding` to the Container, which also shrinks on smaller screens because `responsiveSizing` is on by default.

### How do I set a max-width between two sizes?

Pass your own max-width class, such as `className="max-w-[68rem]"`: it replaces the `max-w-*` class of the size, because a class you pass wins over the theme's. The prebuilt `@vaneui/ui/css` has no arbitrary utilities, so with it use `style={{ maxWidth: '68rem' }}` instead. The size prop still sets the gap between the children.

## Props

| Prop | Category | Default | Description |
| --- | --- | --- | --- |
| `primary` | Appearance |  | Primary color appearance (gray) |
| `accent` | Appearance |  | Accent color appearance (rose) |
| `secondary` | Appearance |  | Secondary color appearance (gray) |
| `tertiary` | Appearance |  | Tertiary color appearance |
| `success` | Appearance |  | Success color appearance (green) |
| `danger` | Appearance |  | Danger color appearance (red) |
| `warning` | Appearance |  | Warning color appearance (amber) |
| `info` | Appearance |  | Info color appearance (cyan) |
| `inheritAppearance` | Appearance |  | Inherit appearance from parent — suppresses own data-appearance/data-variant, uses parent's CSS variables |
| `desktopStack` | Breakpoint |  | Stack into a column at desktop width and below (max-desktop: 80rem) |
| `tabletStack` | Breakpoint |  | Stack into a column at tablet width and below (max-tablet: 64rem) |
| `mobileStack` | Breakpoint |  | Stack into a column at mobile width and below (max-mobile: 48rem) |
| `flex1` | Flex |  | Take up remaining space (= `flex-1`, i.e. `flex: 1 1 0%`) |
| `flexAuto` | Flex |  | Grow but respect intrinsic size (= `flex-auto`, i.e. `flex: 1 1 auto`) |
| `flexNone` | Flex |  | Don't grow and don't shrink (= `flex-none`, i.e. `flex: none`) |
| `margin` | Margin |  | Enable margin on all sides |
| `marginX` | Margin |  | Enable only horizontal (inline) margin |
| `marginY` | Margin |  | Enable only vertical (block) margin |
| `marginT` | Margin |  | Enable only top margin |
| `marginB` | Margin |  | Enable only bottom margin |
| `noMargin` | Margin |  | Disable margin (reset to 0) |
| `padding` | Padding |  | Enable internal padding |
| `paddingX` | Padding |  | Enable only horizontal padding |
| `paddingY` | Padding |  | Enable only vertical padding |
| `noPadding` | Padding | yes | Disable internal padding |
| `pill` | Shape |  | Fully rounded corners (circular) |
| `sharp` | Shape | yes | No rounded corners (square) |
| `rounded` | Shape |  | Medium rounded corners (default) |
| `noShrink` | Shrink |  | Prevent the flex item from shrinking below its content size (= `shrink-0`) |
| `xs` | Size |  | Extra small size |
| `sm` | Size |  | Small size |
| `md` | Size | yes | Medium size (default) |
| `lg` | Size |  | Large size |
| `xl` | Size |  | Extra large size |
| `skeleton` | Skeleton |  | Show the component as a loading placeholder in its own size and shape. On a container, every component inside it becomes a placeholder too |
| `strongBorder` | Strong Border |  | Paint the border in the appearance's strong color instead of its soft one |
| `textLeft` | Text Align |  | Align text to left (physical side, does not flip under RTL) |
| `textCenter` | Text Align |  | Align text to center |
| `textRight` | Text Align |  | Align text to right (physical side, does not flip under RTL) |
| `textJustify` | Text Align |  | Justify text |
| `textStart` | Text Align |  | Align text to the reading-direction start (left in LTR, right in RTL) |
| `textEnd` | Text Align |  | Align text to the reading-direction end (right in LTR, left in RTL) |
| `filled` | Variant |  | Filled variant - solid background with contrasting text color |
| `outline` | Variant | yes | Outline variant - transparent background with border and colored text (default) |
| `ghost` | Variant |  | Ghost variant - transparent background, no border, appearance-colored text, tinted hover background |

Layout and utility props (Border, Display, Flex Direction, Gap, Height, Hide, Items, Justify, Overflow, Pointer Events, Position, Responsive Sizing, Responsive Width, Ring, Shadow, Show, Transparent, Whitespace, Width, Wrap) are listed on [Common Props](https://vaneui.com/docs/reference/common-props.md).
