# @litejs/dom

> A small DOM library for server-side testing, rendering, and handling of HTML files

Latest version **26.4.3** (published 2026-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install @litejs/dom
pnpm add @litejs/dom
yarn add @litejs/dom
bun add @litejs/dom
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; no vulnerabilities; has provenance; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 26.4.3 |
| Published | 2026-04-09 |
| First published | 2023-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 45.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 27 |
| Author | Lauri Rooden |
| Maintainers | lauriro |
| Keywords | document, DOM, HTML, DOMParser, CSSOM, CSSStyleSheet, XMLHttpRequest, XMLSerializer, litejs |

## Links

- npm: https://www.npmjs.com/package/@litejs/dom
- Repository: https://github.com/litejs/dom
- Homepage: https://github.com/litejs/dom#readme
- Issues: https://github.com/litejs/dom/issues
- npm.io page: https://npm.io/package/@litejs/dom

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 26.4.3 (latest) — 2026-04-09
- 26.4.2 — 2026-04-08
- 26.4.1 — 2026-04-08
- 26.4.0 — 2026-04-02
- 26.3.0 — 2026-03-27
- 26.2.0 — 2026-02-20
- 25.12.0 — 2025-12-17
- 25.9.2 — 2025-09-08
- 25.9.1 — 2025-09-08
- 25.9.0 — 2025-09-08
- 25.6.0 — 2025-06-09
- 25.5.0 — 2025-05-11
- 25.1.0 — 2025-01-11
- 24.12.0 — 2024-12-09
- 24.8.0 — 2024-08-30
- … 11 more at https://npm.io/package/@litejs/dom/versions

## README

[1]: https://badgen.net/coveralls/c/github/litejs/dom
[2]: https://coveralls.io/r/litejs/dom
[3]: https://packagephobia.now.sh/badge?p=@litejs/dom
[4]: https://packagephobia.now.sh/result?p=@litejs/dom
[5]: https://badgen.net/badge/icon/Buy%20Me%20A%20Tea/orange?icon=kofi&label
[6]: https://www.buymeacoffee.com/lauriro


LiteJS DOM &ndash; [![Coverage][1]][2] [![Size][3]][4] [![Buy Me A Tea][5]][6]
==========

Dependency-free DOM library for handling HTML, XML and CSS files on server-side.


```javascript
// const { document } = require("@litejs/dom");
import { document, CSSStyleSheet, DOMParser, XMLSerializer } from "@litejs/dom";
import { XMLHttpRequest } from "@litejs/dom/net.js";

// Build DOM manually
const el = document.createElement("h1");
el.id = 123;
el.className = "large";

const fragment = document.createDocumentFragment();
fragment.appendChild(document.createTextNode("hello"));
el.appendChild(fragment);

// Replace the DOM tree with HTML
el.innerHTML = "<b>hello world</b>";
console.log(el.toString());
// <h1 id="123" class="large"><b>hello world</b></h1>

// Minify HTML
console.log(el.toString(true));
// <h1 id=123 class=large><b>hello world</b></h1>

el.querySelectorAll("b");
// [ "<b>hello world</b>" ]

// Use XMLHttpRequest in server side
const xhr = new XMLHttpRequest();
xhr.open("GET", "https://litejs.com");
xhr.responseType = "document";
xhr.onload = function() {
	const doc = xhr.responseXML;
	// Work with DOM in familiar way
	console.log(doc.querySelector("title").textContent);
}
xhr.send();

// Minify CSS
import { CSS } from "@litejs/dom/css.js";
const sheet = new CSSStyleSheet()
sheet.replaceSync(":root{--gap:10px} .a { color: hsl(0 0% 100%); top: calc(var(--gap) + 5px) }")
console.log(CSS.minify(sheet, { var: true, calc: true, color: true }))
// .a{color:#fff;top:15px}
```

### CSS.minify options

- **calc** &ndash; resolve static `calc()` expressions, e.g. `calc(10px + 5px)` &rarr; `15px`
- **color** &ndash; shorten `rgb()`/`hsl()` to hex, e.g. `rgb(255,0,0)` &rarr; `#f00`
- **import** &ndash; inline `@import` rules, rewriting relative URLs
- **prefix** &ndash; add vendor prefixes, e.g. `{ "mask-image": ["-webkit-"] }`
- **prune** &ndash; remove unused selectors `{ keep: Set, keepRe: RegExp }`
- **root** &ndash; base directory for resolving `@import` paths
- **url** &ndash; URL rewrite callback `(path) => newPath`
- **var** &ndash; inline CSS custom properties from `:root`

## Contributing

Follow [Coding Style Guide](https://github.com/litejs/litejs/wiki/Style-Guide),
run tests `npm install; npm test`.


> Copyright (c) 2014-2026 Lauri Rooden &lt;lauri@rooden.ee&gt;  
[MIT License](https://litejs.com/MIT-LICENSE.txt) |
[GitHub repo](https://github.com/litejs/dom) |
[npm package](https://npmjs.org/package/@litejs/dom) |
[Buy Me A Tea][6]

---
_Source: https://npm.io/package/@litejs/dom · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
