Layout
Aspect Ratio
Usage#
import { WdsAspectRatioComponent } from '@wds/angular/aspect-ratio';Examples#
Default#
ratio="16/9": the shape of video players. The width comes from the layout, the height from the ratio.
import { Component } from '@angular/core';
import { WdsAspectRatioComponent } from '@wds/angular/aspect-ratio';
@Component({
selector: 'app-aspect-ratio-default-demo',
imports: [WdsAspectRatioComponent],
template: `
<div class="w-full max-w-md">
<wds-aspect-ratio ratio="16/9" class="w-full">
<div class="flex size-full items-center justify-center rounded-lg bg-muted text-sm font-medium text-muted-foreground">16 / 9</div>
</wds-aspect-ratio>
</div>
`,
})
export class AspectRatioDefaultDemo {}Square#
1/1 for product shots, covers and grid tiles.
import { Component } from '@angular/core';
import { WdsAspectRatioComponent } from '@wds/angular/aspect-ratio';
@Component({
selector: 'app-aspect-ratio-square-demo',
imports: [WdsAspectRatioComponent],
template: `
<div class="w-full max-w-xs">
<wds-aspect-ratio ratio="1/1" class="w-full">
<div class="flex size-full items-center justify-center rounded-lg bg-muted text-sm font-medium text-muted-foreground">1 / 1</div>
</wds-aspect-ratio>
</div>
`,
})
export class AspectRatioSquareDemo {}Portrait#
9/16 for stories and vertical video.
import { Component } from '@angular/core';
import { WdsAspectRatioComponent } from '@wds/angular/aspect-ratio';
@Component({
selector: 'app-aspect-ratio-portrait-demo',
imports: [WdsAspectRatioComponent],
template: `
<div class="w-full max-w-[12rem]">
<wds-aspect-ratio ratio="9/16" class="w-full">
<div class="flex size-full items-center justify-center rounded-lg bg-muted text-sm font-medium text-muted-foreground">9 / 16</div>
</wds-aspect-ratio>
</div>
`,
})
export class AspectRatioPortraitDemo {}Ultrawide#
21/9 for banners and page headers.
import { Component } from '@angular/core';
import { WdsAspectRatioComponent } from '@wds/angular/aspect-ratio';
@Component({
selector: 'app-aspect-ratio-ultrawide-demo',
imports: [WdsAspectRatioComponent],
template: `
<div class="w-full max-w-md">
<wds-aspect-ratio ratio="21/9" class="w-full">
<div class="flex size-full items-center justify-center rounded-lg bg-muted text-sm font-medium text-muted-foreground">21 / 9</div>
</wds-aspect-ratio>
</div>
`,
})
export class AspectRatioUltrawideDemo {}Other ratios#
4/3 (photos from phones), 3/2 (cameras), 4/5 (portrait posts) and 16/10 (laptop screens). 16:9 and a number such as 1.5 also work.
import { Component } from '@angular/core';
import { WdsAspectRatioComponent } from '@wds/angular/aspect-ratio';
@Component({
selector: 'app-aspect-ratio-ratios-demo',
imports: [WdsAspectRatioComponent],
template: `
<div class="w-full">
<div class="mx-auto grid w-full max-w-md grid-cols-2 gap-4">
<wds-aspect-ratio ratio="4/3">
<div class="flex size-full items-center justify-center rounded-lg bg-muted text-sm font-medium text-muted-foreground">4 / 3</div>
</wds-aspect-ratio>
<wds-aspect-ratio ratio="3/2">
<div class="flex size-full items-center justify-center rounded-lg bg-muted text-sm font-medium text-muted-foreground">3 / 2</div>
</wds-aspect-ratio>
<wds-aspect-ratio ratio="4/5">
<div class="flex size-full items-center justify-center rounded-lg bg-muted text-sm font-medium text-muted-foreground">4 / 5</div>
</wds-aspect-ratio>
<wds-aspect-ratio ratio="16/10">
<div class="flex size-full items-center justify-center rounded-lg bg-muted text-sm font-medium text-muted-foreground">16 / 10</div>
</wds-aspect-ratio>
</div>
</div>
`,
})
export class AspectRatioRatiosDemo {}Image#
<img>, <video> or <iframe> inside fills the box (object-fit: cover).
import { Component } from '@angular/core';
import { WdsAspectRatioComponent } from '@wds/angular/aspect-ratio';
@Component({
selector: 'app-aspect-ratio-image-demo',
imports: [WdsAspectRatioComponent],
template: `
<div class="w-full max-w-xs">
<wds-aspect-ratio ratio="1/1" class="w-full overflow-hidden rounded-lg">
<img src="https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=600&h=600&q=80" alt="Portrait of a man in a grey shirt" />
</wds-aspect-ratio>
</div>
`,
})
export class AspectRatioImageDemo {}API References#
wds-aspect-ratio#
16/9 for video or 1/1 for a square tile.
The width comes from the layout; the height follows from ratio. An image or video inside fills the box.
Attributes
| Attribute | Type | Default | Description |
|---|---|---|---|
| ratio | string | '1' | 16/9, 16:9, 4/3 or a number such as 1.5. |
Slots
| Slot | Description |
|---|---|
| (default) |
Accessibility#
Screen reader#
wds-aspect-ratio only sizes its content and has no role. Give an image inside an alt text, or alt="" when it is decorative.
Keyboard support#
wds-aspect-ratio is not focusable and has no keyboard interaction.