Named formatting lives in word/styles.xml, reached by the main document’s
styles relationship. A paragraph or run points to a style by its ID, and the
text carries only what differs from the style.
An example
<w:styles xmlns:w="…">
<w:docDefaults>
<w:rPrDefault><w:rPr>
<w:rFonts w:ascii="Calibri" w:hAnsi="Calibri"/>
<w:sz w:val="22"/>
</w:rPr></w:rPrDefault>
<w:pPrDefault><w:pPr>
<w:spacing w:after="160" w:line="259" w:lineRule="auto"/>
</w:pPr></w:pPrDefault>
</w:docDefaults>
<w:style w:type="paragraph" w:default="1" w:styleId="Normal">
<w:name w:val="Normal"/>
<w:qFormat/>
</w:style>
<w:style w:type="paragraph" w:styleId="Heading1">
<w:name w:val="heading 1"/>
<w:basedOn w:val="Normal"/>
<w:next w:val="Normal"/>
<w:qFormat/>
<w:pPr><w:outlineLvl w:val="0"/></w:pPr>
<w:rPr><w:b/><w:sz w:val="32"/></w:rPr>
</w:style>
</w:styles>
What styles.xml holds
| Element | Meaning |
|---|---|
w:docDefaults | w:rPrDefault and w:pPrDefault: properties that apply before any style. |
w:latentStyles | What the built-in styles that are not yet in the document will look like in Word’s user interface: visibility and order, not formatting. |
w:style | One style. |
w:style
| Item | Meaning |
|---|---|
w:type (attribute) | paragraph, character, table or numbering. |
w:styleId (attribute) | The ID that text refers to. In Word, the name without spaces, for example Heading1. |
w:default (attribute) | This is the default style of its type: the one used when text names no style. |
w:customStyle (attribute) | The style is the user’s own, not built in. |
w:name | The style’s name, such as heading 1, which built-in styles are identified by. |
w:basedOn | The style this one inherits from. |
w:next | The style of the next paragraph after pressing Enter. |
w:link | The linked style: a paragraph and character style pair. |
w:uiPriority, w:semiHidden, w:unhideWhenUsed, w:qFormat | How Word lists the style. |
w:pPr, w:rPr | The style’s paragraph and run properties. |
w:tblPr, w:trPr, w:tcPr, w:tblStylePr | Table style properties, and overrides for parts of a table such as the first row. |
How formatting is resolved
A property’s final value comes from these, later ones overriding earlier ones:
- The document defaults (
w:docDefaults). - The table style, for text in a table.
- The numbering properties of a numbered paragraph.
- The paragraph style and its based-on chain.
- The character style and its based-on chain.
- Direct formatting on the paragraph or run.
Along a based-on chain, the nearest style that sets a property wins. The chain is
followed until a style with no w:basedOn; a reader should guard against
loops.
Some on/off properties are toggle properties: w:b,
w:i, w:caps, w:smallCaps, w:strike,
w:vanish and a few others. When a paragraph style and a character style both
turn one on, the two cancel out: a run in a bold paragraph style with the
Strong character style is not bold. Direct formatting does not toggle: it
sets the value outright.