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.
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
- One
drawablesheet. The subscripts are ordinary inline elements. - Draw the sheet with holes, then each piece on its way to its hole.
- Place the sheet, and draw one box of it somewhere else.
- 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.
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
- The three runs.
- One
Rangeper 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.
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
- The paragraph, and one element that holds the open title.
- 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.
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
- The paragraph.
- 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.
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
- The sentence and the code.
- 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.
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
- One paragraph with five
<br>elements. - Read the lines, then draw the paragraph as folded strips.
How it works
- One drawable block per canvas. The inline elements aren't
drawable. A piece of the block is drawn by clipping a draw of the whole block to a box. - Two kinds of box.
offsetLeft,offsetTop,offsetWidthandoffsetHeightare layout numbers and don't change with how the block is drawn. The demos that move pieces use them.getClientRects()of an element or aRangegives one rectangle per line, at the place where the block was last drawn. The demos that draw the block flat use those. - Frames. A demo asks for frames only while something moves. The demos that read client rectangles draw their first frames twice, because the rectangles follow the draw before.
Show the code
- Place a sheet, turn a client rectangle into sheet pixels, draw one piece.
- Each demo starts when its section comes near the screen.
- The paint handler shared by the six canvases.
- 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.
- Inline elements can be treated as pictures by clipping.
sub,sup,abbr,qandvarhave boxes inside a drawable block (asubwas 7 by 15 px in the check), and a draw of the block clipped to one box moves that element alone. Twelve subscripts and superscripts were dropped into place this way. - There are two kinds of box, and they behave differently. Client rectangles follow the draw: the rectangle of a
varmoved by 60 and 30 px when its block was drawn at (60, 30).offsetLeftandoffsetTopstayed at 35 and 3. A demo that moves pieces uses the offset numbers. A demo that draws the block flat can use either. - A block drawn in two pieces reports rectangles for the last piece only. With the abbreviation's paragraph cut and its lower piece drawn 42 px down, every client rectangle in the paragraph was 42 px down, the ones above the cut too. The canvas finds the tapped abbreviation from the tap's position and the offset boxes.
- A
brhas one client rectangle, 0 px wide. Awbrhas none. The fold lines come from aRangeover the text between two breaks: tops 24 px apart for a 24 px line height. - A
qhas more rectangles than lines. One for the opening mark the browser adds, one for each line of text and one for the closing mark: 3 for a one-lineq, 5 for one that wraps once, 8 for the two in the demo. - Character rectangles show visual order. In
<bdo dir="rtl">the last of six letters was 35.5 px to the left of the first. In a plain span it was 37.3 px to the right. The Hebrew run of 9 characters and the forced run of 20 were both reported right to left. - The
titleof anabbrisn't in the picture. The block was 220 by 24 px with and without it. The demo draws the title from a real element in a gap it opens in the paragraph, and the abbreviations answer to touch and to Enter. - Not verified: everything on a phone. Whether Android shows the
titletooltip on a long press over a drawn abbreviation, text selection across the ornaments by touch, and Arabic or mixed-direction runs, which this page doesn't have.