Nasaq

AspectRatio

A box that keeps a fixed width-to-height ratio as it resizes, for video embeds, maps, cover images and thumbnails; direct img, video and iframe children fill it.

PreviewOpen โ†—

Code

import { AspectRatio } from "@fadymondy/nasaq/web";export function Intro() {  return (    <AspectRatio ratio={16 / 9} className="rounded-card border border-border">      <iframe src="https://www.youtube-nocookie.com/embed/VIDEO_ID" title="Product tour" allowFullScreen />    </AspectRatio>  );}

Layout ยท beta

Live examples and controls: AspectRatio in the lab.

Install

npx shadcn@latest add https://docs.nasaqui.com/r/aspect-ratio.json

A div with CSS aspect-ratio. It reserves the height before media loads, so the page does not jump.

When to use

  • Video and map embeds, cover images, thumbnails in a grid.

When not to use

  • Images with known width and height attributes: the browser already reserves their space.
  • Text content: let it set its own height.

Import

import { AspectRatio } from "@fadymondy/nasaq/web";
// inside this monorepo: "@nasaq/web"

Quick start

import { AspectRatio } from "@fadymondy/nasaq/web";

export function Intro() {
  return (
    <AspectRatio ratio={16 / 9} className="rounded-card border border-border">
      <iframe src="https://www.youtube-nocookie.com/embed/VIDEO_ID" title="Product tour" allowFullScreen />
    </AspectRatio>
  );
}

Anatomy

AspectRatio                     data-slot="aspect-ratio", style="aspect-ratio: <ratio>"
โ””โ”€ img | video | iframe         absolutely fills the box (img and video use object-cover)

Other children flow normally inside the box.

API

AspectRatio: every div prop, plus:

PropTypeDefaultDescription
rationumber16 / 9Width over height: 16 / 9, 4 / 3, 1.

Accessibility

  • Give every iframe a title and every img an alt; the box adds no semantics.

RTL & i18n

  • Nothing to mirror.

Styling & tokens

  • No visual style of its own. Add rounded-card and border-border; overflow-hidden is set so corners clip.

Do / Don't

  • Do pick the media's real ratio so nothing is cropped by surprise.
  • Don't put long text inside; it overflows on narrow screens.

Lab

https://docs.nasaqui.com/?path=/docs/components-layout-aspect-ratio--docs

On this page