Carets and highlights in a canvas
An editable block drawn by a canvas. The browser draws the CSS caret into the picture. The canvas adds a streak behind it and wavy lines under misspelled words. Tap a marked word to correct it.
Show the code caret and highlights
- An editable element inside
<selection-fx>.highlight="typo"names the CSS Custom Highlight whose ranges are measured. - The caret is CSS.
caret-shape,caret-colorandcaret-animation. - Mark the misspelled words with a Highlight that has no style. The canvas draws the wavy line.
- Find the marked word under a tap with
CSS.highlights.highlightsFromPoint(). - Inside the element: where the caret is. A collapsed
Rangehas one client rectangle. - The 2D effect. A quad from the old caret position to the new one, and a sine line under each marked rectangle.
- The shader effect. It is given no positions. It looks for the key colour in the element's picture.
- The whole element.
Two things only a person can check
The test browser has no find bar and no spelling dictionary. On this page find-in-page matches are styled green (::search-text) and spelling marks yellow (::spelling-error).
Open find-in-page, search for caret, and press the button. It reads the canvas back and counts pixels of each colour. Zero while you can see the marks means the browser draws them over the page and leaves them out of the element's picture.
What this browser has
Live checks
These start when you press the button. They use fixtures in a corner of the window and don't take focus, so the checks on the caret itself are the numbers under the editor.
Findings
Measured in headless Chromium 157 on Linux with a software renderer, 2026-11-21.
- The caret is in the element's picture, with its
caret-colorandcaret-shape. The line under the editor counts its pixels in the canvas each time it moves. caret-animation: manualstops the repaints. A blinking caret firespainttwice a second, and a shader effect uploads the element's texture each time. Withmanualthe canvas is repainted only when the caret moves.- The caret's position comes from a collapsed
Range.getClientRects()returns one rectangle of zero width at the caret, at the drawn position. On an empty line it returns nothing, so the streak skips that move. CSS.highlights.highlightsFromPoint(x, y)answers at the drawn position. It returns the Highlight and the range under the point, so a word that is only marked by a range can be tapped. No element wraps the word.- A shader can find the caret without being told where it is. The key-glow effect has no rectangles. It samples the element's picture for the key colour, which the caret and the
::highlight()underline both use. This also works for anything else painted in that colour, wanted or not. ::highlight(*)isn't in Chromium 157 (it is listed for 158), so each named Highlight still needs its own rule.- The marks are redrawn from ranges, so they survive editing. The typo list runs again on every
inputevent and replaces the Highlight. A correction replaces the range's text withRange.deleteContents()andinsertNode().
Not built or not verified:
- Find-in-page and spelling marks in the picture: not verified here, see the button above.
- The Proofreader API (origin trial) isn't in the test browser. The typo list on this page stands in for it. The table above says whether your browser has it.
- Typing on an Android keyboard, with composition and autocorrect, wasn't tested.
- Not built: the editor on a 3D monitor (the 3D form has the surface), and a second editor using
EditContextwith the canvas drawing all the text.