w:spacing (Spacing)
Controls space before and after a paragraph and the line spacing rule and value.
Parent elements
Description
w:spacing controls the whitespace before and after a paragraph and the spacing between lines within it when used in paragraph context (w:pPr). It is defined in ECMA-376 Part 1 §17.3.1.33.
When applied inside w:rPr (run context), w:spacing controls character spacing (tracking/kerning offset) for individual runs, using different attributes than the paragraph variant. This element is essential for controlling document flow and readability.
All distance values in paragraph context are in twentieths of a point (twips); 1 inch = 1440 twips. Line spacing can be specified as fixed (exact), minimum (at least), or proportional (auto/percentage).
Attributes (Paragraph Context — inside w:pPr)
| Attribute | Type | Possible Values | Description |
|---|---|---|---|
w:before |
ST_TwipsMeasure |
Non-negative integer in twips (e.g., 240 = 12 pt). |
Space added above the paragraph before any content. |
w:after |
ST_TwipsMeasure |
Non-negative integer in twips. | Space added below the paragraph after content ends. |
w:beforeLines |
xsd:integer |
Percentage in fiftieths of a line (e.g., 100 = 1 line). Takes precedence over w:before. |
Space above in line units; useful for proportional spacing. |
w:afterLines |
xsd:integer |
Percentage in fiftieths of a line. Takes precedence over w:after. |
Space below in line units. |
w:line |
ST_SignedTwipsMeasure |
Integer in twips (for exact/atLeast) or twips × 240 units for auto. Example: 276 ≈ 1.15 line (single space at 12 pt). |
Line spacing value; interpretation depends on w:lineRule. |
w:lineRule |
ST_LineSpacingRule |
auto (proportional, default), exact (fixed), atLeast (minimum) |
Governs how w:line is interpreted; critical for understanding line spacing behavior. |
w:beforeAutospacing |
ST_OnOff |
true / false / 1 / 0 |
When true, overrides w:before with automatic spacing (Word decides based on font size). |
w:afterAutospacing |
ST_OnOff |
true / false / 1 / 0 |
When true, overrides w:after with automatic spacing. |
Attributes (Run Context — inside w:rPr)
| Attribute | Type | Possible Values | Description |
|---|---|---|---|
w:val |
ST_SignedHpsMeasure |
Integer in twentieth-points (e.g., 20 = 1 pt). Negative values compress spacing. |
Character spacing adjustment applied uniformly between all characters in the run. |
Examples
Paragraph spacing: 12 pt before, 6 pt after, single line spacing
<w:pPr>
<w:spacing w:before="240" w:after="120" w:line="240" w:lineRule="auto"/>
</w:pPr>
var pPr = new ParagraphProperties(
new SpacingBetweenLines
{
Before = "240", // 12 pt
After = "120", // 6 pt
Line = "240", // Single line spacing (100% at 12 pt baseline)
LineRule = LineSpacingRuleValues.Auto
});
1.5-line spacing with proportional units
<w:pPr>
<w:spacing w:before="0" w:after="0" w:line="360" w:lineRule="auto"/>
<!-- line="360" with lineRule="auto" = 1.5× line spacing -->
</w:pPr>
var pPr = new ParagraphProperties(
new SpacingBetweenLines
{
Before = "0",
After = "0",
Line = "360", // 1.5× line spacing (360 / 240 = 1.5)
LineRule = LineSpacingRuleValues.Auto
});
Fixed line spacing (exactly 18 pt)
<w:pPr>
<w:spacing w:line="360" w:lineRule="exact"/>
<!-- 360 twips = 18 pt exactly; overrides font size -->
</w:pPr>
var pPr = new ParagraphProperties(
new SpacingBetweenLines
{
Line = "360", // Exactly 18 pt line height
LineRule = LineSpacingRuleValues.Exact
});
Line Spacing Reference
| Description | w:line Value |
w:lineRule |
Notes |
|---|---|---|---|
| Single (100%) | 240 |
auto |
Standard line spacing for 12 pt font |
| 1.15 lines | 276 |
auto |
Default in Microsoft Word |
| 1.5 lines | 360 |
auto |
360 / 240 = 1.5 |
| Double (200%) | 480 |
auto |
480 / 240 = 2.0 |
| Exactly 12 pt | 240 |
exact |
Fixed height, ignores font size |
| Exactly 18 pt | 360 |
exact |
Fixed height |
| At least 12 pt | 240 |
atLeast |
Minimum height; can grow with font |
| At least 18 pt | 360 |
atLeast |
Minimum height |
Character Spacing in Runs (w:rPr context)
When w:spacing appears inside w:rPr, it controls character-level spacing (tracking):
<w:rPr>
<w:spacing w:val="20"/> <!-- 20 twentieth-points = 1 pt spacing added between characters -->
</w:rPr>
Useful for:
- Tight spacing: negative values (e.g.,
w:val="-10") - Wide spacing: positive values (e.g.,
w:val="30") - Small caps or decorative text
Autospacing Behavior
When w:beforeAutospacing="true" or w:afterAutospacing="true":
- Word automatically calculates spacing based on paragraph font size.
- Typical values are 0 pt before and 8-10 pt after for normal text.
- Consecutive paragraphs with matching autospacing settings use unified rather than additive spacing.
- Automatic spacing overrides explicit
beforeoraftervalues.
Conversion Reference
| Spacing | Twips | Half-Points | Line Units |
|---|---|---|---|
| 6 pt | 120 | 12 | — |
| 12 pt | 240 | 24 | 1 line (at 12 pt baseline) |
| 18 pt | 360 | 36 | 1.5 lines |
| 24 pt | 480 | 48 | 2 lines |
| 36 pt | 720 | 72 | 3 lines |
Character Spacing Example
<w:r>
<w:rPr>
<w:spacing w:val="20"/>
</w:rPr>
<w:t>Spaced out text</w:t>
</w:r>
var run = new Run(
new RunProperties(
new Spacing { Val = "20" } // +1 pt character spacing
),
new Text("Spaced out text"));
Twips Conversion Reference
| Unit | Twips | Formula |
|---|---|---|
| 1 pt | 20 | pt × 20 |
| 6 pt | 120 | 6 × 20 |
| 12 pt | 240 | 12 × 20 |
| 18 pt | 360 | 18 × 20 |
| 1 inch | 1440 | 1 in × 1440 |
| 1 cm | ~567 | 1 cm × 567 |
Notes
- Paragraph vs. character spacing: Paragraph spacing controls space before/after paragraphs and between lines; run-level spacing controls tracking between characters.
- Line spacing units: With
w:lineRule="auto",w:lineis measured in 1/240ths of a line (240 = single, 360 = 1.5×, 480 = double). WithexactoratLeast, it is measured in twips (240 twips = 12 pt). - Line rule impact:
autois proportional to font size,exactfixes the line height and can cause overlap with large fonts, andatLeastsets a minimum that can expand. - Paragraph spacing collapse: Adjacent paragraphs do not simply add their spacing; the larger effective spacing is used.
- Before/after line precedence:
beforeLinesandafterLinestake precedence over distance-basedbeforeandaftervalues. - Twips: 1440 twips = 1 inch = 72 points; 20 twips = 1 point; 240 twips = 12 points.
- Line units:
beforeLinesandafterLinesexpress spacing in line multiples (fiftieths), which is more proportional than twips. - Character-width units: In
w:rPr,w:spacingis measured in twentieths of a point, not paragraph twips; it is applied uniformly and may affect kerning or ligatures. - Negative character spacing: Negative values compress characters and may cause overlap; use sparingly.
- Practical defaults: Body text commonly uses single spacing (
w:line="240" w:lineRule="auto") or 1.15 spacing (w:line="276" w:lineRule="auto"). - Performance: Excessive character spacing or very tight spacing can affect rendering and readability.
- Accessibility: Adequate line spacing (1.5× or more) can improve readability; very tight or loose spacing reduces readability.
- Localization: Spacing requirements vary by language and culture; test with the target audience.
- Print and screen: Rendering may vary between screen and print; test both. Line spacing generally renders consistently across printer types.
- Compatibility: Standard line spacing is supported across Office versions; newer values such as
beforeLinesmay not render in legacy versions.