Aspect ratios

One page renders at any whole W:H ratio. Lay out with CSS, never crop.

The aspectThe aspect is the width-to-height ratio of a film, such as 16:9, 9:16 or 1:1. is the width-to-height ratio of a film. A page renders at any ratio of two whole numbers, such as 16:9, 9:16, 1:1, 4:5, 4:3, 2:1 or 1200:630. You write the layout once in CSS, and the renderer gives it a different size.

Why it exists

One film often goes to several places: a wide player, a phone feed, a square post. A film that crops one canvas to fit another loses the edges of its layout. A film that lays out again for each canvas keeps every word and every mark in the frame. So the renderer never crops. It gives the page the size of the aspect, and the page lays itself out.

How it works

One page, three aspects, three films. The names of the files carry the aspect.

The renderer picks the aspect in this order. The first one that exists wins:

  1. --aspect W:H on a render verb.
  2. <meta name="aspect"> in the page.
  3. 16:9.

It then sets three things before your scripts run:

  • <html data-aspect="W:H">, for example data-aspect="9:16".
  • --vw and --vh on :root, the width and height of the layout viewport as pixel lengths.
  • window.vawe.aspect, window.vawe.width and window.vawe.height.

The page sees an --aspect flag in the same way as the meta. A draft captures at half size, but the layout viewport has the full size, so a draft lays out exactly like a final.

Write the layout

Use --vh and --vw for sizes and [data-aspect] selectors for changes between aspects.

h1 { font-size: calc(var(--vh) * 0.11); }
[data-aspect="9:16"] h1 { left: 8%; top: 30%; }

--vh holds a unit (for example 1920px). Write calc(var(--vh) * 0.11), never * 0.11px.

Render an aspect

bin/vawe dev  films/<name>/page.html --aspect 9:16    # one draft
bin/vawe ship films/<name>/page.html --aspect all     # one file for each of the five common aspects
bin/vawe dev  films/<name>/page.html --aspect 2:1     # any whole W:H

--aspect all renders the five aspects in the table below, one file each. Any other ratio gets its own flag value. The default output name gets the aspect (-2x1), so two aspects do not overwrite each other.

bin/vawe frame <page> --at 0 --size 1200x630 writes a PNG of that size. The size must have the ratio of the aspect, so pass --aspect 1200:630 with it.

The page at 16:9: the title on the left, three lanes in a row on the right.
One page at 16:9. The layout comes from CSS, not from a crop.
The same page at 1:1: the title on top, the three lanes under it.
The same page at 1:1.
The same page at 9:16: the title and the lanes in one column.
The same page at 9:16. A max-aspect-ratio query moves the lanes into a column.

Sizes

aspectfinal size
16:91920 × 1080
9:161080 × 1920
1:11080 × 1080
4:51080 × 1350
4:31440 × 1080
any other W:H1920 px on the long edge

Any ratio with equal sides, such as 3:3, gives 1080 × 1080. A draft is half the size of the table. The renderer rounds each side of the output to an even number, because the encoder refuses an odd side.

Limits

  • A value that is not two whole numbers, such as 16/9 or 0:1, stops the render with an error that says is not a W:H ratio of whole numbers.
  • Two aspects of one page are two separate renders. Each one is deterministicDeterminism means that the same page gives the same frames on every render, in any order. by itself. See Determinism.

From the blogHTML video aspect ratio: 16:9, 9:16 and 1:1

On this page