Hi, I'm Ishaan. I make Elsewhere, a reader that reads a book aloud and underlines each word as it is spoken. This post is about one decision the whole read-along rests on: the book's own markup is never changed to show where the voice is.
The obvious way, and why I dropped it
The obvious idea is to wrap each word in a span and swap a class on the current one. For a novel that is thousands of extra elements, and the book's own HTML is no longer the book's own HTML. A span can change line breaks, break a footnote link, or interfere with how the publisher styled a paragraph. And the word changes several times a second, so every change means touching the tree and hoping the layout holds still.
I wanted the text to stay exactly where the author's markup put it, so a line never jumps because a word got underlined.
Highlights that live outside the DOM
The CSS Custom Highlight API lets you register a Range and style it from CSS, with no element wrapped around it.…