Kuchikiki
An HTML tree-manipulation library for Rust with CSS-selector matching, a maintained fork of Kuchiki.
Repository Health
Technical Analysis
Kuchikiki (口利き) is an HTML tree-manipulation library for Rust. It parses HTML into an in-memory DOM you can traverse, query with CSS selectors, mutate, and serialize back to markup, built on top of the html5ever parser.
It is a maintained fork of the original, now-unmaintained Kuchiki (朽木) library, kept alive by the Brave project, which depends on it (notably in its SpeedReader). Migrating from Kuchiki is as simple as adding an extra ki to the crate name and re-mapping references.
What You Get
- An in-memory HTML DOM tree with reference-counted
NodeRefnodes - CSS-selector matching via
Selector,Selectors, and specificity handling - Node and element iterator adapters for traversal and filtering
- HTML parsing for full documents and fragments with configurable options
- Serialization back to HTML markup after in-place mutation
Common Use Cases
- Extracting and rewriting content in HTML documents (e.g. reader modes)
- Scraping data from HTML by matching CSS selectors
- Programmatically editing DOM structure and attributes in Rust
- Serving as a maintained drop-in replacement for the abandoned Kuchiki crate
Under The Hood
Architecture - The crate builds a tree of NodeRef handles (in tree.rs) using reference counting and interior mutability (cell_extras.rs) so nodes can be shared and mutated while retaining parent/child links. parser.rs wraps html5ever’s TendrilSink to produce the tree, select.rs compiles and evaluates CSS selectors against elements, iter.rs supplies traversal/filter adapters exposed through the traits module, and serializer.rs writes the tree back to HTML. The public API re-exports these pieces from lib.rs.
Tech Stack - Rust, built directly on html5ever for standards-compliant HTML parsing and tokenization, plus its tendril string type. The crate enforces #![deny(missing_docs)], so the entire public surface is documented.
Code Quality - Modules are cleanly separated by concern (parsing, tree, selection, iteration, serialization), an in-tree tests.rs plus test_data/ exercise behavior, and the project ships a CHANGELOG, security policy, and Renovate config. Active maintenance by Brave keeps it current where upstream Kuchiki stalled.
API Design - The API is idiomatic Rust: parse_html().one(html) yields a NodeRef, select("css") returns matching elements, and iterator traits make traversal composable. Migration from Kuchiki requires only a crate rename, lowering adoption cost for existing users.