Inline text elements: sub, bdo, abbr, q, var and br

Six ideas from the element catalogue about elements that sit inside a line of text. None of them is a drawable element: each is part of the picture of the paragraph around it. I wanted to know how much a canvas can do with them from their rectangles alone, and what it can do for the one that has no width, <br>.

Subscripts that settle

Chemical formulas and one equation. The line is drawn with a hole at every <sub> and <sup>. Each subscript then drops into its hole from above and each superscript rises into it from below, one after another.

Water is H2O and glucose is C6H12O6.

CO2 + H2O gives H2CO3.

E = mc2, a2 + b2 = c2. More

A <sub> isn't drawable by itself, but it has a box. Clipping a second draw of the paragraph to that box gives the same thing as a picture of the subscript, as long as nothing else is inside the box.

Show the code
  1. One drawable sheet. The subscripts are ordinary inline elements.
  2. Draw the sheet with holes, then each piece on its way to its hole.
  3. Place the sheet, and draw one box of it somewhere else.
  4. Styles.

Bidirectional text explained

Three lines. The small numbers over a run are the positions of its characters in the source text, and the arrow goes from the first character to the last. In the Hebrew word and in the run that <bdo dir="rtl"> turns round, the numbers count down along the line.

Left to right

שלום עולם is hello world

Forced the other way

The numbers and arrows are canvas drawing, not text. Each is placed from a Range rectangle of one character, and those rectangles are reported at the place where the sheet was last drawn.

Show the code
  1. The three runs.
  2. One Range per character, a number over each, an arrow over the run.

Abbreviations expanded in place

Tap an abbreviation with a dotted line under it. The paragraph is cut under that line, the lower piece moves down, and the abbreviation's title is drawn in the gap. Tap it again, or tap another.

A page is written in and styled with . A script reaches it through the , which is one among many. Pictures can be .

The browser's own tooltip for title isn't in the element's picture and doesn't appear on a touch screen. Once the paragraph is drawn in two pieces at two places it has no single hit region that fits, so the canvas finds the tapped abbreviation from the tap's position and the boxes of the abbreviations.

Show the code
  1. The paragraph, and one element that holds the open title.
  2. Cut the paragraph, draw the title in the gap, and find the tapped abbreviation.

Quotation marks as ornaments

Two <q> elements and a <cite>. The canvas draws a band behind each line of a quotation, a large mark where it starts and where it ends, and a wave under the title of the work. The text itself is unchanged and can be selected.

The tide table says high water at four, and again a little before five in the afternoon, which the harbour master reads as stay in. Both lines are from Notes for Small Boats.

A <q> has a rectangle for the opening mark the browser adds, one for each line of its text, and one for the closing mark. The large marks are centred on the first and the last of them.

Show the code
  1. The paragraph.
  2. Draw the bands, the marks and the wave, then the text over them.

Variables that light up together

A sentence and the code that goes with it. Tap a variable, or move a mouse over one: every <var> with the same name is outlined, in the sentence and in the code, and a dashed line joins them in order.

Add n numbers into sum, then divide sum by n to get mean.

let sum = 0;
for (const x of list) sum += x;
const n = list.length;
const mean = sum / n;

The tap is an ordinary click on the <var>: the sheet is drawn flat, so its hit region fits. Only the outlines and the line are canvas drawing.

Show the code
  1. The sentence and the code.
  2. Outline every <var> with the picked name.

Line breaks as cut lines

A note with a <br> at the end of each line. The dashed lines are where the canvas will cut. Press the button: the note folds along them like a paper fan, and unfolds again.

Back at six.
Soup is on the stove.
Feed the cat, not the dog.
The key is under the pot.
Do not wait up.
Love, M.

The cut lines aren't taken from the <br> elements, which are 0 px wide. They're the tops of the text between two breaks, read with a Range while the note is flat.

Show the code
  1. One paragraph with five <br> elements.
  2. Read the lines, then draw the paragraph as folded strips.

How it works

Show the code
  1. Place a sheet, turn a client rectangle into sheet pixels, draw one piece.
  2. Each demo starts when its section comes near the screen.
  3. The paint handler shared by the six canvases.
  4. After a lost context the text is shown as plain HTML.

Live checks

The checks wait for a tap. Each builds its own small canvas in a corner of the window, and none of them touches the demos above.

Findings

Measured in headless Chromium 157 on 2026-11-21. Not yet run on a phone.