AspectRatio
XS · 350B gzip budgetContainer that maintains a fixed aspect ratio.
- Category
- Media & layout
- Budget
- xs, static display primitive
- External runtime
- React / React DOM only
axe fixtureSSR rendersource scanbundle budget
Preview
Live fixtureTry the component here. Locale-aware formatting and direction follow the selected language; example content and labels are not automatically translated. Overlay demos use interactive launchers.
Install
npx shadcn@latest add https://gear5-ui.vercel.app/r/aspect-ratio.jsonCopies the source into your project.
New here? Set up Tailwind and import aliases first →Source & props
Edit on GitHub ↗Prop types and inline documentation are included below. This is repository source; the installer rewrites shared imports for your project.
"use client";
import React from "react";
export interface AspectRatioProps {
children: React.ReactNode;
ratio?: number;
className?: string;
as?: "div" | "section" | "article";
}
export function AspectRatio({
children,
ratio = 16 / 9,
className = "",
as = "div",
}: AspectRatioProps) {
const Tag = as;
return (
<Tag
className={className}
style={{
position: "relative",
width: "100%",
paddingBottom: `${(1 / ratio) * 100}%`,
overflow: "hidden",
}}
>
<div
style={{
position: "absolute",
inset: 0,
display: "flex",
alignItems: "center",
justifyContent: "center",
}}
>
{children}
</div>
</Tag>
);
}
What CI checks
Quality contract- Bundled, minified and gzipped against its tier budget
- Audited by axe in the state previewed above
- Rendered through react-dom/server with no browser globals
- Scanned for network calls, dangerous sinks, and unguarded animation