🧹

Why WordPress Strips Your HTML (and How to Stop It)

Quick answer: Paste custom HTML into a regular WordPress paragraph block and the block editor's formatting handler strips anything it doesn't recognize — custom classes, inline styles, most attributes. To keep your markup intact, use the Custom HTML block instead, and paste clean HTML into it, since WordPress's own content filter still applies to markup it considers unsafe regardless of which block you use.

Why does the block editor strip my markup?

Two different systems are working against you, and it helps to know which one you're fighting.

The first is the block editor's paste handler. Ordinary text blocks (Paragraph, Heading, List) are built around a rich text component that only understands a small, fixed set of formatting: bold, italic, strikethrough, links, and inline code. When you paste HTML into one of these blocks, the editor converts what it recognizes into that format and drops everything else — custom classes, data-* attributes, inline styles, non-standard tags. This happens in the browser, before the post is ever saved, and it happens the same way no matter who's logged in.

The second is WordPress's own content sanitizer, which runs on the server when the post is saved. It filters out tags and attributes that aren't on an approved list, and how strict it is depends on your user role and site configuration — some roles have permission to save raw, unfiltered HTML, others don't. This is a security feature: it's the same mechanism that stops a lower-permission user from saving a <script> tag into a post.

How do you paste HTML without losing it?

Use the Custom HTML block. Add it from the block inserter, and whatever you paste into it is stored as raw markup instead of being run through the rich text formatting handler. It renders your code in a live preview (in an iframe) so you can confirm it looks right before you publish.

This sidesteps the paste-handler problem entirely, because the Custom HTML block never tries to convert your markup into its own block format. It doesn't sidestep the server-side sanitizer, though — if your account doesn't have permission to save unfiltered HTML, tags or attributes the sanitizer doesn't allow will still be removed when you save, even inside a Custom HTML block.

Why does cleaning the HTML first still matter?

Because most of what gets stripped by either system is exactly the clutter a cleanup pass would remove anyway. Content pasted from Word or Google Docs is full of inline styles and application-specific classes that mean nothing on your site — see how to clean up HTML from Word and Google Docs for what that markup actually looks like. If you strip that out before pasting, what's left is the structure you actually want (headings, links, tables, lists), which is far more likely to survive both the paste handler and the sanitizer intact.

The Word to HTML Cleaner handles this in one step: paste your content, and it strips the inline styles, Word-specific classes, and Microsoft namespace tags while leaving your actual structure alone. What comes out is markup that's clean enough to paste straight into a Custom HTML block without a fight.

Need Your Website Rebuilt the Right Way?. Bootstrap Creative designs and builds B2B and manufacturing websites that are fast, clean, and built to convert. See Web Design Services →

Frequently asked questions

Why does WordPress remove my custom classes and attributes?

Two separate things are happening. WordPress's built-in content sanitizer strips tags and attributes it doesn't recognize as safe for users who don't have unfiltered HTML permission. Separately, the block editor's normal text blocks run pasted content through their own formatting handler, which only understands a small set of formatting (bold, italic, links) and drops the rest — regardless of your user role.

What's the Custom HTML block, and when should I use it?

It's a block type that stores your markup as raw HTML instead of running it through the editor's rich text formatting handler. Use it whenever you're pasting HTML with structure the editor doesn't have a block for — a table, a custom-styled callout, an embed. It previews your code in an iframe so you can check it renders correctly before publishing.

Does cleaning my HTML first actually help?

Yes. If the HTML you're pasting is already free of inline styles, stray classes, and Word or Docs formatting cruft, there's less for the editor's sanitizer to strip or mangle, and what does make it through the Custom HTML block is markup you actually meant to keep.

HTML & CSS Cleaner Tool

As web developers and designers, we often encounter HTML files laden with inline styles—those pesky CSS rules embedded directly within HTML tags. While this approach might seem convenient at first, it can lead to bloated code, slower page load times, and maintenance headaches. Fear not! Our HTML and CSS Cleaner Tool comes to the rescue. Whether you’re a seasoned developer or just starting your web journey, understanding the importance of clean HTML and CSS is essential.

Built and maintained by Bootstrap Creative, a web design and marketing agency for B2B and manufacturing companies. · Blog