> ## 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

```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;
}
```

## Arguments

**options** `SanitizeHtmlOptions` *required*

Configuration options for sanitization

**properties**

**options.html** `string` *required*

The HTML content to sanitize

**options.removeScripts** `boolean`

Remove all `<script>` elements. Defaults to true.

**options.removeStyles** `boolean`

Remove all `<style>` elements. Defaults to true.

**options.removeSvgs** `boolean`

Remove all `<svg>` elements. Defaults to true.

**options.removeComments** `boolean`

Remove HTML comments. Defaults to true.

**options.removeLongAttributes** `boolean`

Remove attributes longer than maxAttributeLength. Defaults to true.

**options.maxAttributeLength** `number`

Maximum length for attributes before removal. Defaults to 500.

**options.preserveAttributes** `Array\<string\>`

List of attribute names to always preserve. Defaults to \["class", "src"].

**options.removeEmptyTags** `boolean`

Remove empty tags (except preserved ones). Defaults to true.

**options.preserveEmptyTags** `Array\<string\>`

List of tag names to preserve even when empty. Defaults to \["img"].

**options.minifyWhitespace** `boolean`

Remove extra whitespace between tags and empty lines. Defaults to true.

## Returns: `string`

The sanitized HTML string


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.