Vanilla Breeze

highlight-wc

Medium-style text highlighting and annotation component with color swatches, private notes, and localStorage persistence.

Overview

The <highlight-wc> component enables Medium-style text selection highlighting on any content. Users can select text, choose a highlight color, add private notes, and all annotations persist in localStorage.

It wraps the data-highlights attribute system in a convenient web component interface.

Attributes

AttributeTypeDefaultDescription
for string ID of an external element to annotate. When set, the component is invisible and targets the referenced element.
colors comma-separated yellow,green,blue,pink Available highlight colors
readonly boolean Render stored highlights but disable creating new ones
storage-key string pathname Custom localStorage key suffix

Demo

Select any text in the article below to highlight it. Choose a color from the toolbar, add a private note, or click an existing highlight to modify it.

Wrapping Content

Wrap any content to enable highlighting on the first child element.

Targeting by ID

Use for to annotate an element elsewhere on the page. The component itself renders as invisible.

Custom Colors

Define color values with CSS custom properties on :root:

JavaScript API

The component exposes methods that delegate to the internal HighlightController:

Accessibility

  • Toolbar uses role="toolbar" with arrow-key navigation
  • Screen reader announcements for highlight add/remove actions
  • Escape closes toolbar, Ctrl+Enter saves notes
  • Note panel uses role="dialog"

Related