Supported Elements & Inline CSS
Updated 22 Oct 2026
Comprehensive list of supported HTML tags, typography mappings, and CSS properties.
@m2d/html parses both inline formatting tags and block-level layout structures, translating CSS styles into Microsoft Word OpenXML run and paragraph options.
Supported HTML Elements
| HTML Element | Converted MDAST Node | Word OpenXML Equivalent | Notes |
|---|---|---|---|
<img> | image | docx.ImageRun | Converted to MDAST image; rasterized by @m2d/image |
<table>, <tr>, <td>, <th> | table, tableRow, tableCell | docx.Table | Converted to MDAST table; formatted by @m2d/table |
<ul>, <ol>, <li> | list, listItem | Numbered / bullet paragraph | Formatted by @m2d/list |
<strong>, <b> | strong | Bold docx.TextRun | Preserves font styling |
<em>, <i> | emphasis | Italic docx.TextRun | Preserves font styling |
<del>, <s>, <strike> | delete | Strikethrough docx.TextRun | |
<u>, <ins> | Extended inline node | Underlined docx.TextRun | |
<sub> | Extended inline node | Subscript docx.TextRun | Native Word subscript |
<sup> | Extended inline node | Superscript docx.TextRun | Native Word superscript |
<a> | link | docx.ExternalHyperlink | Preserves href and text |
<br> | break | Line break | Soft carriage return within paragraph |
<hr> | thematicBreak | Horizontal border rule | |
<blockquote> | blockquote | Indented quote paragraph | Supports left border accents |
<input type="checkbox"> | Checkbox node | Unicode Checkbox | Renders ☑ (checked) or ☐ (unchecked) |
<h1> – <h6> | heading | docx.HeadingLevel | Level 1 through 6 headings |
<p>, <div> | paragraph | docx.Paragraph | Preserves block layout and inline styling |
Supported Inline CSS Properties
Inline styles specified via style="..." on HTML elements are parsed and standardized:
Colors & Shading
color: Hex, RGB, HSL, or named colors are normalized to Word 6-digit hex format (e.g.,#FF0000).background-color: Mapped todocx.ShadingTypeor highlight runs.
Typography
font-weight:bold,700,800,900trigger bold styling.font-style:italictriggers italic styling.font-size: Pixel, point, or rem dimensions are converted into Word half-points (twips).text-decoration:underlineandline-throughstrike.text-transform:uppercase,lowercase,capitalize.
Alignment & Spacing
text-align:left,center,right,justifymap to WordAlignmentType.margin-top,margin-bottom: Converted into paragraph before/after spacing twips.
Borders
border,border-left: Supportssolid,dashed,dotted,doublewith border width and color.
Embedded <style> Blocks & CSS Rule Cascading
@m2d/html and @m2d/html-node automatically extract <style> blocks and cascade CSS rules onto matching AST nodes across the document:
Supported Selectors
- Tag Selectors:
table,th,td,tr,h1–h6,p,blockquote,pre,code,hr,ol,ul - Descendant & Child Combinators: e.g.
table td,tr > th,div p
<style>
table {
border: 1px solid #cbd5e1;
width: 100%;
}
th {
background-color: #f1f5f9;
color: #1e293b;
padding: 8px;
}
td {
border: 1px solid #e2e8f0;
padding: 6px;
}
blockquote {
border-left: 4px solid #3b82f6;
background-color: #eff6ff;
}
</style>How Cascaded Styles Are Rendered in DOCX
- Headings (
h1–h6), Paragraphs (p), Blockquotes, Code Blocks, and<hr>:@m2d/htmlattaches resolved CSS rules to each AST node'snode.data.@m2d/corenatively forwardsnode.datadirectly todocx.Paragraph(applying shading, borders, text alignment, and spacing) without requiring extra plugin configuration. - Tables and Table Cells (
table,tr,th,td): Tables are rendered by the@m2d/tableplugin.@m2d/tableconsumescell.dataandnode.datato apply custom cell shading, cell padding (margins), cell borders, and table borders. - Class Selectors (
.my-class): Standard Markdown nodes do not have HTML class names. Class selectors apply to raw HTML elements that include a matchingclass="..."attribute. For standard Markdown content, use tag-based selectors or inlinestyle="..."attributes.
Standalone Utilities (@m2d/html/utils)
@m2d/html/utils exports standalone helpers for color normalization and DOM abstraction:
import { standardizeColor, type DocumentLike } from "@m2d/html/utils";
// Converts any CSS color to 6-digit hex format without '#'
const hex = standardizeColor("red"); // "ff0000"
const hexFromHash = standardizeColor("#0052cc"); // "0052cc"Known Limitations
- External Stylesheets: Remote
<link rel="stylesheet">files are not fetched; use embedded<style>blocks or inlinestyle="..."attributes. - Complex Flexbox / CSS Grid: HTML layout grids must use standard
<table>elements for consistent rendering in Word. - Script Tags:
<script>,<meta>, and other non-visual tags are safely stripped.