w:body (Document Body)
Container for the block-level content that forms the main story of the document.
Parent elements
Description
w:body is the content container within w:document, holding all the visible content of the document. It is defined in ECMA-376 Part 1 §17.2.2.
w:body contains an ordered sequence of block-level elements: w:p (paragraphs), w:tbl (tables), w:sdt (structured document tags), w:bookmarkStart, w:bookmarkEnd, and revision elements. Its final child must be a w:sectPr that defines the last (or only) section’s layout properties.
Attributes
| Attribute | Type | Possible Values | Description |
|---|---|---|---|
| (none) | — | — | All content is expressed via child elements. |
Common Child Elements
| Child | Purpose | Example |
|---|---|---|
w:p |
Paragraph container | <w:p>...</w:p> |
w:tbl |
Table container | <w:tbl>...</w:tbl> |
w:sdt |
Structured document tag (content control) | <w:sdt>...</w:sdt> |
w:sectPr |
Section properties (final child, required) | <w:sectPr>...</w:sectPr> |
w:bookmarkStart / w:bookmarkEnd |
Bookmark anchors | <w:bookmarkStart w:id="0" w:name="MyBookmark"/> |
w:commentRangeStart / w:commentRangeEnd |
Comment anchors | <w:commentRangeStart w:id="0"/> |
w:ins / w:del |
Tracked changes (insertions/deletions) | <w:ins w:id="0" ...> |
Examples
Simple body with paragraphs and section
<w:body>
<w:p>
<w:r><w:t>First paragraph</w:t></w:r>
</w:p>
<w:p>
<w:r><w:t>Second paragraph</w:t></w:r>
</w:p>
<w:sectPr>
<w:pgSz w:w="12240" w:h="15840"/>
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440"/>
</w:sectPr>
</w:body>
new Body(
new Paragraph(new Run(new Text("First paragraph"))),
new Paragraph(new Run(new Text("Second paragraph"))),
new SectionProperties(
new PageSize { Width = 12240, Height = 15840 },
new PageMargin { Top = 1440, Right = 1440, Bottom = 1440, Left = 1440 }));
Body with tables and mixed content
<w:body>
<w:p>
<w:pPr><w:pStyle w:val="Heading1"/></w:pPr>
<w:r><w:t>Document Title</w:t></w:r>
</w:p>
<w:tbl>
<w:tblPr><w:tblW w:w="5000" w:type="pct"/></w:tblPr>
<w:tblGrid><w:gridCol w:w="2500"/><w:gridCol w:w="2500"/></w:tblGrid>
<w:tr>
<w:tc><w:p><w:r><w:t>Cell 1</w:t></w:r></w:p></w:tc>
<w:tc><w:p><w:r><w:t>Cell 2</w:t></w:r></w:p></w:tc>
</w:tr>
</w:tbl>
<w:p>
<w:r><w:t>Text after table</w:t></w:r>
</w:p>
<w:sectPr>
<w:pgSz w:w="12240" w:h="15840"/>
</w:sectPr>
</w:body>
new Body(
new Paragraph(
new ParagraphProperties(new ParagraphStyleId { Val = "Heading1" }),
new Run(new Text("Document Title"))),
new Table(
new TableProperties(new TableWidth { Width = "5000", Type = TableWidthUnitValues.Pct }),
new TableGrid(new GridColumn { Width = "2500" }, new GridColumn { Width = "2500" }),
new TableRow(
new TableCell(new Paragraph(new Run(new Text("Cell 1")))),
new TableCell(new Paragraph(new Run(new Text("Cell 2")))))),
new Paragraph(new Run(new Text("Text after table"))),
new SectionProperties(new PageSize { Width = 12240, Height = 15840 }));
Body with bookmarks and tracked changes
<w:body>
<w:bookmarkStart w:id="0" w:name="Introduction"/>
<w:p>
<w:r><w:t>Introduction text</w:t></w:r>
</w:p>
<w:bookmarkEnd w:id="0"/>
<w:ins w:id="0" w:author="John" w:date="2024-01-15T10:00:00Z">
<w:p>
<w:r><w:t>Added content</w:t></w:r>
</w:p>
</w:ins>
<w:sectPr/>
</w:body>
new Body(
new BookmarkStart { Id = 0, Name = "Introduction" },
new Paragraph(new Run(new Text("Introduction text"))),
new BookmarkEnd { Id = 0 },
new InsertedRun(
new Paragraph(new Run(new Text("Added content")))),
new SectionProperties());
Body Child Elements
| Element | Purpose | Multiple | Order |
|---|---|---|---|
w:p |
Paragraph | Yes | Body content (2nd+) |
w:tbl |
Table | Yes | Body content (2nd+) |
w:sdt |
Structured Document Tag | Yes | Body content (2nd+) |
w:bookmarkStart |
Bookmark start anchor | Yes | Annotation (2nd+) |
w:bookmarkEnd |
Bookmark end anchor | Yes | Annotation (2nd+) |
w:commentRangeStart |
Comment start | Yes | Annotation (2nd+) |
w:commentRangeEnd |
Comment end | Yes | Annotation (2nd+) |
w:commentRangeStart |
Comment range (complex) | Yes | Annotation (2nd+) |
w:ins |
Inserted content (tracked changes) | Yes | Revision (2nd+) |
w:del |
Deleted content (tracked changes) | Yes | Revision (2nd+) |
w:permStart |
Permission range start | Yes | Permission (2nd+) |
w:permEnd |
Permission range end | Yes | Permission (2nd+) |
w:sectPr |
Section properties (final) | No (exactly 1) | Last element |
Typical Document Structure
<w:body>
<w:p>...</w:p> <!-- Title/heading -->
<w:p>...</w:p> <!-- Body paragraphs -->
<w:tbl>...</w:tbl> <!-- Tables -->
<w:p>...</w:p> <!-- More content -->
<w:bookmarkStart/> <!-- Anchors for cross-refs -->
<w:p>...</w:p>
<w:bookmarkEnd/>
<w:sectPr>...</w:sectPr> <!-- Final section properties (REQUIRED) -->
</w:body>
Section Model
- Single Section: A document with one
w:sectPrat the end uses identical layout for all content. - Multiple Sections: Section breaks (inserted via
w:sectPrinsidew:pPr) create multiple sections with different page layouts. - Last Section: The
w:body/w:sectPralways defines the final section; intermediate sections havew:sectPrinw:pProf the last paragraph in that section.
Notes
- Required final element:
w:bodymust contain exactly onew:sectPras its last child; this defines section properties for the entire document (or the final section if there are section breaks). - Block-level content:
w:bodycontains only block-level elements (paragraphs, tables, SDTs); inline elements likew:rare invalid as direct children. - No nested bodies: A
w:bodycannot be nested inside anotherw:body; each document has exactly one body in the main part. - Content ordering: Paragraphs and tables flow in document order; the visual appearance depends on paragraph properties and table properties.
- Empty document: A valid document can contain an empty
w:bodywith only aw:sectPr; this would display as a blank page. - Bookmarks and comments: Use
w:bookmarkStart/w:bookmarkEndandw:commentRangeStart/w:commentRangeEndto mark regions for cross-references or comments; they do not display but are part of document structure. - Tracked changes: Wrap paragraphs or tables in
w:insorw:delelements to record insertions and deletions for revision tracking. - Structured content: Use
w:sdtelements for content controls, allowing conditional visibility, placeholder content, and form-like document regions. - Performance: Documents with very large bodies (>10,000 paragraphs) may experience rendering performance issues; consider splitting into subdocuments if needed.
- Accessibility: The body structure directly affects accessibility; screen readers depend on logical paragraph/table nesting and proper heading hierarchies defined via styles.
- Footnotes/Endnotes: Footnotes and endnotes are defined elsewhere (endnotes.xml, footnotes.xml); body contains only
w:footnoteReferenceandw:endnoteReferenceruns.