react-highlight-words

A React component that highlights matching search terms within a body of text

Library
npm
v0.21.0
2,304 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
43 /100 Fair
Development Activity 0
Maintenance 20
Community 52
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
73 /100 Good
Architecture 70
Code Quality 72
Innovation 60
Learning Curve 90

react-highlight-words renders a body of text with an array of search words wrapped in a highlight element, defaulting to the semantic <mark> tag but swappable for any custom React component. It’s built as a thin, focused wrapper around highlight-words-core, the same author’s underlying matching logic, so string search terms are automatically converted to case-insensitive regexes (with optional auto-escaping) without requiring the consumer to hand-write matching code.

The component exposes granular styling and behavior props — separate class names and inline styles for highlighted vs. unhighlighted text, an activeIndex/activeClassName pair for marking one match as currently selected, and a sanitize hook for normalizing text (e.g. stripping accents) before comparison — making it a common building block for search-result snippets, autocomplete dropdowns, and in-page find UIs.

What You Get

  • A <Highlighter searchWords={[...]} textToHighlight={...} /> component that wraps all matches in a <mark> (or custom tag)
  • Automatic conversion of string search terms into regexes, with autoEscape to safely handle special characters
  • Separate styling hooks for highlighted vs. unhighlighted text (highlightClassName/highlightStyle, unhighlightClassName/unhighlightStyle)
  • An activeIndex/activeClassName/activeStyle trio for marking one specific match as the currently selected result
  • A sanitize prop for normalizing text before comparison (e.g. accent stripping) without altering the displayed text
  • Support for custom highlightTag/unhighlightTag React components instead of the default mark/span elements

Common Use Cases

  • Highlighting the matched query term(s) inside search result snippets in a React app
  • Building autocomplete or typeahead dropdowns that show which part of each suggestion matched the user’s input
  • Implementing an in-page “find in text” feature with a currently-active match indicator
  • Highlighting multiple distinct terms (e.g. tags or keywords) within displayed content simultaneously
  • Normalizing accented or differently-cased text before matching, via the sanitize prop, while preserving original display text

Under The Hood

Architecture: The published component is a thin ~120-line wrapper (src/Highlighter.js) around chunk-finding logic delegated to the sibling highlight-words-core package (also maintained by the author), which computes match/no-match text chunks; Highlighter.js then maps those chunks to React elements, applying the configured highlight/unhighlight tags, classes, and styles, with activeIndex handled as a simple chunk-index comparison during the render pass. Tech Stack: Plain JavaScript (no TypeScript) built with Webpack across several purpose-specific configs (dist.cjs, dist.umd, website, dev) to produce both a CommonJS distribution and a UMD bundle, tested via Karma rather than Jest, and linted with standard (zero-config ESLint preset) run as a prebuild step. Code Quality: The core logic is covered by a single, fairly thorough Highlighter.test.js exercising the main prop combinations, plus a documented CodeSandbox example for custom findChunks usage; the project has had minimal commit activity since its early releases, so its small, stable surface area has changed little in practice. API Design: The prop table is exhaustive and self-documenting in the README — every visual and behavioral variation (active match, custom tags, sanitize hook) is exposed as a discrete, independently optional prop, which keeps the common case (searchWords + textToHighlight) to two lines while still supporting advanced customization.

Used by 9 apps in this directory

TypeScript
72%
AGPL 3.0

APITable

Databases · Low Code Platforms

15,623

API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.

View details
71
Repo Health
77
Technical
60
Dependency
Built with
TypeScript 72%
Java 22%
Updated 1 months ago
JavaScript
95%
MIT

AnythingLLM

AI Assistants · Automation · Developer Tools

66,533

The all-in-one AI platform for private document chat, no-code agents, and local LLMs with zero setup friction.

View details
90
Repo Health
78
Technical
64
Dependency
Built with
JavaScript 95%
Updated 1 weeks ago
TypeScript
88%
MIT

DevTools-X

Developer Tools

1,534

41 offline-first developer utilities in a single 10MB cross-platform desktop app — no Electron, no cloud, no compromise.

View details
49
Repo Health
68
Technical
68
Dependency
Built with
TypeScript 88%
Updated 4 months ago
TypeScript
100%
Other

Dub

Analytics · Marketing

24,835

The open-source link attribution platform for short links, conversion tracking, and affiliate programs — powering 100M+ clicks monthly.

View details
81
Repo Health
78
Technical
62
Dependency
Built with
TypeScript 100%
Updated 1 weeks ago
TypeScript
48%
AGPL 3.0

Grafana

Analytics · Monitoring

76,962

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
63
Dependency
Built with
TypeScript 48%
Go 46%
Updated 1 weeks ago
TypeScript
71%
Other

highlight.io

Analytics · Developer Tools · Monitoring

9,378

Open-source full-stack monitoring that unifies session replay, error tracking, logging, and distributed tracing so you can stop context-switching between tools.

View details
67
Repo Health
78
Technical
65
Dependency
Built with
TypeScript 71%
Go 16%
Updated 1 months ago
TypeScript
99%
MIT

GraphQL Hive

Developer Tools · Devops · Monitoring

484

Open-source GraphQL schema registry and observability platform with breaking change detection, federation support, and CI/CD integration for teams of any size.

View details
90
Repo Health
81
Technical
69
Dependency
Built with
TypeScript 99%
Updated 1 weeks ago
Rust
72%
Apache 2.0

Rivet

AI Agents · Developer Tools

6,195

Stateful actors as a primitive for AI agents, real-time collaboration, and durable execution — with in-memory state, WebSockets, queues, and scheduling built in.

View details
86
Repo Health
81
Technical
64
Dependency
Built with
Rust 72%
TypeScript 25%
Updated 1 weeks ago
JavaScript
57%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,007

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
JavaScript 57%
TypeScript 36%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers