Skip to Content
Md2Docx logo Md2Docx

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 ElementConverted MDAST NodeWord OpenXML EquivalentNotes
<img>imagedocx.ImageRunConverted to MDAST image; rasterized by @m2d/image
<table>, <tr>, <td>, <th>table, tableRow, tableCelldocx.TableConverted to MDAST table; formatted by @m2d/table
<ul>, <ol>, <li>list, listItemNumbered / bullet paragraphFormatted by @m2d/list
<strong>, <b>strongBold docx.TextRunPreserves font styling
<em>, <i>emphasisItalic docx.TextRunPreserves font styling
<del>, <s>, <strike>deleteStrikethrough docx.TextRun
<u>, <ins>Extended inline nodeUnderlined docx.TextRun
<sub>Extended inline nodeSubscript docx.TextRunNative Word subscript
<sup>Extended inline nodeSuperscript docx.TextRunNative Word superscript
<a>linkdocx.ExternalHyperlinkPreserves href and text
<br>breakLine breakSoft carriage return within paragraph
<hr>thematicBreakHorizontal border rule
<blockquote>blockquoteIndented quote paragraphSupports left border accents
<input type="checkbox">Checkbox nodeUnicode CheckboxRenders ☑ (checked) or ☐ (unchecked)
<h1> – <h6>headingdocx.HeadingLevelLevel 1 through 6 headings
<p>, <div>paragraphdocx.ParagraphPreserves 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 to docx.ShadingType or highlight runs.

Typography

  • font-weight: bold, 700, 800, 900 trigger bold styling.
  • font-style: italic triggers italic styling.
  • font-size: Pixel, point, or rem dimensions are converted into Word half-points (twips).
  • text-decoration: underline and line-through strike.
  • text-transform: uppercase, lowercase, capitalize.

Alignment & Spacing

  • text-align: left, center, right, justify map to Word AlignmentType.
  • margin-top, margin-bottom: Converted into paragraph before/after spacing twips.

Borders

  • border, border-left: Supports solid, dashed, dotted, double with 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/html attaches resolved CSS rules to each AST node's node.data. @m2d/core natively forwards node.data directly to docx.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/table plugin. @m2d/table consumes cell.data and node.data to 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 matching class="..." attribute. For standard Markdown content, use tag-based selectors or inline style="..." 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 inline style="..." 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.

On this page