Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

← All tutorials

Tutorial: Blog post

Build a long-form article: a title and byline, five sections, a quote, a code sample, a chart, tags and a list of further reading. You'll write it as plain HTML, then add a reading width, two small custom elements and a generated table of contents.

About 15 minutes · Uses all four layers: semantic HTML, layout attributes, custom elements, web components

The finished page. Scroll it and try the contents list.

Before you start

Make a folder, and in it one file called index.html. Paste in this starter and open the file in a browser. Everything in the tutorial goes inside <body>.

The <link> is the whole install for the first three steps. The one line of CSS keeps the text off the edge of the window, using a Vanilla Breeze spacing token; it is the only CSS you will write. There is no script tag yet: you add it in step 4, the only step that needs it. For npm and self-hosting, see Quick Start.

Step 1 — Semantic HTML

An article is mostly decisions about meaning, and HTML already has an element for each one.

The post is an <article> with a <header> for the title and byline and a <footer> for what comes after the text. The date is a <time> with a machine-readable datetime. The quote is a <blockquote> whose own <footer> names the speaker. The code is <pre><code>. The chart is an inline SVG in a <figure> with a <figcaption>, so the file needs no image. The further reading is a native <details>, which opens and closes without any script.

Three smaller choices matter later. Each <h2> gets an id you chose, so a link to #results keeps working if you reword the heading. Each tag is a link with rel="tag", and the author link has rel="author": both say what the link is, and the stylesheet draws tag links as pills because of it. The opening paragraph has class="lead", one of a few variant classes Vanilla Breeze defines for cases where HTML has no element.

Check

Step 2 — A reading measure with layout attributes

Long text needs a measure: a line short enough that your eye finds the start of the next one. It also needs rhythm, with more space above a heading than below it so each heading belongs to the text that follows.

data-layout="prose" does both. It caps the article at 65 characters per line, spaces its direct children, and gives the figure, the code block and the quote extra room. data-layout-centered puts the column in the middle of the page. You could get the width alone from data-layout="center" with data-layout-max="prose", but then you would have to space every heading yourself.

The rhythm reaches direct children only, so the lines inside the <header> and <footer> are still touching. Each becomes a stack with its own gap: tight in the header, where three lines form one unit, and looser in the footer. The tag list takes class="inline", the list variant that lays items out in a wrapping row without bullets. A layout attribute would arrange the items but leave the bullets, so the variant class is the right tool here.

What changed

Step 3 — Custom elements where HTML has no word

Custom elements in Vanilla Breeze are new tag names styled by the same stylesheet. The ones in this step have no JavaScript. The test for using one: is there a thing on the page that HTML has no element for, and that you would otherwise build from a <span> and a class?

This article has two. "Field notes" is a category label: not a heading, not a link, just a small chip. That is <layout-badge>; data-variant="subtle" and data-color="primary" give it a quiet tint that follows the theme. The byline gets a <user-avatar> showing the author's initials in a data-fallback span. The name is printed right beside it, so the avatar is marked aria-hidden="true" and a screen reader does not read "ML" before "Mara Lindqvist".

The tags fail the test, so they stay as they are. They are links, HTML has an element for links, and rel="tag" already makes them pills.

What changed

Step 4 — Web components: a table of contents and heading links

Web components are the layer that needs JavaScript, so the test is stricter: does the reader get something the first three layers cannot give, and is the page still whole without it?

A five-section article passes twice. A list of its sections helps a reader decide where to start, but a list written by hand goes stale the first time you rename a heading. <page-toc> builds the list from the headings on the page. It needs each heading to have an id, which is why you wrote them in step 1. levels="h2" limits it to the section headings and data-title sets its label. Its scope is a CSS selector and it reads the first element that matches. The default is main; main article says exactly which article you mean, so the list stays right when the page later gains a second one, such as a comment or a related post.

The second is sharing a section. <heading-links> adds a link icon to each heading it contains; activating one jumps to that section and copies its address. It goes around the <article>, not inside it. Inside, it would become the article's only direct child and the step 2 rhythm would have nothing to space.

Add the script to the <head>, then the two elements:

Check

What you learned

Try it yourself

  1. Number the article. Add data-numbered to the <article> and see what happens to the headings and the figure caption. No script is involved. Read the article element.
  2. Show reading progress. Add a <reading-progress> element and scroll. Read reading-progress, then decide whether it passes the step 4 test for your page.
  3. Keep the contents in view. Move <page-toc> out of the article into an <aside> beside it, so the current-section marker is visible while you read. Read the sidebar section of page-toc and data-sticky.
↑