Component libraryAspect ratio
Components/Essentials

Aspect ratio

Free

Reserve media space at a chosen width-to-height ratio before content loads.

npx shadcn@latest add https://tidalui.com/r/aspect-ratio.json
Desktop viewport

Installation

Terminal
npx shadcn@latest add https://tidalui.com/r/aspect-ratio.json

Import components/ui/tidal.css, components/ui/aspect-ratio.css, then add the component inside a tidal-scope wrapper. Its scoped design tokens keep it independent of your existing CSS.

Usage

Complete example source · Dependency and asset manifest

Loading the complete example…

API & behavior

Native div attributes/ref and children (raw root HTML is excluded because the frame owns its content wrapper), ratio (width divided by height, defaults to 16/9; nonfinite or nonpositive values fall back to 16/9), and optional clip=false. Direct image/video/canvas/svg children fill the reserved frame with object-fit:cover; callers can override media fit and position with their own CSS. Captions belong outside the frame. The ratio owns inline aspectRatio; explicit caller width/height/min/max geometry remains their responsibility. clip=true hides overflowing media, while false preserves visible focus rings. No media fetch, load state, semantics, or animation is invented.

Style with the --t-* CSS variables. Set data-theme="dark" on your tidal-scope wrapper for a dark surface. Motion respects the system’s reduced-motion preference.

Building with an agent?Give it the installation guide and component catalog.