Skip to content

The parsing foundation for the web.

Parsec reads HTML, CSS, JavaScript, XML, URLs and text encodings the way the standards say a browser should, and hands you the tree. It's written in Rust, split into crates you take one at a time, and it runs from Python, JavaScript and C as well.

Version 0.3.1, Apache-2.0.

What you wrote

<title>Shop</title>
<p class=lead>Hello <b>world</p>
<p>again

What Parsec built

<html>
  <head>
    <title>
      "Shop"
    "\n"
  <body>
    <p class="lead">
      "Hello "
      <b>
        "world"
    <b>
      "\n"
      <p>
        "again"

What it noticed on the way

  • 1:1 expected-doctype-but-got-start-tag
  • 2:29 unexpected-end-tag
  • 3:9 expected-closing-tag-but-got-eof
Parsed by parsec-web 0.3.1 when this page was built. Nobody closed the <b>, so it carries into the next paragraph, exactly as it does in every browser.

Six parsers, each in its own crate

Want CSS but not HTML? Take parsec-web-css with its default features off and you won't compile an HTML tokenizer. Every number below is what Parsec's CI requires on its main branch today, read from the baseline when this page was built.

ParsesWhat you getCrateChecked against
HTMLThe HTML Standard’s tokenizer and tree builder, CSS selectors, XPath 1.0, serializing and editing the tree.parsec-web-corehtml5lib tree construction: 3,898 pass, none fail
CSSTokenizing and parsing stylesheets, typed values for every property, media queries and the cascade.parsec-web-cssweb-platform-tests CSS parsing: 14,758 pass, 135 don't yet
JavaScriptECMAScript 2025 scripts and modules to a tree with spans, ESTree JSON, scopes, and page state read without running anything.parsec-jstest262, parsing: 52,782 pass, none fail
XMLXML 1.0 with namespaces, not validating, with a span on every node and XPath over the result.parsec-xmlW3C XML conformance: 1,915 pass, none fail
URLThe WHATWG URL Standard: parsing, setters, origins and IDNA, as browsers resolve links.parsec-urlweb-platform-tests URL parsing: 904 pass, none fail
EncodingFinding a page’s encoding the way a browser does, and decoding it, from whole bytes or a stream.parsec-web-encodingweb-platform-tests legacy multi-byte: 62,352 pass, none fail

Fast is a result. The numbers are how you check it.

Standards

679,730 tests pass across 35 conformance suites, from html5lib and test262 to the web-platform-tests. 30 of those suites pass every test they run. The 5 that don't are still in the baseline, so a regression fails CI and a fix has to raise the count:

  • css-parsing-tests: 3,270 of 8,366
  • html5lib-tree-construction-error-counts: 165 of 1,967
  • wpt-cascade: 131 of 1,474
  • wpt-computed-values: 755 of 12,111
  • wpt-css-parsing: 135 of 14,893

Speed

Parsing 13 real pages, 24.36 MB
370 MB/s, against 242 for Lexbor's C and 82 for html5ever, 1.53 times Lexbor's speed
32 CSS selectors over those pages
226 ms in all, where Lexbor takes 728
JavaScript, 11.58 MB of bundles and inline scripts
380 MB/s, against 363 for oxc and 147 for swc; oxc is still ahead on the smallest inline scripts

One machine's numbers: an Apple M2 Max (12 cores, 32 GB), macOS 26.7, on 15 November 2026 for HTML and selectors and 28 November 2026 for JavaScript. The Benchmarks page has every row, the corpus and the commands to run it yourself in about five minutes.

Separate trees, shared plumbing

HTML and XML look alike and parse nothing alike, so they don't share a tree builder. Each language keeps its own grammar, its own tree and its own error handling. What they share is small: spans, line indexes, diagnostics and limits, in a crate that depends on nothing. CI checks that every crate reaches only what's in its row here, and fails the build when one doesn't.

CrateForReaches
parsec-basespans, line indexes, diagnostics and limitsnothing at all
parsec-web-corethe HTML parser and its treeno other Parsec crate
parsec-urlURLsno other Parsec crate
parsec-jsJavaScriptparsec-base
parsec-xmlXMLparsec-base, and parsec-xpath with the xpath feature
parsec-xpathXPath 1.0parsec-web-core with the html feature
parsec-web-cssCSSparsec-web-core with the cascade feature
parsec-web-encodingencodingsparsec-web-core with the parse feature
parsec-webthe one most people installcore, CSS, encoding, URL and XPath together

Tested against the web, not only the specs

Spec suites tell you a parser is right by the standard. They can't tell you it survives the pages people actually crawl. That's what Netweir is for. It's the crawling and extraction framework the HTML parser was first written for, and it now builds on Parsec's crates from crates.io like anyone else.

Every Monday, Netweir's CI fetches 300 pages from a pinned list of 2,709 production URLs, a different slice each week, and parses each one with Parsec and with html5ever. If Parsec panics, hangs, or builds a tree html5ever disagrees with, the run fails. The list mixes the top sites' home pages with Wikipedia in 33 languages, docs, news, forums, shops, government sites and pages in legacy encodings.

Add it in one line

The crate is parsec-web and the library inside it is parsec, so Rust code says use parsec::…. In Python the module is parsec_html.

main.rs
let doc = parsec::parse("<title>Shop</title><p>Hello", false);
assert_eq!(
    doc.inner_html(doc.root()),
    "<html><head><title>Shop</title></head><body><p>Hello</p></body></html>"
);

No <html>, no <body>, an unclosed <p>. Parsec fixes all three the way a browser would, because the HTML Standard says how to recover from every mistake and it follows that. The getting started guide goes from here to selectors, edits and writing the page back out.

Build on it, or help build it

Found a page Parsec gets wrong? That's the most useful thing you can send me, along with a benchmark run on your own machine or a fix for a test that doesn't pass yet.