Skip to main content
export declare function sanitizeHtml(options: SanitizeHtmlOptions): string;
Sanitizes and cleans HTML content by removing unwanted elements, attributes, and whitespace. Provides fine-grained control over each cleaning operation through configurable options.

Examples

import { sanitizeHtml } from "@intuned/browser";
export default async function handler(params, page, context){
const dirtyHtml = `
  <div>
    <script>alert('xss')</script>
    <p style="color: red;">Hello World</p>
    <span></span>
  </div>
`;
const sanitizedHtml = sanitizeHtml({ html: dirtyHtml });
// Returns: '<div><p>Hello World</p></div>'
}

Arguments

options
SanitizeHtmlOptions
required
Configuration options for sanitization

Returns: string

The sanitized HTML string