> ## Documentation Index
> Fetch the complete documentation index at: https://intunedhq.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# sanitizeHtml

Sanitizes and cleans HTML content by removing unwanted elements, attributes, and whitespace.
Provides fine-grained control over each cleaning operation through configurable options.

```typescript theme={null}
export declare function sanitizeHtml(options: SanitizeHtmlOptions): string;
```

## Examples

<CodeGroup>
  ```typescript Basic Sanitization theme={null}
  import { BrowserContext, Page } from "playwright";
  import { sanitizeHtml } from "@intuned/browser";

  interface Params {}

  export default async function handler(
    params: Params,
    page: Page,
    context: BrowserContext
  ) {
    await page.goto("https://books.toscrape.com");
    const firstRow = page.locator("ol.row").locator("li").first();
    // Get the HTML of the first row.
    const html = await firstRow.innerHTML();
    // Sanitize the HTML.
    const sanitizedHtml = sanitizeHtml({ html });
    // Log the sanitized HTML.
    console.log(sanitizedHtml);
    // Return the sanitized HTML.
    return sanitizedHtml;
  }
  ```
</CodeGroup>

## Arguments

<ResponseField name="options" type="SanitizeHtmlOptions" required>
  Configuration options for sanitization

  <Expandable title="properties" defaultOpen>
    <ResponseField name="options.html" type="string" required>
      The HTML content to sanitize
    </ResponseField>

    <ResponseField name="options.removeScripts" type="boolean">
      Remove all `<script>` elements. Defaults to true.
    </ResponseField>

    <ResponseField name="options.removeStyles" type="boolean">
      Remove all `<style>` elements. Defaults to true.
    </ResponseField>

    <ResponseField name="options.removeSvgs" type="boolean">
      Remove all `<svg>` elements. Defaults to true.
    </ResponseField>

    <ResponseField name="options.removeComments" type="boolean">
      Remove HTML comments. Defaults to true.
    </ResponseField>

    <ResponseField name="options.removeLongAttributes" type="boolean">
      Remove attributes longer than maxAttributeLength. Defaults to true.
    </ResponseField>

    <ResponseField name="options.maxAttributeLength" type="number">
      Maximum length for attributes before removal. Defaults to 500.
    </ResponseField>

    <ResponseField name="options.preserveAttributes" type="Array<string>">
      List of attribute names to always preserve. Defaults to \["class", "src"].
    </ResponseField>

    <ResponseField name="options.removeEmptyTags" type="boolean">
      Remove empty tags (except preserved ones). Defaults to true.
    </ResponseField>

    <ResponseField name="options.preserveEmptyTags" type="Array<string>">
      List of tag names to preserve even when empty. Defaults to \["img"].
    </ResponseField>

    <ResponseField name="options.minifyWhitespace" type="boolean">
      Remove extra whitespace between tags and empty lines. Defaults to true.
    </ResponseField>
  </Expandable>
</ResponseField>

## Returns: `string`

The sanitized HTML string
