custom-highlight

A set of lifecycle hooks for styling arbitrary text within elements using the CSS Custom Highlight API
5,170 2
Install
npm install custom-highlight
Latest Version:1.0.2
Vue:3
License:MIT
Last Updated:Jul 1, 2026
Links: GitHub  ·  npm
Maintainer: roydukkey

custom-highlight

A set of lifecycle hooks for styling arbitrary text within elements using the CSS Custom Highlight API.

Release Version License

Features

  • Highlight single or multiple tokens within an element, or patterns using a regular expression
  • Easily configure case-insensitive searching for tokens and patterns
  • Define custom highlight groups for targeting each with unique styles
  • Deeply monitor changes to character data triggering an update to highlights

Install

npm install custom-highlight

CDN

<script src="https://unpkg.com/custom-highlight"></script>
<script src="https://cdn.jsdelivr.net/npm/custom-highlight"></script>

It will be exposed globally as window.CustomHighlight.

Usage

Here is a very basic example that will highlight the words “brown fox” in the paragraph.

<p id="gettingStarted">The quick brown fox jumps over the lazy dog.</p>

<script type="module">
import CustomHighlight from 'custom-highlight';

const element = document.getElementById('gettingStarted');
const options = { value: 'brown fox' };

if (element) {
  CustomHighlight
    .created(element, options)
    .beforeMount(element, options)
    .mounted(element, options);
}
</script>

<style>
  ::highlight(default) {
    background-color: yellow;
    color: black;
  }
</style>

This works just fine in a static webpage, but frameworks that dynamically render content by manipulating the DOM (e.g. Vue, React, Svelte, etc.) will require additional effort in conforming to their component lifecycles.

See the docs for examples and recipes using Vue and native Web Components.

Related Packages

vue3-highlight-text

a vue3 directive of highlight text

84,789
vue-proportion-directive

vue 固定元素比例指令

6,003 10
@hxui/css

Helix User Interface Library - Pure CSS Framework

5,196
ardirectives

Ardirectives

811
@verstaerker/vue-bem

A Vue.js directive and mixin to create BEM class names.

430 9

Version History

Version Released Vue License
1.0.2 ^3.5.25 MIT
1.0.1 ^3.5.13 MIT