Cloudflare HTMLRewriter: parse and transform HTML in Workers
Answer: HTMLRewriter is a streaming API to parse and transform HTML in Cloudflare Workers. You attach handlers with on for elements and onDocument for the document, then transform a response.
Examples
new HTMLRewriter()
.on("*", new ElementHandler())
.onDocument(new DocumentHandler());
Notes
It is part of the Workers runtime APIs.
Reference list
HTMLRewriteris a streaming API to parse and transform HTML.Handlersare attached with on and onDocument.HTMLRewriterparses and transforms HTML.
See also
Claims
- id: C1 claim: HTMLRewriter is a streaming API to parse and transform HTML. source: S2 evidence: "API to parse and transform HTML"
- id: C2 claim: Handlers are attached with on and onDocument. source: S2 evidence: "on(\"*\", new ElementHandler()) .onDocument(new DocumentHandler())"
- id: C3 claim: HTMLRewriter parses and transforms HTML. source: S1 evidence: "parse and transform HTML"
Sources
- [S1] HTMLRewriter. Cloudflare docs. https://developers.cloudflare.com/workers/runtime-apis/html-rewriter/ . License: CC-BY-4.0. Accessed 2026-11-18.
- [S2] html-rewriter.mdx. Cloudflare docs source. https://raw.githubusercontent.com/cloudflare/cloudflare-docs/production/src/content/docs/workers/runtime-apis/html-rewriter.mdx . License: CC-BY-4.0. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Cloudflare docs, HTMLRewriter; Cloudflare docs source, html-rewriter.mdx. CC-BY-4.0 (https://raw.githubusercontent.com/cloudflare/cloudflare-docs/production/LICENSE). Copyright Cloudflare, Inc. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Cloudflare docs, HTMLRewriter; Cloudflare docs source, html-rewriter.mdx. CC-BY-4.0 (https://raw.githubusercontent.com/cloudflare/cloudflare-docs/production/LICENSE). Copyright Cloudflare, Inc.
Cite this
iinventedlight. 2026. "Cloudflare HTMLRewriter: parse and transform HTML in Workers." iinventedlight Library, iil:note:9m80vvcf, version of 2026-11-18. https://iinventedlight.com/library/notes/cloudflare-htmlrewriter/. License: CC-BY-4.0.
@misc{iil_note_9m80vvcf,
author = {{iinventedlight}},
title = {{Cloudflare HTMLRewriter: parse and transform HTML in Workers}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/cloudflare-htmlrewriter/},
note = {Permanent ID iil:note:9m80vvcf. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- cloudflare-htmlrewriter.table.json (table; CC-BY-4.0)
- cloudflare-htmlrewriter.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/cloudflare-htmlrewriter.md.