Skip to main content

Container

Container provides a max-width centered content wrapper with preset sizes. Use it to constrain page content to readable widths.

Open in Storybook

Import

import { Container } from "@tosui/react";

Basic Usage

Sizes

sm: 640px max-width
md: 768px max-width
lg: 1024px max-width (default)
xl: 1280px max-width
2xl: 1536px max-width
full: 100% width

Center Content

Use centerContent to center children both horizontally and vertically.

Centered content

Custom Padding

The default horizontal padding is 16px (px=4). Override it as needed.

Container with 32px horizontal padding

Common Patterns

Page Layout

<Container as="main" size="lg" py={8}>
<Heading>Page Title</Heading>
<Text>Page content goes here...</Text>
</Container>

Narrow Content

<Container size="sm">
<Card>
<CardBody>
<VStack gap={4}>
<Heading>Sign In</Heading>
<Input placeholder="Email" />
<Input type="password" placeholder="Password" />
<Button w="100%">Sign In</Button>
</VStack>
</CardBody>
</Card>
</Container>

Props Reference

PropTypeDefaultDescription
size"sm" | "md" | "lg" | "xl" | "2xl" | "full""lg"Max-width preset
centerContentbooleanfalseCenter children with flexbox
px0-324Horizontal padding
asElementType"div"HTML element to render

Size Values

SizeMax Width
sm640px
md768px
lg1024px
xl1280px
2xl1536px
full100%

TypeScript

import { Container, type ContainerSize, type ContainerProps, type ContainerOwnProps } from "@tosui/react";