w:style (Style Definition)
Defines a named reusable style (paragraph, character, table, or numbering type) with a set of formatting properties.
Description
w:style defines a named style that can be applied to paragraphs, runs, or tables. It is defined in ECMA-376 Part 1 §17.7.4.17.
The w:type attribute classifies the style; w:styleId is the internal identifier referenced by w:pStyle, w:rStyle, or w:tblStyle. Styles can inherit from other styles via w:basedOn and chain to the next style via w:next.
Attributes
| Attribute | Type | Possible Values | Description |
|---|---|---|---|
w:type |
ST_StyleType |
paragraph, character, table, numbering |
The type of style. |
w:styleId |
ST_String |
Non-blank identifier, unique within the document (e.g. Heading1, Normal, DefaultParagraphFont). |
Internal ID referenced by w:pStyle, w:rStyle, w:tblStyle. |
w:default |
ST_OnOff |
true / false |
When true, this is the default style of its type (applied when no explicit style is set). |
w:customStyle |
ST_OnOff |
true / false |
When true, this is a user-defined style not from the built-in set. |
Examples
<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:pPr>
<w:outlineLvl w:val="0"/>
<w:pageBreakBefore/>
</w:pPr>
<w:rPr>
<w:b/>
<w:sz w:val="32"/>
</w:rPr>
</w:style>
new Style(StyleValues.Paragraph, "Heading1")
{
StyleName = new StyleName { Val = "heading 1" },
BasedOn = new BasedOn { Val = "Normal" },
NextParagraphStyle = new NextParagraphStyle { Val = "Normal" },
StyleParagraphProperties = new StyleParagraphProperties(
new OutlineLevel { Val = 0 },
new PageBreakBefore()),
StyleRunProperties = new StyleRunProperties(
new Bold(),
new FontSize { Val = "32" })
};