Skip to main content

HTML Cleaner

Turn messy HTML from Google Docs, Word, a CMS, or a scraper into clean, predictable markup. Strip inline styles, junk classes and ids, empty elements, and comments in one click.

HTML Input

Paste messy HTML and choose how much cleanup to apply

Minimal, low-risk cleanup. Formats the markup and normalizes whitespace without removing anything.

Presentation

Comma-separated. Only applies while “Remove all attributes” is on.

Comma-separated. Wildcards like data-* are supported.

Content

Structure

Formatting

What Is the HTML Cleaner Tool?

The HTML Cleaner is a free online utility that takes messy HTML — the kind pasted out of Google Docs, Word, a CMS, or a web scraper — and turns it into clean, predictable markup. It removes inline styles, meaningless classes and ids, nested <span> wrappers, &nbsp; runs, empty elements, and comments nobody asked for.

The tool runs the @vijayhardaha/html-cleaner library entirely in your browser. It parses your HTML into a tree, applies a pipeline of small composable transforms, and serializes the result once — so the same input and options always produce identical output. Nothing is uploaded, and the tool works offline once loaded.

Key Features

  • 19 cleanup options covering presentation, content, and structure
  • Five ready-made presets — Safe, Clean, Article, Aggressive, and Text
  • Presets write their values into the option controls, so you always see what is enabled
  • Deterministic output: the same input and options always produce byte-identical markup
  • Formatting controls for indentation, line endings, and trailing newlines
  • A change report showing exactly what was removed, unwrapped, or converted
  • Runs 100% client-side — your HTML never leaves your browser

Why Use This Tool

  • Pasting editor or scraper HTML into a CMS no longer drags along invisible styling baggage
  • Clean, predictable markup keeps your content diff-friendly instead of producing formatting churn
  • Stripping classes, ids, and inline styles removes implementation details you never meant to publish
  • Extracting readable text from a page is a single click with the Text preset
  • Consistent output makes scraped pages easy to compare and diff

Common Use Cases

  • Cleaning content pasted from Google Docs or Word before publishing
  • Reducing a scraped page to readable text for indexing or summarization
  • Preparing HTML for email templates where inline styles and editor cruft have to go
  • Flattening tables into plain content or converting them to divs
  • Normalizing markup in a review or audit workflow where deterministic output matters

What Gets Removed

  • Inline style attributes, classes, and ids
  • HTML comments
  • Empty elements, including NBSP-only nodes when enabled
  • Runs of non-breaking spaces, collapsed into regular spaces
  • Redundant wrapper elements such as nested spans and anchor tags (unwrapped, keeping their content)
  • Images, when you opt in
  • Table structure, either removed while keeping cell content or renamed to nested divs

How Presets Work

Presets are named bundles of option values layered on top of the safe defaults. Safe does only the default whitespace and formatting cleanup. Clean adds removal of inline styles, classes, and ids. Article goes further and unwraps spans and links and drops images. Aggressive removes every attribute, unwraps spans and links, drops images, and removes table markup. Text strips all tags and keeps readable line breaks, with formatting disabled.

Selecting a preset fills in the option controls below the input, and you can override any individual option afterward — the selector simply switches to Custom so you can see that the options no longer match a named bundle.

Technical Details

This tool uses the @vijayhardaha/html-cleaner npm package. The cleaner parses HTML into a HAST tree, runs each transform as an independent unit, and serializes the tree once. Because the work happens in your browser, there is no API request, no rate limit, and no upload. Note that this is a markup normalizer, not a security sanitizer — use a dedicated tool such as DOMPurify before rendering untrusted HTML.


Frequently Asked Questions

Is this tool free to use?

Yes, the HTML Cleaner is completely free to use with no signup, registration, or usage limits required.

Is my data sent to a server?

No. The HTML Cleaner runs entirely in your browser. Your markup never leaves your device, is never uploaded, stored, or logged, and the tool keeps working offline once the page has loaded.

What is HTML cleaning?

HTML cleaning parses your markup into a tree and applies predictable transformations — removing comments, inline styles, junk classes and ids, empty elements, and redundant wrappers — so the output is clean, consistent, and deterministic.

How is cleaning different from minifying?

Minifying compresses markup for smaller file size while keeping the structure intact. Cleaning restructures the markup itself: it strips presentation noise, unwraps redundant containers, and can reduce a document down to plain text. Cleaning often shrinks markup too, but readability rather than byte count is the goal.

Is this tool a security sanitizer?

No. This tool normalizes markup — it does not guarantee that dangerous content such as script tags, event handler attributes, or javascript: URLs is removed. Never use it as a security boundary for untrusted input; use a dedicated sanitizer such as DOMPurify for that.

What are presets and how do they work?

Presets are named bundles of options: Safe, Clean, Article, Aggressive, and Text. Selecting one fills in every option control so you can see exactly what it enables, and you can then override any individual option before cleaning. Editing an option switches the selector to Custom.

Can I clean HTML copied from Google Docs or Word?

Yes — that is exactly what this tool is built for. Use the Clean preset to strip inline styles, classes, and ids while keeping your text and structure, or the Article preset to also unwrap spans and links and drop images before pasting into a CMS.

What library does this tool use?

This tool uses @vijayhardaha/html-cleaner, an open-source library that parses HTML into an AST, applies composable transforms, and serializes deterministic output.

Can I use this tool offline?

Yes. Because all processing happens in your browser, the tool works offline once the page has loaded — there is no server-side API call involved.


Credits & Source

Built on @vijayhardaha/html-cleaner, the open-source HTML cleaner maintained by Vijay Hardaha.


Related Tools

UnminifyReverse minification for HTML, CSS, and JavaScript. Beautify compressed code to make it readable for debugging and auditing.
CSS MinifierOptimize your stylesheets by removing redundant spaces and comments. Achieve faster CSS rendering and improved overall site performance.
JS MinifierCompress JavaScript files to minimize payload size. Improve browser execution speed and reduce bandwidth consumption for your web applications.
HTML MinifierCompress HTML files by removing unnecessary whitespace, comments, and characters. Reduce page size to significantly improve website load speed.
Dropdown to ArrayQuickly transform HTML `<select>` dropdown options into structured PHP or JavaScript arrays. Eliminate manual coding for data migration.
Text to ArrayConvert plain text lists into valid PHP or JavaScript arrays with auto-generated keys. Streamline your development workflow for configuration files.
Text to PHP VariablesAutomatically wrap lines of text into PHP variable declarations. Streamline the process of creating configuration lists and arrays.
CSS InlinerTransform external or internal CSS rules into inline HTML styles. Essential for maximizing email template compatibility across all clients.
JSON SorterAlphabetically sort JSON keys to make complex data structures readable. Perfect for debugging API responses and ensuring data consistency.
PX to REM ConverterConvert pixel (PX) values to REM units for scalable web typography. Essential for building accessible, responsive designs that adapt to user settings.