
When to Use
Essential for:- Multi-column layouts - Side-by-side content
- Card designs - Boxed content with backgrounds
- Spacing control - Consistent gaps between elements
- Visual grouping - Related content sections
- Responsive layouts - Mobile-optimized structures
How Containers Work
Containers can hold any other elements, including other containers. This nesting creates powerful layout possibilities:Orientation
Choose how elements arrange inside:Rows (Horizontal)
Elements placed side-by-side:- Desktop: True horizontal layout
- Mobile: Often stacks vertically
- Use for: Navigation bars, feature lists
Columns (Vertical)
Elements stack top-to-bottom:- Consistent across devices
- Natural reading flow
- Use for: Forms, content sections
Start with Columns for mobile-first design. Rows work best for specific
desktop layouts that gracefully degrade to columns on mobile.
Spacing & Alignment
Gap
Space between child elements:0px
- Elements touch10px
- Tight spacing20px
- Standard spacing40px
- Breathing room
Alignment
Control how children position: Horizontal Alignment- Left - Start of container
- Center - Centered horizontally
- Right - End of container
- Top - Align to top
- Middle - Center vertically
- Bottom - Align to bottom
Visual Styling
Backgrounds
Transform containers into cards: Solid Colors- Add background color
- Adjust opacity for overlays
- Create visual separation
- Hero sections
- Patterned backgrounds
- Branded sections
Borders & Shadows
Borders Frame your content:- Width: 1-5px typically
- Color: Match brand colors
- Style: Solid, dashed, dotted
- Subtle: Slight elevation
- Medium: Clear separation
- Strong: Floating effect
0px
- Sharp edges8px
- Modern cards16px
- Soft containers50%
- Circular (if square)
Common Patterns
Two-Column Layout
Feature Cards
Testimonial Box
Pricing Table
Mobile Optimization
Containers adapt intelligently:Responsive Behavior
- Rows → Columns - Horizontal layouts stack vertically
- Proportional spacing - Gaps scale appropriately
- Touch-friendly - Padding increases on mobile
Best Practices
- Test row layouts on mobile
- Use columns for critical content
- Adjust gaps for mobile (usually smaller)
- Consider hide/show for desktop-only layouts
Avoid deeply nested containers (more than 3 levels) as they complicate
mobile layouts and slow rendering.
Advanced Techniques
Sticky Containers
Make containers stick while scrolling: Position: Attached- Stays fixed in viewport
- Good for: CTAs, navigation
- Becomes sticky after scrolling into view
- Good for: Share buttons, progress bars
Overlay Effects
Create overlays with containers:- Background image on container
- Semi-transparent color overlay
- Text content on top
- High contrast for readability
Conditional Containers
Show/hide entire sections:Animation Ready
Containers work with entrance animations:- Fade in groups of elements
- Slide in from side
- Scale up on appearance
Performance Tips
Optimize for Speed
- Limit nesting depth
- Use native CSS properties
- Compress background images
- Avoid too many shadows
Reduce Complexity
- Combine similar containers
- Use gaps instead of margin/padding on children
- Leverage browser defaults
Troubleshooting
Elements not aligning properly
Elements not aligning properly
- Check container alignment settings
- Verify orientation (row vs column)
- Look for conflicting child element positions
- Test without custom CSS first
Container background not showing
Container background not showing
- Ensure container has height (add padding)
- Check if children are positioned absolutely
- Verify background color opacity isn’t 0
- Look for z-index issues
Mobile layout broken
Mobile layout broken
- Test with columns instead of rows
- Check for fixed widths on children
- Verify responsive breakpoints
- Reduce container nesting
Gaps not working
Gaps not working
- Gap only affects direct children
- Check if browser supports gap property
- Try padding as alternative
- Verify orientation matches expectation
Design Examples
Hero Section
Feature Grid
Form Section
Accessibility
Containers improve accessibility:- Semantic grouping - Related content together
- Visual hierarchy - Clear content relationships
- Focus management - Tab order follows structure
- Screen reader friendly - Logical content flow