Angular Component for highlighting the text in HTML

August 15, 2025 · View on GitHub

This package contains an Angular component to highlight one or many words in a given text.

Note that, this library supports any Angular projects from version 20 onwards till latest version.

This project is forked from ultrasonicsoft/ngx-highlight-text With the following differences:

  1. Compatible with modern angular, specifically standalone components
  2. Provides the functionality as a component instead of a pipe
  3. Allow application to highlight multiple terms
  4. Provide application with more styling options

The highlighting logic is unaltered from the original.

Install

You can get it on npm.

npm install ngx-highlight-text --save

Setup / Usage

  • Import HighlightComponent into any component that needs highlighting
import { HighlightComponent } from "ngx-highlight-text2";

@Component({
  template: `
    <h1 highlight content="Demo page" terms="m"></h1>
    <p highlight [content]="description" [terms]="blah"></p>       
    <p highlight [content]="d2" [terms]="['mom','dad']"></p>       
    `,
  imports: [
    HighlightComponent
  ]
})
export class MyComponent {
  description="blah blah blah";
  d2="hi mom, hi dad";
 }

Parameter

PropertyDescriptionTypeDefault
[content]the text to be highlightedstring
[terms]the term or terms to highlightstring or string[]
[hl-color-bg]the background color to highlight a termstringyellow
[hl-color-fg]the foreground color to highlight a termstringblack
[hl-style]the full css style to highlight a termstringfont-weight:bold
[hl-class]the name of css class to highlight a term (superceedes [hl-style])string
[match-all]if true match all instances within the content, otherwise just match the first onebooleantrue
[match-case]if true match case exactly, otherwise ignore casebooleanfalse

Example

screen shot of rendered components

License

MIT License © Balram Chavan