Hulian UIv0.93.5413 components0 components
  • Start
  • Components
  • Blocks
  • Pages
  • Demos
  • Changelog
ChineseEnglish
  • ComponentsComponents
  • ThemeTheme

Containers

  • Layout
  • AdminLayout
  • SettingsLayout
  • ScrollArea
  • Viewport
  • Resizable
  • AspectRatio
  • FitScreen
  • PreviewSandbox
  • Masonry
  • Container
  • AccentScope

Arrangement

  • Stack
  • Grid
  • Spacer
  • Divider
  • Separator

AspectRatio

aspect-ratio

Keeps media or content inside a fixed width-to-height ratio.

Usage

16 / 9 widescreen

Use ratio to lock the aspect ratio, and the height will adapt proportionally when the container width changes (commonly used for videos/covers).

16 / 9
tsx
<div className="w-64">
  <AspectRatio ratio={16 / 9}>
    <img src="..." alt="..." />
  </AspectRatio>
</div>

1 / 1 square

ratio={1} Lock square, suitable for avatars, thumbnails, and icon placeholders.

1 / 1
tsx
<div className="w-40">
  <AspectRatio ratio={1}>
    <img src="..." alt="..." />
  </AspectRatio>
</div>

Vertical 3 / 4

ratio is less than 1, which is the vertical ratio, suitable for portrait cards/posters.

3 / 4
tsx
<div className="w-40">
  <AspectRatio ratio={3 / 4}>
    <img src="..." alt="..." />
  </AspectRatio>
</div>

When to use

Use AspectRatio to keep an image, video, or card at a fixed ratio such as 16:9, 1:1, or 4:3. Its height follows the available width without layout shift. The component only constrains the ratio using CSS and can render as an RSC. Use Viewport when the layout itself must respond to container width, or FitScreen when a fixed-size design must be scaled proportionally to fill the available area.

Import

ts
import { AspectRatio } from "@hulianui/ui"

Props

NameTypeDefaultDescription
rationumber1Width divided by height, such as 16/9, 1, or 4/3.

Inherits HTMLAttributes<HTMLDivElement>.

Slots

SlotTypeDescription
childrenReactNodeChild content, usually an image or video, that automatically fills the container.

Usage guidelines

  • ratio is a number, not a string. Pass an expression such as 16 / 9 or a numeric value such as 1.7778; do not pass "16/9".
  • The parent determines the width. AspectRatio fills the available width and derives its height from ratio. If the parent does not constrain the width, the component expands to the full available width. Child elements do not need their own w-full h-full; the component already stretches them to fill the container.

Related

Layout · AdminLayout · ScrollArea · Viewport · Resizable · FitScreen

Playground

ratio 1.78
<AspectRatio ratio={1.7778}>
  <img src="..." alt="..." />
</AspectRatio>
PreviousResizableLayoutNextFitScreen

On this page

  • Usage
  • Documentation
    • When to use
    • Import
    • Props
    • Slots
    • Usage guidelines
    • Related
  • Playground