Aspect Ratio
A box that keeps a width-to-height ratio, filled by its content.
When to use
- Use when
- Images, video, maps, or embeds that must keep their shape as the layout resizes.
- Avoid when
- The content has its own intrinsic size, such as an img with width and height set.
Installation
The source lands in src/components/ui/aspect-ratio.tsx, along with any Shelf items it builds on, and .shelf/lock.json records what was installed. It's yours to edit.
Usage
Built on
- Packages
@stylexjs/stylex- Shelf items
utils- Figma
- Optional native Figma library. See Designers.
Verified
- Size
- 0.4 kB gzipped on its own, 1.4 kB with the Shelf items and packages it builds on. JS and CSS in a production build, without React.
- Accessibility
- Axe passes on 2 stories
- Behavior
- 2 interaction tests in Storybook
- React Doctor
- React Doctor finds nothing