Using HTML inside Markdown can make your documentation more powerful, but it should be used carefully.
Follow these best practices to keep your documents clean, portable, and easy to maintain.
Use Markdown Whenever Possible
Markdown is easier to read and supported across virtually every Markdown editor.
For example, use Markdown instead of HTML for:
- Headings
- Lists
- Links
- Images
- Tables
- Code blocks
- Blockquotes
Reserve HTML for features that Markdown cannot provide.
Keep HTML Simple
Avoid writing complex HTML layouts inside Markdown documents.
Good example:
<img src="logo.png" alt="Project Logo" width="250">
Avoid embedding large HTML structures unless absolutely necessary.
Test on Your Target Platform
Not every Markdown renderer supports the same HTML elements.
Always preview your document on the platform where it will be published.
Examples include:
- GitHub
- GitLab
- VS Code
- Obsidian
- Docusaurus
- MkDocs
This helps prevent unexpected rendering issues.
Avoid Inline CSS
Many Markdown platforms remove inline CSS for security reasons.
Instead of this:
<p style="color:red;">
Important
</p>
Use standard Markdown formatting or supported HTML elements whenever possible.
Add Alt Text to Images
Always include descriptive alternative text when using HTML images.
Good example:
<img
src="diagram.png"
alt="Markdown syntax diagram"
width="500">
Alt text improves accessibility and helps search engines understand image content.
Don't Mix Too Much HTML and Markdown
Combining small amounts of HTML with Markdown works well.
However, documents that contain mostly HTML become harder to read and maintain.
Aim to keep Markdown as the primary syntax.