OK
Removes inline styles
Inline styles
Deletes classes and IDs
Classes & IDs
Deletes empty HTML tags
Empty tags
remove tags with one space
Tags with 1 space
remove successive spaces
Successive spaces
delete comments
Comments
remove tag attributes
Tag attributes
html to plain text
To plain text
Smart non-breaking spaces
Smart  s
ai watermarks remove
AI Watermarks

Deletes classes and IDsRemove HTML Classes and IDs

Classes and IDs are powerful for styling and scripting, but legacy content or generated HTML can overuse them, leaving bloated, brittle markup. Removing class and id attributes helps produce cleaner🧹, more portable HTML while you refactor styles and scripts to use modern patterns.

Tip: Remove classes and IDs when migrating content from one website to another.

✨ If your document also embeds CSS directly on elements, start by removing inline styles, or go broader and remove most tag attributes in one pass.

class="" id="" Compact code

What gets removed?

  • class attributes everywhere (elements keep their tags and content)
  • id attributes everywhere
  • Redundant identifiers added by editors, frameworks, or exports
  • Styling hooks that are no longer used

Why remove classes and IDs?

  • Cleaner HTML: easier to read, review, and debug.
  • Portability: content becomes independent of a specific CSS framework.
  • Safer refactors: fewer hidden dependencies on legacy selectors.
  • Better exports: ideal for DOCX, email, or text conversions.
Important: Only remove IDs when you're sure they aren't needed for fragment links, form labels, or JavaScript behavior.

Example: Before and After

Before (decorated markup):

<div id="hero" class="section section--primary">
  <h2 class="title is-3">Pretty HTML</h2>
  <p class="lead">Clean, portable HTML.</p>
</div>

After (cleaned):

<div>
  <h2>Pretty HTML</h2>
  <p>Clean, portable HTML.</p>
</div>

Move presentatoin to external CSS (utility classes or component classes) and only keep IDs where they are truly necessary (for example, fragment links or form labels). After trimming identifiers, it's common to reveal stray wrappers that have no content - use Remove empty HTML tags to clear those out.

Remove unused CSS: Use this free online tool to remove the unused styles from a HTML and CSS input.

How to use this page

  1. Paste or drop your HTML into the editor.
  2. Classes & IDs is selected by default here; other options are off.
  3. Click Pretty to strip class and id attributes across the document.
  4. Download the cleaned HTML or DOC file.

Common scenarios

When removal is ideal

  • Exporting content from a CMS or page builder
  • Cleaning HTML before sending it to email clients
  • Migrating between CSS frameworks
  • Preparing markup for text-only or Markdown conversion

When to keep them

  • Fragment links: anchors like #pricing
  • Form accessibility: label → for associations
  • JavaScript hooks: behavior bound to specific IDs or classes
  • Component systems: reusable UI blocks still under active development

Impact on layout and behavior

Removing classes and IDs does not change the semantic meaning of your HTML, but it can affect styling and scripts that rely on those attributes. That's why this step is often part of a larger cleanup or refactor process, not a one-click "final" operation.

Aspect Before removal After removal Notes
Readability Noisy, attribute-heavy Clean and focused Easier to review and diff
Styling Tightly coupled to classes Requires external or structural CSS Encourages modern CSS patterns
JavaScript Often selector-based Needs refactor if IDs/classes removed Plan this step carefully
Portability Framework-specific Framework-agnostic Ideal for reuse and export

Removing classes and IDs with JavaScript

You can also process an HTML string programmatically. Parse the markup, remove the attributes, then serialize the result. This approach is reliable and avoids fragile regular expressions. ⚙️

function stripClassesAndIds(html) {
  var parser = new DOMParser();
  var doc = parser.parseFromString(html, 'text/html');
  doc.querySelectorAll('[class]').forEach(function (el) {
    el.removeAttribute('class');
  });
  doc.querySelectorAll('[id]').forEach(function (el) {
    el.removeAttribute('id');
  });
  return doc.body.innerHTML;
}
// Example
var raw = '<h2 id="title" class="big">Hello</h2>';
var cleaned = stripClassesAndIds(raw);
// '<h2>Hello</h2>'

Optional: preserve a small allowlist

In real projects, you may want to keep a short list of IDs or classes that are still required. You can extend the function to skip elements that match an allowlist before removing attributes.
This gives you control while still dramatically reducing markup noise. 👍

Workflow: Remove inline styles → strip classes and IDs → remove empty tags → normalize spacing. This sequence reveals problems early and keeps your HTML predictable. Or just check these options and press the big Pretty button.

FAQ

Will this break my layout?

It can if your CSS relies on those classes or IDs. Use this tool when you're refactoring styles or exporting content, not on live pages without planning.

Is it safe for SEO?

Yes. Search engines don't rely on classes or IDs to understand content. As long as your semantic structure remains intact, SEO is unaffected.

Should I remove IDs everywhere?

It depends. Keep IDs that are required for accessibility, deep links, or scripts. This tool removes everything by default, so use it thoughtfully.

What about data attributes?

This tool focuses on class and id. If you want to remove other attributes, use the broader attribute-cleaning tool instead.

Don't forget to remove class and id attributes from your HTML with Pretty HTML if necessary. Clean markup while preserving content and structure.

Back to top