Skip to content

stripHTML ​

Removes all HTML tags from a string, returning only the plain text.

Syntax ​

typescript
stripHTML(html: string): string

Parameters ​

ParameterTypeDescription
htmlstringThe string containing HTML to be cleaned.

Returns ​

TypeDescription
stringThe string without HTML tags.

Example ​

typescript
stripHTML("<p>Olá <b>mundo</b>!</p>"); // "Olá mundo!"
stripHTML("<div><span>Texto</span></div>"); // "Texto"
stripHTML(""); // ""

Notes ​

  • Throws TypeError if the argument is not a string.
  • Removes all HTML tags, but does not perform full sanitization for XSS.

References ​

Released under the MIT License.