Displays content within a desired ratio. The box fills the width of its container and sets its height from ratio with the CSS aspect-ratio property.
<script lang="ts">
import { AspectRatio } from "#lib/components/ui/aspect-ratio/index.js";
</script>
<AspectRatio ratio={16 / 9} rounded="lg">
<img src="/photo.jpg" alt="A city street at night" />
</AspectRatio>pnx remote0 add https://plainsv.com/r/aspect-ratio.jsonSet ratio to the width divided by the height, such as 16 / 9 or 4 / 3. The default is 1, a square. Images, videos, and iframes placed directly inside cover the box and crop to the ratio.
<AspectRatio ratio={4 / 3}>
<div>Any content</div>
</AspectRatio>The box is square-cornered by default. Set rounded to xs through 4xl or pill to round it and clip the content to the corners. pill is a true pill and can clip tall content, so use 3xl or 4xl for round corners that stay safe. The box has no padding or text of its own, so there is no size prop.
<AspectRatio ratio={1} rounded="lg">...</AspectRatio>The AspectRatio props extend the native div attributes.
interface Props extends CompPropsWithChild<"div"> {
/** Width divided by height, such as `16 / 9`; defaults to `1` */
ratio?: number;
/** Corner radius; square when omitted. Clips the content to the corners. `pill` is a true pill that can clip the content, so use `3xl` or `4xl` to stay round */
rounded?: UiRounded;
}