DOCX

Text and Paragraphs

Work with paragraphs, text runs, formatting, alignment, spacing, indentation, lists, and tab stops

Documents are built from paragraph elements, each containing text runs with individual formatting.

Paragraph

{
  "sections": [
    {
      "children": [
        { "paragraph": { "children": ["Plain text paragraph."] } },
        { "paragraph": { "heading": "Heading1", "children": ["Chapter Title"] } }
      ]
    }
  ]
}

Alignment and Spacing

{
  "sections": [
    {
      "children": [
        {
          "paragraph": {
            "alignment": "center",
            "spacing": { "before": 200, "after": 200, "line": 360 },
            "indent": { "left": 720 },
            "children": ["Centered paragraph with spacing and indent."]
          }
        }
      ]
    }
  ]
}

Borders

{
  "sections": [
    {
      "children": [
        {
          "paragraph": {
            "border": { "bottom": { "style": "single", "size": 6, "color": "999999" } },
            "children": ["Paragraph with a bottom border."]
          }
        }
      ]
    }
  ]
}

TextRun

Each text run can have its own formatting:

{
  "sections": [
    {
      "children": [
        {
          "paragraph": {
            "children": [
              { "text": "Bold", "bold": true },
              { "text": ", Italic", "italic": true },
              { "text": ", Underline", "underline": { "type": "single" } },
              { "text": ", Strikethrough", "strike": true },
              { "text": ", 24pt", "size": 24 },
              { "text": ", Colored", "color": "FF0000" },
              { "text": ", Courier", "font": "Courier New" },
              { "text": ", Super", "superScript": true },
              { "text": ", Sub", "subScript": true }
            ]
          }
        }
      ]
    }
  ]
}

Numbered and Bulleted Lists

Use numbering to define list styles, then reference them in paragraphs:

{
  "numbering": {
    "config": [
      {
        "reference": "my-numbering",
        "levels": [
          { "level": 0, "format": "decimal", "text": "%1.", "alignment": "start" },
          { "level": 1, "format": "lowerLetter", "text": "%2)", "alignment": "start" }
        ]
      }
    ]
  },
  "sections": [
    {
      "children": [
        {
          "paragraph": {
            "numbering": { "reference": "my-numbering", "level": 0 },
            "children": ["First item"]
          }
        },
        {
          "paragraph": {
            "numbering": { "reference": "my-numbering", "level": 0 },
            "children": ["Second item"]
          }
        },
        {
          "paragraph": {
            "numbering": { "reference": "my-numbering", "level": 1 },
            "children": ["Nested sub-item"]
          }
        }
      ]
    }
  ]
}

For bullet lists, use format: "bullet" in the level config.

Tab Stops

{
  "sections": [
    {
      "children": [
        {
          "paragraph": {
            "tabStops": [{ "type": "left", "position": 10000 }],
            "children": ["Name", "TAB", "John Doe"]
          }
        }
      ]
    }
  ]
}

Page Break

Insert a page break between paragraphs:

{
  "sections": [
    {
      "children": [{ "paragraph": { "pageBreakBefore": true, "children": ["Start of new page"] } }]
    }
  ]
}

Paragraph Options Reference

OptionTypeDescription
alignment"left" | "center" | "right" | "distribute"Horizontal alignment
spacing.beforenumberSpace before in TWIPs
spacing.afternumberSpace after in TWIPs
spacing.linenumberLine spacing in 1/240ths of a line
indent.leftnumberLeft indent in TWIPs
indent.rightnumberRight indent in TWIPs
indent.firstLinenumberFirst line indent in TWIPs
indent.hangingnumberHanging indent in TWIPs
headingstringHeading level ("Heading1""Heading6")
borderobjectParagraph borders
pageBreakBeforebooleanForce page break before this paragraph
numberingobjectList reference and level
tabStopsarrayTab stop definitions
stylestringNamed style reference
paraIdstringUnique paragraph id (8-digit hex, w14:paraId)
textIdstringParagraph text id (w14:textId)
rsidstringRevision id (w:rsidR, hex); related: defaultRunRsid, propertiesRsid, runPropertiesRsid, deletionRsid

TextRun Options Reference

OptionTypeDescription
textstringText content
boldbooleanBold formatting
italicbooleanItalic formatting
underlineobjectUnderline style and type
strikebooleanStrikethrough
doubleStrikebooleanDouble strikethrough
subScriptbooleanSubscript
superScriptbooleanSuperscript
sizenumberFont size in points (12 = 12pt)
colorstringHex color without #
fontstringFont family name
highlightstringHighlight color
shadingobjectBackground shading
stylestringNamed character style reference
breaknumberNumber of line breaks
characterSpacingnumberCharacter spacing in TWIPs
rsidstringRevision id (w:rsidR, hex); related: runPropertiesRsid, deletionRsid
Copyright © 2026