w:rStyle (Run Style Reference)
References a named character style by its styleId, applying its run properties to the run.
Parent elements
Description
w:rStyle references a named character style by its styleId, applying all run properties defined in that style to the run. It is defined in ECMA-376 Part 1 §17.3.2.29.
Character styles applied via w:rStyle have lower priority than direct run properties set in the same w:rPr. The w:val must match the w:styleId attribute of a w:style element with w:type="character" in styles.xml.
Attributes
| Attribute | Type | Possible Values | Description |
|---|---|---|---|
w:val |
ST_String |
The styleId of any character style defined in the document (e.g. DefaultParagraphFont, Hyperlink, Strong, Emphasis). |
References the character style to apply. |
Examples
<w:r>
<w:rPr>
<w:rStyle w:val="Emphasis"/>
</w:rPr>
<w:t>Emphasised text</w:t>
</w:r>
new Run(
new RunProperties(
new RunStyle { Val = "Emphasis" }),
new Text("Emphasised text"));
<!-- Character style with override: hyperlink with bold -->
<w:r>
<w:rPr>
<w:rStyle w:val="Hyperlink"/>
<w:b/> <!-- Override style's default formatting -->
</w:rPr>
<w:t>Bold Hyperlink</w:t>
</w:r>
new Run(
new RunProperties(
new RunStyle { Val = "Hyperlink" },
new Bold()), // Overrides style
new Text("Bold Hyperlink"));
<!-- Custom character style -->
<w:r>
<w:rPr>
<w:rStyle w:val="CustomTermStyle"/>
<w:color w:val="0070C0"/> <!-- Direct property -->
</w:rPr>
<w:t>Important Term</w:t>
</w:r>
new Run(
new RunProperties(
new RunStyle { Val = "CustomTermStyle" },
new Color { Val = "0070C0" }),
new Text("Important Term"));
Built-in Character Styles
| Style ID | Display Name | Use Case | Typical Formatting |
|---|---|---|---|
DefaultParagraphFont |
Default Paragraph Font | Default run formatting | Inherits from paragraph style |
Hyperlink |
Hyperlink | Web/email links | Blue, underlined |
FollowedHyperlink |
Followed Hyperlink | Visited links | Purple, underlined |
Strong |
Strong | Bold emphasis | Bold weight |
Emphasis |
Emphasis | Italic emphasis | Italic style |
IntenseEmphasis |
Intense Emphasis | Bold + italic + color | Bold + italic + colored |
BookTitle |
Book Title | Referenced book titles | Italic |
SubtleReference |
Subtle Reference | Cross-references | Gray color |
NoSpacing |
No Spacing | Inline code/monospace | Monospace font |
Character Style Priority
- Highest: Direct run properties in
w:rPr(direct formatting) - Medium: Character style (
w:rStyle) - Lowest: Paragraph style’s run properties (
w:pPr/w:rPr) - Fallback: Document’s default character formatting
Notes
- Style IDs are locale-independent internal identifiers; display name is in
w:style/w:name. - Missing Style: If
w:valreferences a non-existent character style, the element is ignored. - Direct Override: Direct run properties in
w:rPralways override character style properties. - Paragraph Style Inheritance: Character styles are independent; they don’t inherit from paragraph styles.
- Linked Styles: Some character styles are linked to paragraph styles (e.g., “Heading 1 Char”); they sync when parent paragraph style changes.
- Custom Character Styles: Documents can define custom character styles in styles.xml with custom style IDs.
- Best Practice: Use character styles for semantic markup (emphasis, strong, hyperlink) rather than direct formatting.
- Performance: Overuse of direct character formatting (instead of styles) increases file size and reduces consistency.