# Container

A padded and centred content column.

```tsx
import { Container } from "@/components/ui/container"
import { Heading } from "@/components/ui/heading"
import { Text } from "@/components/ui/text"
import { VStack } from "@/components/ui/stack"

export default function ContainerDemo() {
  return (
    <Container size="md">
      <VStack gap={2}>
        <Heading>Welcome to arene</Heading>
        <Text tone="muted">Build consistent interfaces with components you own.</Text>
      </VStack>
    </Container>
  )
}
```

## Installation

**Command**

```bash
npx shadcn@latest add @arene/container
```

Needs the [arene setup](https://www.arene.style/docs/installation) first.

**Manual**

1. Install the packages it imports:

   ```bash
   npm install @base-ui/react @stylexjs/stylex clsx
   ```

2. Set up the token layer. See [Installation](https://www.arene.style/docs/installation).
   Copy `theme/widths.ts` from the installation page.

3. Copy the component into your project.

   ```tsx title="components/ui/container.tsx"
   "use client"

   import type { CSSProperties } from "react"
   import { useRender } from "@base-ui/react/use-render"
   import * as stylex from "@stylexjs/stylex"
   import type { StyleXStyles } from "@stylexjs/stylex"
   import { clsx } from "clsx"

   import { widths } from "@/theme/widths"
   import { space } from "@/theme/tokens.stylex"

   const styles = stylex.create({
     base: { minWidth: 0, marginInline: "auto", paddingInline: space.s6 },
   })
   const containerStyles = { base: styles.base, widths }

   type ContainerProps = useRender.ComponentProps<"div"> & {
     size?: keyof typeof widths
     xstyle?: StyleXStyles
     style?: CSSProperties
   }

   function Container({
     render,
     ref,
     size = "xl3",
     xstyle,
     className,
     style,
     ...props
   }: ContainerProps) {
     const sx = stylex.props(styles.base, widths[size], xstyle)
     return useRender({
       defaultTagName: "div",
       render,
       ref,
       props: {
         "data-slot": "container",
         "data-size": size,
         ...sx,
         ...props,
         className: clsx(sx.className, className),
         style: { ...sx.style, ...style },
       },
     })
   }

   export { Container, containerStyles, type ContainerProps }
   ```

4. Change the `@/` imports if your project uses different aliases.

## Usage

```tsx
import { Container } from "@/components/ui/container"
```

```tsx
<Container size="md">Page content</Container>
```

`size` caps the full-width column in rem using the shared width scale:
`narrow` (12rem), `xs` (20rem), `sm` (24rem), `md` (28rem), `lg` (32rem) and `xl3` (48rem). Inline padding is `space.s6`.
Override padding through `xstyle`. `containerStyles` exports `base` and
`widths`.

## Size

Choose a width from the shared scale. Padding stays inside the width cap.

```tsx
import * as stylex from "@stylexjs/stylex"
import { Container } from "@/components/ui/container"
import { VStack } from "@/components/ui/stack"
import { color, leading, radius, space, text } from "@/theme/tokens.stylex"

const styles = stylex.create({
  column: { backgroundColor: color.muted, borderRadius: radius.md, paddingBlock: space.s2 },
  content: {
    backgroundColor: color.background,
    borderRadius: radius.sm,
    paddingInline: space.s3,
    paddingBlock: space.s1_5,
    fontSize: text.sm,
    lineHeight: leading.sm,
  },
})

export default function ContainerSize() {
  return (
    <VStack gap={3} width="100%">
      <Container size="narrow" xstyle={styles.column}>
        <div {...stylex.props(styles.content)}>narrow, 12rem</div>
      </Container>
      <Container size="xs" xstyle={styles.column}>
        <div {...stylex.props(styles.content)}>xs, 20rem</div>
      </Container>
      <Container size="sm" xstyle={styles.column}>
        <div {...stylex.props(styles.content)}>sm, 24rem</div>
      </Container>
      <Container size="md" xstyle={styles.column}>
        <div {...stylex.props(styles.content)}>md, 28rem</div>
      </Container>
      <Container size="lg" xstyle={styles.column}>
        <div {...stylex.props(styles.content)}>lg, 32rem</div>
      </Container>
      <Container size="xl3" xstyle={styles.column}>
        <div {...stylex.props(styles.content)}>xl3, 48rem</div>
      </Container>
    </VStack>
  )
}
```

## Composition

Pass `render` to choose a semantic element. Put its props on that element.

```tsx
import { Container } from "@/components/ui/container"

export default function ContainerRender() {
  return (
    <Container render={<section aria-label="Release summary" />} size="md">
      Your release summary
    </Container>
  )
}
```

## API reference

See Base UI's [useRender reference](https://base-ui.com/react/utils/use-render)
for composition props. Native element props are forwarded.

| Prop        | Type                   | Default        |
| ----------- | ---------------------- | -------------- |
| `size`      | `keyof typeof widths`  | `"xl3"`        |
| `render`    | `useRender.RenderProp` | Native element |
| `xstyle`    | `StyleXStyles`         | None           |
| `className` | `string`               | None           |
| `style`     | `CSSProperties`        | None           |

### Data attributes

| Attribute               | On   | Effect                   |
| ----------------------- | ---- | ------------------------ |
| `data-slot="container"` | root | Identifies the component |
| `data-size`             | root | Mirrors `size`           |
