mdast2docx logo Md2Docx
Version 1.1.12

Supported Elements & Inline CSS

Updated 5 min ago

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.

Known Limitations

  • External Stylesheets: CSS files or <style> blocks in the document head are not evaluated.
  • Complex Flexbox / CSS Grid: HTML layout grids must use standard <table> elements for consistent rendering in Word.
  • Script Tags: <script>, <style>, <meta>, and other non-visual tags are stripped.

On this page