Container component provides a centered, responsive wrapper with consistent padding and maximum width constraints based on standard Tailwind breakpoints.
Props
The maximum width of the container. Maps to Tailwind’s screen size breakpoints:
sm- max-w-screen-sm (640px)md- max-w-screen-md (768px)lg- max-w-screen-lg (1024px)xl- max-w-screen-xl (1280px)2xl- max-w-screen-2xl (1536px)
Usage
Basic Container
Small Container for Focused Content
Extra Large Container
Nested Content
Features
- Centered Layout: Automatically centers content horizontally with
mx-auto - Consistent Padding: Applies
px-5horizontal padding on all screen sizes - Full Height: Uses
h-fullto occupy available vertical space - Responsive Width: Maximum width adapts to the specified size breakpoint
- Flexible Content: Accepts any child content through the default slot
Styling
The Container component uses Tailwind’s utility functioncn() to merge classes conditionally. The base classes applied are:
w-full- Full width within parenth-full- Full height within parentmx-auto- Horizontal centeringpx-5- Horizontal padding (1.25rem)max-w-screen-{size}- Maximum width based on size prop
When to Use
Use the Container component when you need to:- Create a centered layout with consistent maximum width
- Ensure content doesn’t stretch too wide on large screens
- Maintain consistent horizontal padding across your pages
- Implement responsive layouts that adapt to different screen sizes
Component Source
Location:src/components/Container.astro