Stage 01 · Write · Researched comparison
Best Ruby HTML Parsers in 2026
Nokogiri is the default pick for most Ruby teams. It wraps libxml2 and libgumbo, handles broken markup, and supports CSS and XPath queries. Nokolexbor is a faster drop-in replacement when you need Lexbor speed and can accept its narrower feature set. Loofah is the right choice when the job is sanitizing untrusted HTML rather than general parsing. All are open source and free to use.
By Shihab Mia
Published 27 Nov 2026 · 5 tools compared
We run no ads and no affiliate links at launch. The order of a list follows our published method. See how we score.
Prices are the starting prices vendors list publicly. Plans change, so confirm the current price on the vendor page before you buy.
Key takeaways
- Nokogiri is the most widely used Ruby HTML parser and covers parsing, CSS selectors, XPath and XML.
- Nokolexbor swaps in the Lexbor engine for speed and aims for Nokogiri API compatibility.
- Loofah and Rails HTML Sanitizer focus on cleaning untrusted HTML, not general-purpose parsing.
- Ox is a fast XML parser with limited HTML support; use it for XML-heavy work.
Who each pick is for
- General HTML and XML parsing in RubyNokogiri
- Fast HTML parsing with a Nokogiri-like APINokolexbor
- Sanitizing untrusted HTML safelyLoofah
- Sanitizing HTML inside Rails applicationsRails HTML Sanitizer
- Fast XML parsing with some HTML supportOx
Comparison
| Tool | Best for | Standout feature | Listed starting price | Free plan or trial |
|---|---|---|---|---|
| 1Nokogiri | General HTML and XML parsing in Ruby | Mature and widely used | Free (open source) | Free plan |
| 2Nokolexbor | Fast HTML parsing with a Nokogiri-like API | Lexbor engine is fast | Free (open source) | Free plan |
| 3Loofah | Sanitizing untrusted HTML safely | Built on Nokogiri | Free (open source) | Free plan |
| 4Rails HTML Sanitizer | Sanitizing HTML inside Rails applications | Integrates with Rails helpers | Free (open source) | Free plan |
| 5Ox | Fast XML parsing with some HTML support | Very fast XML parsing | Free (open source) | Free plan |
How we picked
We compared libraries on fit for HTML parsing and sanitizing in Ruby, supported Ruby platforms, licence terms, maintenance activity and known limits. Sources are official project pages, documentation and repositories. We did not run benchmarks or hands-on tests. Prices and licences can change, so confirm details on each project page before you commit.
The tools, one by one
Nokogiri
Best for general HTML and XML parsing in Ruby

