Utilities✨ Premium

Dynamic Aspect Ratio

Media area that picks its format from the width available — square, 4:3, 16:9 then 21:9 — with a badge showing the format actually applied.

CSS@containerAspect Ratio

Updated

This effect is part of Effect.Labs — 840 vanilla effects, some free, some premium. Utilities has 43 effects, including 3 free. Explore the category →

3 usage examples

“Les Vergers de Tallanche” film page — 21:9 player on top, square clips below — Dynamic Aspect Ratio example 1

① “Les Vergers de Tallanche” film page — 21:9 player on top, square clips below

WhenOn the film page the trailer fills the top in 21:9; below, three clips reuse the same component in 84 px cells and turn square. Nothing to do: each area reads its own width.
WhyOne media area for the header and the thumbnails: no crop to plan for each slot.
SettingsThe player is a 600 px root shown at 80 % (transform: scale(.8) on its parent) to fit the scene; clips are 84 px roots. Different gradients set with style="background-image:…"; the position animation keeps running.
Cadrevelle scheduling tool — widening the preview of a post — Dynamic Aspect Ratio example 2

② Cadrevelle scheduling tool — widening the preview of a post

WhenIn the preview of a scheduled post, pull the handle (or use the arrow keys): the image goes from square to 4:3, 16:9 then 21:9, and the badge shows the format at each step. On load the preview sweeps from 230 to 640 px and back.
WhyOne gesture shows how the visual will be cropped depending on the slot width.
SettingsWork area shown at 72 % so every step fits; handle setting the frame width between 200 and 640 px.
Visorne video call — the screen share goes from 16:9 to 4:3 when participants open — Dynamic Aspect Ratio example 3

③ Visorne video call — the screen share goes from 16:9 to 4:3 when participants open

WhenJade shares her screen in 16:9 across the full width. Clicking “Participants (4)” opens the list on the right: the share area shrinks under 450 px and turns 4:3, badge included.
WhyThe share stays whole, in a format consistent with the room it has left, with no hand-computed letterboxing.
SettingsButton (aria-expanded) opening a 178 px column in the scene grid; call toolbar laid over the area.

How it works

.fx-0764-root is a transparent container (container: dar-media / inline-size) taking the full width. The .dar-media area has 10 px corners, a centred label and a cyan-blue-violet gradient twice its size, whose position slides in a 6 s loop (@keyframes dar-shift). Its height comes only from aspect-ratio, which starts at 1 / 1.

Three @container dar-media steps change the format: 4 / 3 from 300 px, 16 / 9 from 450 px, 21 / 9 from 600 px. The label grows at the same time (0.85 to 1.4 rem). The format change is animated over 0.5 s: measured, the area eases from the square height to the 16:9 height in all three engines tested.

The .dar-badge is empty in the HTML; its text comes from ::before, redefined in every step (content: "16:9"…). So it is always right, whatever makes the width change, and with no script. For real media, set your image or video as the .dar-media background, or put an <img> / <video> inside with object-fit: cover.

Accessibility

  • Badge is read: text generated by ::before is part of the name read by recent screen readers (“16:9”). If it means nothing to your audience, add aria-hidden="true" to the badge.
  • Reduced motion: under prefers-reduced-motion: reduce, the gradient stops sliding (it stays, still) and format and label changes happen without transition.
  • Contrast: shadowed white label on the default gradient: at least 4.6:1 on all three colours, measured in Chromium, Firefox and WebKit at several points of the animation; white badge on a 45 % black veil. With a light photo behind, darken it or strengthen the badge veil.
  • Media to describe: the area is a div; if you put a meaningful picture in it, use an <img alt="…"> rather than a CSS background.

Browser compatibility

Container queries, aspect-ratio (Chrome 88, Firefox 89, Safari 15) and a CSS animation. Measured in Chromium 151, Firefox 153 and WebKit 26.5: 1:1 up to 260 px, 4:3 from 300 to 430, 16:9 at 520, 21:9 at 620 and 800 px, badge matching the displayed format every time.

Chrome 105+✓ Full (measured)
Firefox 110+✓ Full (measured)
Safari 16+✓ Full (measured in WebKit)
Edge 105+✓ Full
Mobile iOS 16+✓ Full
Android Chrome 105+✓ Full

Without @container the area stays square and the badge reads “1:1”, which is still accurate.

The code

HTML structure to paste into your page (the CSS + JS come with your purchase):

index.html — structure
<div class="fx-0764-root">
  <div class="dar-media">
    <span class="dar-label">Dynamic Ratio</span>
    <span class="dar-badge"></span>
  </div>
</div>

One-time payment, no subscription — the code is yours forever

Customize

Options passed to the API or data-* attributes:

Option / propertyDefaultEffect
Steps and formats (CSS — @container dar-media (min-width: …) and aspect-ratio) 1:1, 4:3 from 300, 16:9 from 450, 21:9 from 600 px Change each aspect-ratio and the badge content in the same rule so they stay in step (e.g. 3:2 instead of 4:3).
Visual (CSS or HTML — .dar-media) #048096 → #1b6df5 → #8453f5 gradient, animated For a photo, replace the background with url(…) center / cover and remove animation.
Gradient speed (CSS — animation: dar-shift 6s) 6 s, looping 12 s for barely visible motion, none for a still background.
Badge (HTML/CSS — .dar-badge) Visible, top right Delete the tag for media with no hint, or move it with top/left.
Label (HTML — .dar-label) “Dynamic Ratio” Put the video title, or remove it for an image on its own.
Format transition length (CSS — transition: aspect-ratio .5s) 0.5 s none if the area sits in a list that resizes often.

FAQ

Yes. Its text is set in CSS in the same rule as the format: when the area turns 16:9, the badge reads “16:9” at the same moment, whether the width changed because of the window, a column or a panel.
Place a <video> inside .dar-media with position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover. The area keeps the computed format and the video is cropped inside it.
Under 300 px wide, square is the first step. Lower the 4:3 step (to 220 px, say) if you prefer a shorter picture in narrow columns.