Aspect Ratio
AspectRatio is a layout component that maintains a consistent width-to-height ratio for its children. This is particularly useful for responsive media content like videos, images, and iframes that need to scale proportionally.Installation
Usage
Video Embedding
Use AspectRatio to embed responsive videos that maintain their aspect ratio:Image Containers
Create consistent image containers with specific aspect ratios:Common Aspect Ratios
Props
The aspect ratio using a colon-separated number pattern (width:height). Examples: “16:9”, “4:3”, “1:1”, “21:9”.
The content to maintain at the specified aspect ratio. Commonly used with iframe, video, img, or other media elements.
Best Practices
Do
- Use AspectRatio for media content that needs to scale responsively
- Use standard aspect ratios like 16:9 for videos and 4:3 for images
- Ensure the ratio prop uses the correct format (width:height with colon)
- Wrap iframes, videos, and images that need consistent proportions
Don’t
- Don’t use AspectRatio for content that doesn’t need a fixed aspect ratio
- Don’t use invalid ratio formats (the component will throw an error)
- Don’t nest multiple AspectRatio components
- Don’t use for layout containers that should flow naturally
Accessibility
- AspectRatio is purely a layout component with no accessibility requirements
- Ensure child elements (iframes, videos, images) have appropriate accessibility attributes
- Provide descriptive alt text for images
- Include title attributes for iframes
- Ensure videos have captions when needed
Related Components
- Box - Flexible container component
- Media Object - Layout for image/icon with text content