AspectRatio
AspectRatio keeps a child's width and height in a fixed relationship while
the parent still decides its size.
Use it for previews, thumbnails, video, maps, or card media when the shape
should stay consistent as the layout changes.
Use AspectRatio when the child should scale responsively while preserving shape. Do not use it when you already know both the exact width and exact height, or when you need cropping or clipping rather than proportional sizing.
Example
use fission::prelude::*;
fission_component! {
pub MediaFrame<()> {
props { content: Widget }
}
view(frame, _state, _cx) =>
AspectRatio(ratio: 16.0 / 9.0, child: frame.content.clone())
}
The parent still controls how much space is available. AspectRatio only makes sure the child stays in the requested proportion.
Field table
| | | |
|---|
| | | Required. 16.0 / 9.0 gives a widescreen rectangle; 1.0 gives a square. |
| | The node constrained by the ratio. | Required. The child still renders normally inside the resulting box. |
Layout behavior
Internally, AspectRatio lowers to a box layout node with aspect_ratio: Some(ratio). If only one dimension becomes bounded by the parent, the other dimension is derived from the ratio. If both dimensions remain flexible, the surrounding constraints decide the final size.
That means AspectRatio is about sizing, not clipping. If the child paints outside its bounds or needs rounded corners, pair it with Clip or Container. Specific advice
Keep the ratio positive and meaningful. A very common pattern is 1.0 for avatars or tiles and 16.0 / 9.0 for media. If your layout needs cards that automatically wrap while keeping consistent preview shapes, combine AspectRatio with SimpleGrid. Production checklist
Keep the ratio positive and test the actual parent constraints, not only a
standalone fixed-size preview.
Check portrait and landscape media; choose image/video fit separately from
the frame ratio.
Add clipping only when the design requires it, and verify that it does not
hide meaningful content or input targets.