What it is and where it fits
Nokogiri parses HTML and XML and gives you a document tree you can query with CSS selectors or XPath. It uses libxml2 and includes the libgumbo HTML5 parser, so it handles malformed markup that appears in real pages. It runs on MRI, JRuby and TruffleRuby, with platform-specific gems for common systems.
The project is maintained by Sparkle Motion and released under the MIT licence. Installation compiles native extensions on some platforms, which can slow CI builds; precompiled gems reduce this on supported platforms. It parses strings and IO, and it can also fetch remote pages, though fetching is separate from parsing.
Choose Nokogiri when you want one library for scraping, feed parsing, XML work and test fixtures. Skip it only if native builds are a problem in your environment and a pure-Ruby parser fits your needs.
Standout: Mature and widely used
Free (open source), as listed by the vendor (Nokogiri website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Mature and widely used
- CSS and XPath selectors
Drawbacks
- Native extension build can be slow
- large dependency footprint
Skip it if this limit matters to you: native extension build can be slow.
Verdict. A sensible pick for general HTML and XML parsing in Ruby.
Alternatives in this guide: Nokolexbor, Loofah, Rails HTML Sanitizer
Nokolexbor
Best for fast HTML parsing with a Nokogiri-like API

What it is and where it fits
Nokolexbor is a Ruby binding to the Lexbor HTML parser, built by SerpApi. It targets the Nokogiri API so existing code often works with a require change. It handles CSS selectors and common node operations, and it is designed for speed on HTML5 parsing.
It is distributed as a gem under the MIT licence and builds against Lexbor. Because it is younger than Nokogiri, the API surface is narrower and some edge cases behave differently. Check the repository for the current list of supported methods and known gaps.
Pick Nokolexbor when parsing speed matters and your code relies on the Nokogiri-style API. Stay with Nokogiri if you depend on XML features, XPath coverage or a long track record.
Standout: Lexbor engine is fast
Free (open source), as listed by the vendor (Nokolexbor website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Lexbor engine is fast
- aims for Nokogiri API compatibility
Drawbacks
- Smaller community
- not every Nokogiri feature is covered
Skip it if this limit matters to you: smaller community.
Verdict. A sensible pick for fast HTML parsing with a Nokogiri-like API.
Alternatives in this guide: Nokogiri, Loofah, Rails HTML Sanitizer
Loofah
Best for sanitizing untrusted HTML safely

What it is and where it fits
Loofah cleans HTML so it is safe to render. It is built on Nokogiri and provides scrubbers that strip scripts, event handlers and other risky markup. You can define allowed tags and attributes, or use the built-in HTML5 and relaxed scrubbers. It is MIT licensed.
Loofah is the tool for user-submitted content, comments and rich-text fields. It is not designed for extracting data from pages, though you can combine it with Nokogiri for that. The default rules are a starting point; review them against your own threat model.
Choose Loofah when the job is sanitizing, not parsing for data. If you only need Rails helpers, the Rails HTML Sanitizer may be enough.
Standout: Built on Nokogiri
Free (open source), as listed by the vendor (Loofah website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Built on Nokogiri
- configurable scrubbers and allowed tags
Drawbacks
- Not a general scraper
- sanitizing rules need review
Skip it if this limit matters to you: not a general scraper.
Verdict. A sensible pick for sanitizing untrusted HTML safely.
Alternatives in this guide: Nokogiri, Nokolexbor, Rails HTML Sanitizer
Rails HTML Sanitizer
Best for sanitizing HTML inside Rails applications

What it is and where it fits
Rails HTML Sanitizer provides the sanitize helpers used by Rails views. It builds on Loofah and Nokogiri and ships default allowlists for tags and attributes. You can pass custom allowed tags and attributes per call. It is MIT licensed and maintained by the Rails team.
It suits Rails apps that render user content and want a supported, convention-based sanitizer. Outside Rails, or when you need fine-grained scrubber logic, Loofah gives you more control.
Use it when you are in Rails and want the standard helpers. Do not treat it as a parser for scraping; it is a sanitizing layer.
Standout: Integrates with Rails helpers
Free (open source), as listed by the vendor (Rails HTML Sanitizer website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Integrates with Rails helpers
- sensible default allowlists
Drawbacks
- Rails-oriented
- less flexible than Loofah for custom scrubbers
Skip it if this limit matters to you: rails-oriented.
Verdict. A sensible pick for sanitizing HTML inside Rails applications.
Alternatives in this guide: Nokogiri, Nokolexbor, Loofah
Ox
Best for fast XML parsing with some HTML support

What it is and where it fits
Ox is a fast XML parser and serializer written in C with a Ruby API. It offers SAX, object and DOM-style modes and is often used for large XML feeds. It has some HTML handling, but it is not a full HTML5 parser and does not match Nokogiri's tolerance for broken markup.
Ox is MIT licensed. Use it for XML-heavy work such as sitemaps, feeds and configuration files. For scraping messy HTML pages, Nokogiri or Nokolexbor are better fits.
Pick Ox when XML speed is the priority. Skip it for general HTML parsing where malformed markup is common.
Standout: Very fast XML parsing
Free (open source), as listed by the vendor (Ox website). Confirm the current plan price before you buy.
Free plan. Plans change, so confirm on the vendor's pricing page before you buy.
Benefits
- Very fast XML parsing
- supports SAX and object modes
Drawbacks
- HTML support is limited
- not a full HTML5 parser
Skip it if this limit matters to you: HTML support is limited.
Verdict. A sensible pick for fast XML parsing with some HTML support.
Alternatives in this guide: Nokogiri, Nokolexbor, Loofah
Who should use what
If you are scraping pages or parsing feeds, start with Nokogiri. If parsing speed is a bottleneck and your code already uses the Nokogiri API, try Nokolexbor. If you render user-submitted HTML, use Loofah, or the Rails HTML Sanitizer inside a Rails app. If you work mostly with XML and need speed, Ox is a good fit.
Questions to settle before you buy
What to check before you buy
- Confirm the library parses the kind of markup you see, including broken HTML.
- Check which Ruby versions and platforms are supported.
- Review the licence and any native build requirements for your CI.
- For sanitizers, review the default allowlist against your threat model.
- Check recent commits and open issues to judge maintenance.
FAQ
Is Nokogiri still the standard Ruby HTML parser?
Yes. It is the most widely used option, with CSS and XPath selectors, HTML5 parsing via libgumbo and broad platform support. Most Ruby scraping code assumes it.
Can I use Nokolexbor as a drop-in for Nokogiri?
Often, but not always. It targets the Nokogiri API, yet some methods and edge cases differ. Test your code against it before switching in production.
Should I use Loofah or Rails HTML Sanitizer?
Loofah gives you configurable scrubbers and works outside Rails. Rails HTML Sanitizer wraps Loofah for Rails helpers. Use the Rails one in Rails apps and Loofah when you need custom rules.
When should I choose Ox over Nokogiri?
Choose Ox when XML speed is the priority, such as for large sitemaps, feeds and configuration files. For messy HTML5 pages, Nokogiri or Nokolexbor are better fits.
Can Ox parse HTML?
It has limited HTML support and is mainly an XML parser. For messy HTML5 pages, use Nokogiri or Nokolexbor instead.
Sources we checked
Method: how we score · editorial policy.
Change log. First published 27 Nov 2026.