Mushilu-San UI

Search components

PlaygroundStorybookGitHub
Layout

Aspect ratio

Keeps its content at a fixed width-to-height ratio, such as 16:9 for video.

Selector: mui-aspect-ratio

Import
import { AspectRatio } from '@mushilu-san/ui/layout';
PreviewCode

Loading example…

Overview

Aspect ratio sizes its box from the width and keeps the ratio as the width changes. The ratio input is width divided by height, so 16 / 9 is the default.

The content is stretched to fill the box, so use it for images, video and embeds.

When to use

  • Keeping a video, image or map at a fixed shape while the layout width changes.
  • Reserving space for media so the page does not shift when it loads.

When not to use

  • Text content with an unknown height. Let it size itself.

Guidelines

Do

  • Give images a meaningful alt text when they are content.

Don't

  • Do not use it to force text into a shape. Text can overflow the box.

Accessibility

Roles and attributes

ElementRoleNotes
host—A layout wrapper with no role. Accessibility comes from the content inside.
  • Make sure the content inside is accessible, such as an image with alt or a video with captions.

API

AspectRatio

Selector: mui-aspect-ratio

NameTypeDefaultDescription
rationumber16 / 9 Numeric ratio — width divided by height. Default 16/9 ≈ 1.778.

CSS parts

  • ::part(inner)
  • ::part(root)

Tokens

  • --mui-radius-md