Markdown is a superset of HTML, with consequences
CommonMark allows raw HTML inline and as block elements. Inline tags (<span>, <kbd>, <sub>, <sup>, <abbr>, <cite>) work where Markdown emphasis works. Block tags (<div>, <table>, <details>) need a blank line before and after to be treated as a block.
Useful HTML in Markdown
- Image sizing — Markdown has no width attribute; use
<img src="..." width="400" alt="...">. - Collapsible sections —
<details><summary>Click</summary>...</details>. Renders on GitHub. - Keyboard shortcuts —
<kbd>Cmd</kbd>+<kbd>K</kbd>shows a styled key. - Subscript / superscript —
H<sub>2</sub>O,x<sup>2</sup>. - Complex tables — when GFM tables can't (rowspan, colspan, block content in cells), drop to
<table>.
The XSS warning
If your site renders user-supplied Markdown (comments, wiki, forum posts) you must sanitize the output HTML. Without sanitization, <script>alert(1)</script> in a comment becomes a real script tag in the page. GitHub strips dangerous tags; many static-site generators do not (they assume the author is trusted). Know which side of the line your renderer is on.
Principle: trusted-author Markdown can include any HTML. Untrusted-author Markdown must be sanitized server-side with a known-good library (rehype-sanitize, DOMPurify, bleach, sanitize-html). 'I'll sanitize on the client' is an XSS vulnerability waiting for a refactor.