HextaUI

Aspect ratio: Responsive

Override the ratio at a breakpoint with an aspect class. This one is square on small screens and md:aspect-video from md up.

Sunset over mountains
import { AspectRatio } from "@/components/ui/aspect-ratio"

export function AspectRatioResponsive() {
  return (
    <div className="w-full max-w-md">
      <AspectRatio ratio={1} className="rounded-lg md:aspect-video">
        <img src="/preview/landscape.svg" alt="Sunset over mountains" />
      </AspectRatio>
    </div>
  )
}

This adds the example as components/examples/aspect-ratio/responsive.tsx, together with the Aspect ratio component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/aspect-ratio-responsive.json

To add only the component, follow the Aspect ratio installation.

Props in this example

The Aspect ratio props this example sets, from the API reference.

PropTypeDefault
ratio
number | `${number}/${number}` | `${number}:${number}`1

Every prop is in the Aspect ratio API reference.

See them all, with keyboard support and accessibility notes, on the Aspect ratio page.