Aspect Ratio

A layout component that maintains a specified aspect ratio for its content, useful for embedding responsive images, videos, and maps.

Anatomy

<script>
  import { AspectRatio } from "@saas-ui/svelte/layout/aspect-ratio";
</script>

<AspectRatio ratio={16/9}>
  <img src="image.jpg" alt="..." />
</AspectRatio>

Examples

Basic Accessibility

Basic aspect ratio container with a configurable ratio value.

Common Ratios Accessibility

Examples of common aspect ratios: 1:1 (square), 4:3 (standard), 16:9 (widescreen), and 21:9 (ultrawide).

Google Map Accessibility

Embed responsive Google Maps or other iframes with consistent aspect ratios.

Image Accessibility

Use AspectRatio to display images that maintain their proportions within a fixed ratio container.

Responsive Accessibility

The aspect ratio is maintained across all viewport sizes while the container scales responsively.

Video Accessibility

Embed responsive videos that maintain a 16:9 aspect ratio regardless of container width.

Props

Prop Type Default Description
ratio number 4/3 The aspect ratio of the container. Common values are: 21/9, 16/9, 9/16, 4/3, 1.85/1, 1
children any - The content to be rendered inside the component.
class text - Additional CSS classes to apply.