# no-unsafe-dom-html

Rule `unicorn/no-unsafe-dom-html`. Disallow unsafe DOM HTML APIs.

- Source: unicorn
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #2025 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/no-unsafe-dom-html` | no | no | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/no-unsafe-dom-html.md) |

## Code examples

### Incorrect: the rule reports this

```js
element.innerHTML = html;
element.outerHTML = html;
iframe.srcdoc = html;
element.insertAdjacentHTML('beforeend', html);
element.setHTMLUnsafe(html);
Document.parseHTMLUnsafe(html);
range.createContextualFragment(html);
iframe.setAttribute('srcdoc', html);
document.write(html);
document.writeln(html);
```

### Correct: the rule accepts this

```js
element.setHTML(html);
Document.parseHTML(html);
element.textContent = text;
element.insertAdjacentText('beforeend', text);
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/no-unsafe-dom-html": "error",
    },
  },
];
```

## Related rules

- [unicorn/no-unreadable-new-expression](https://lintradar.dev/rules/unicorn/no-unreadable-new-expression.md): Disallow unreadable `new` expressions.
- [unicorn/no-unnecessary-default-arguments](https://lintradar.dev/rules/unicorn/no-unnecessary-default-arguments.md): Disallow arguments that match their parameter defaults.
- [unicorn/no-unused-properties](https://lintradar.dev/rules/unicorn/no-unused-properties.md): Disallow unused object properties.
- [unicorn/prefer-dispose](https://lintradar.dev/rules/unicorn/prefer-dispose.md): Prefer using `using`/`await using` over manual `try`/`finally` resource disposal.
- [unicorn/no-repeated-call-wrappers](https://lintradar.dev/rules/unicorn/no-repeated-call-wrappers.md): Disallow repeating the same wrapper at every call to a function.
- [unicorn/prefer-error-is-error](https://lintradar.dev/rules/unicorn/prefer-error-is-error.md): Prefer `Error.isError()` when checking for errors.

---

Web page: https://lintradar.dev/rules/unicorn/no-unsafe-dom-html. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
