Newsletter
Join the Community
Subscribe to our newsletter for the latest news and updates
The fast, flexible, and elegant library for parsing and manipulating HTML and XML.
Cheerio is a free, open-source JavaScript library for parsing HTML and XML strings and manipulating the resulting document with a jQuery-like syntax, widely used for server-side web scraping and HTML transformation. It runs in Node.js and in browsers, accepts a document string as input, and outputs serialized HTML or plain text via its .html() and .text() methods. The project is maintained by the cheeriojs organization on GitHub and has over 30,000 stars.
Cheerio parses an HTML or XML document into a lightweight DOM tree and exposes a jQuery-style API for selecting elements, traversing the tree, and mutating content. It takes a document string (for example, fetched HTML from a URL) and returns a queryable object that behaves like jQuery's $. The library is built on the parse5 HTML parser by default and can optionally use the more forgiving htmlparser2, and it is packaged as an ESM or CommonJS module.
.text(), .attr(), .html(), and .addClass(), so developers familiar with jQuery can start immediately.cheerio.load() accepts HTML or XML strings, and selectors can accept a context and root to scope searches..html() serializes the full document, .text() extracts text content, and .prop('outerHTML') returns a selection's outer HTML.tagName, parentNode, previousSibling, nextSibling, nodeValue, and childNodes.$('ul .pear'), extract attribute values or text, and serialize the result.import * as cheerio from 'cheerio') or CommonJS (require('cheerio')). 3. Call cheerio.load(html) to get a $ object. 4. Use selectors and manipulation methods on the object. 5. Render the final HTML with $.html().Cheerio is free and open-source, released under the MIT License.
Yes, Cheerio is completely free to use and is distributed under the MIT License. You can install it with npm, yarn, bun, or Deno without any licensing fees.
Cheerio parses an HTML or XML string into a DOM-like structure and provides a jQuery-style API to select elements, read attributes and text, and modify the document. After manipulation, it can render the updated markup as a string.
The page states that Cheerio can parse nearly any HTML or XML document. It wraps the parse5 parser for HTML and can optionally use htmlparser2, which also supports XML-style documents.
Yes, Cheerio works in both browser and server environments. It can be imported with ESM or CommonJS, making it suitable for Node.js scripts and client-side bundlers alike.
Cheerio is a parser and manipulation library that works on a string input and is much faster and lighter than jsdom, which simulates a full browser DOM including event handling and layout. Cheerio is the better choice when you only need to read or transform static HTML.
