Aspect Ratio
16 : 9
Constrains its content to a fixed width-to-height ratio (pure CSS aspect-ratio).
Import
Section titled “Import”<script> import AspectRatio from "@invisible-ui/svelte/AspectRatio.svelte";</script><script setup> import { AspectRatio } from "@invisible-ui/vue";</script>import { AspectRatio } from "@invisible-ui/react";<script type="module"> import "@invisible-ui/elements/define";</script>
<ds-aspect-ratio></ds-aspect-ratio>In Elements:
<ds-aspect-ratio ratio="16/9"> <img src="/cover.jpg" alt="Harbour at dawn" /></ds-aspect-ratio>| Prop | Type | Default | Description |
|---|---|---|---|
ratio | number | 1 | Width ÷ height (e.g. 16 / 9). |
| Prop | Type | Default | Description |
|---|---|---|---|
ratio | number | 1 | Width-to-height ratio, e.g. 16 / 9, 4 / 3, 1. |
Slots: default.
| Prop | Type | Default | Description |
|---|---|---|---|
ratio | number | 1 | Width-to-height ratio, such as 16 / 9, 4 / 3 or 1. |
children | ReactNode | — | The media or block content to fit in the box. |
| Attribute | Reactive | Description |
|---|---|---|
ratio | yes | width to height, as 16/9 or a number; 1 by default |
Reactive attributes re-render the element when they change after the first render.
Properties: ratio (number).
The content is the default slot (an image, video, map, …).
Example
Section titled “Example”<AspectRatio ratio={16 / 9}><img src="/cover.jpg" alt="" /></AspectRatio>In React:
<AspectRatio ratio={16 / 9}> <img src="/cover.jpg" alt="" /></AspectRatio>Presentational — no ARIA of its own.