sanitize-html
It is well suited for cleaning up HTML fragments such as those created by CKEditor and other rich text editors.
Official Documentation ↗v2.0. Check the official docs for the latest API surface.Installation
npm install sanitize-htmlpnpm add sanitize-htmlyarn add sanitize-htmlMethods
No methods match this filter.
Overview
It is well suited for cleaning up HTML fragments such as those created by CKEditor and other rich text editors. It is especially handy for removing unwanted CSS when copying and pasting from Word.
API reference status
This page lists only entry points that appear verbatim in the official README examples: sanitizeHtml, alert. Parameter and return types are not given by the official README, so signatures are marked unverified.
Errors
The following points are quoted verbatim from the official documentation (https://github.com/apostrophecms/sanitize-html). Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- This situation often arises when SVGs fail to display correctly because their case-sensitive tags, such as linearGradient and attributes like viewBox, are inadvertently lowercased. (https://github.com/apostrophecms/sanitize-html)
- The content still gets escaped properly, with the exception of the script and style tags. (https://github.com/apostrophecms/sanitize-html)
- When you disable parsing of the style attribute (parseStyleAttributes: false) and you pass in options for the allowedStyles property, an error will be thrown. (https://github.com/apostrophecms/sanitize-html)
Security notes
Quoted from the official documentation (https://github.com/apostrophecms/sanitize-html); this is not a complete threat model.
- Additionally, sanitize-html escapes ALL text content - this means that ampersands, greater-than, and less-than signs are converted to their equivalent HTML character references (& –> &, <, and so on). (https://github.com/apostrophecms/sanitize-html)
- Requirements sanitize-html is intended for use with Node.js and supports Node 10+. (https://github.com/apostrophecms/sanitize-html)
- Regarding TypeScript sanitize-html is not written in TypeScript and there is no plan to directly support it. (https://github.com/apostrophecms/sanitize-html)
Verification notes
- Official source: https://github.com/apostrophecms/sanitize-html
- Evidence: https://cdn.jsdelivr.net/gh/apostrophecms/sanitize-html@latest/README.md
- Checked on 2026-11-04 by
scripts/phase11/build-api-profiles.mjs
FAQ
- What does sanitize-html do?
- It is well suited for cleaning up HTML fragments such as those created by CKEditor and other rich text editors.
- How do I install sanitize-html?
- Run `npm install sanitize-html`.
- Where can I verify the API details?
- Official repository/documentation: https://github.com/apostrophecms/sanitize-html. Checked on 2026-11-04; signatures and return values not stated in the official README are marked unverified.
Report a problem with this API docOpens a pre-filled issue on GitHub.