Skip to content
Pebble Pro is here at $49 one timeSee what’s included ↗
Pebble
ComponentsDocsMCPPricing
⌕ Find a component↗Log in
All components 673

Categories

Core inputs & forms46Buttons & actions33Navigation36Overlays & feedback49Data display33Charts & data viz40Cards & layout43Marketing blocks38App shells & pages37AI interfaces40Text & typography effects33Backgrounds & visual effects38Motion & transitions32Numbers & counters32Media34E-commerce333D & interactive36Themed sets40
Start with the essentials.Installation guide ↗Connect your agent ↗
← All componentsCards & layout

Aspect Ratio

Box that locks its content to a width-to-height ratio, built on Radix AspectRatio.

Preview

Ridge Loop

4.1 of 6.2 km · Priya, 38 min

16:9

No cover photo

4:3, at least 1200 px wide

variant="well" · empty
3:4Ines
21:9Tomás

Install

Add the editable source with the shadcn CLI. Your project also needs the shared theme tokens this component uses. Setup and requirements. The Pebble installer is not published yet.

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

Props

PropTypeDefaultDescription
rationumber1Width divided by height, e.g. 16 / 9.
variant"plain" | "well""plain"Plain is an invisible box; well is a recessed frame for media.
asChildbooleanfalseRender the inner box as the child element.
classNamestring-Merged after the default overflow-hidden on the inner box.
Build notes
Radix renders two divs: an outer wrapper with `position: relative; width:
100%; padding-bottom: (100 / ratio)%`, and the inner element (which gets our
`data-slot` and className) at `position: absolute; inset: 0`. Percentage
padding resolves against the parent's width, which is what locks the ratio;
this works everywhere, unlike relying on the CSS `aspect-ratio` property for
replaced content in older engines. We add `overflow-hidden` by default so
rounded corners clip the media; className overrides it. Children usually take
`size-full object-cover`.

**Pebble (2026-11-03).** New optional `variant`; `well` adds `rounded-xl
bg-muted ring-1 ring-hairline inset-shadow-xs` for empty media slots, and the
root carries `data-variant`. Radix puts the ratio on the outer wrapper's
inline `padding-bottom`, so a parent can animate a ratio change with
`motion-safe:*:transition-[padding-bottom] *:duration-(--motion-base)
*:ease-move`; the component itself stays static. The demo has no gradient
art: a drawn SVG trail map (`preserveAspectRatio="xMidYMid slice"`, so it
crops to any ratio) under a 16:9 / 4:3 / 1:1 switcher, a `well` empty state,
and fixed 3:4 and 21:9 crops of the same map.

<!-- PEBBLE-LICENSE -->
View source

registry/layout/aspect-ratio/aspect-ratio.tsx

"use client";

/* PEBBLE-LICENSE
Built by Pebble. Component: aspect-ratio.

First-party license: MIT

The following first-party terms apply only to original Pebble material.

MIT License

Copyright (c) 2026 Praxys Solutions LLC (Pebble)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

THIRD-PARTY NOTICES
These notices apply to identified upstream portions; Pebble terms do not replace or narrow their rights.

Upstream: https://raw.githubusercontent.com/shadcn-ui/ui/main/LICENSE.md
MIT License

Copyright (c) 2023 shadcn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
END PEBBLE-LICENSE */

import * as React from "react";
import { AspectRatio as AspectRatioPrimitive } from "radix-ui";

import { cn } from "@/lib/utils";

// Pebble: `plain` is an invisible box; `well` is a recessed frame for media
// that has not loaded or has no edge of its own.
const variants = {
  plain: "",
  well: "rounded-xl bg-muted ring-1 ring-hairline inset-shadow-xs",
} as const;

export type AspectRatioProps = React.ComponentProps<typeof AspectRatioPrimitive.Root> & {
  variant?: keyof typeof variants;
};

/**
 * Locks its child to a width:height ratio (`ratio`, default 1). The box takes
 * the parent's width; the height follows from the ratio.
 */
export function AspectRatio({ variant = "plain", className, ...props }: AspectRatioProps) {
  return (
    <AspectRatioPrimitive.Root
      data-slot="aspect-ratio"
      data-variant={variant}
      className={cn("overflow-hidden", variants[variant], className)}
      {...props}
    />
  );
}
Pebble

Small details.
Better interfaces.

React components to explore, make your own, and build on.

Library

  • Components
  • Installation
  • Pricing

Resources

  • For agents
  • About
  • Support

Legal

  • License
  • Terms
  • Privacy
  • Final sale

Built by Pebble

A product of Praxys Solutions LLC ↗

Pebble Pro is live

$49 one time, lifetime updates ↗