Raw HTML in Markdown — HTML Passthrough

Understand how raw HTML tags are passed through when converting Markdown to HTML. Learn which elements work, security considerations, and when to use raw HTML.

Advanced

Detailed Explanation

Raw HTML in Markdown

One of Markdown's design principles is that you can use raw HTML anywhere in a Markdown document. Most Markdown parsers pass HTML tags through directly to the output.

Block-Level HTML

Block-level HTML elements (like <div>, <table>, <section>) must be separated from surrounding content by blank lines:

A regular paragraph.

<div class="custom-box">
  <p>This is raw HTML inside Markdown.</p>
</div>

Another paragraph.

Converts to:

<p>A regular paragraph.</p>
<div class="custom-box">
  <p>This is raw HTML inside Markdown.</p>
</div>
<p>Another paragraph.</p>

Important: Markdown syntax is not processed inside block-level HTML elements. So **bold** inside a <div> will not be converted to <strong>.

Inline HTML

Inline HTML elements (like <span>, <abbr>, <mark>) can be used within Markdown text:

This word is <mark>highlighted</mark> and this has a <span style="color:red">red</span> color.

Unlike block-level HTML, Markdown syntax is processed around inline HTML elements.

Common Use Cases for Raw HTML

  • Custom attributes: Adding id, class, or style to elements
  • Complex tables: Using colspan, rowspan, and multi-line cells
  • Embedded media: <video>, <audio>, and <iframe> elements
  • Details/summary: Collapsible sections with <details> and <summary>
  • Definition lists: <dl>, <dt>, <dd> elements not supported in basic Markdown

Security Considerations

Many Markdown renderers sanitize HTML to prevent XSS attacks. Tags like <script>, <style>, and event handlers (onclick, onerror) are typically stripped. When building a Markdown-to-HTML pipeline, always consider whether raw HTML should be allowed, restricted, or fully sanitized.

Use Case

Raw HTML passthrough is used when Markdown syntax is insufficient — embedding videos, creating complex layouts, adding custom CSS classes, or using semantic HTML elements like <details>, <figure>, and <aside>. It bridges the gap between Markdown simplicity and HTML's full expressiveness.

Try It — Markdown to HTML Converter

Open full tool