Box Model and Positioning
Every block is drawn as a CSS box: its content, the padding around it, the border, and the margin outside. These are
the keys of a style that size that box, space it, take it out of the flow, and place it
or its content. Borders and outlines are on Borders, backgrounds and clip paths on
Colour and paint. Two families of box keys are told beside the content they shape: the keys that flow a
block's content through columns (columnCount, columnWidth, columnGap, columnFill, columnSpan) on
Columns, and the keys that steer where a page or a column divides a box
(breakBefore, breakAfter, breakInside, orphans, widows) and what its border does there
(boxDecorationBreak) on Breaks and pagination.
A length is a number of points, or a string with a unit pt, in, mm or px ("4mm", "0.5in").
Margins and padding
| Key | Takes | Default | What it does |
|---|---|---|---|
margin | one to four lengths, negative allowed | Space outside the box, every side at once. | |
marginTop, marginRight, marginBottom, marginLeft | a length, negative allowed | 0 | Space outside the box on one side; a negative top margin pulls the box up. |
padding | one to four lengths | 0 | Space inside the box, between its border and its content, every side at once. |
paddingTop, paddingRight, paddingBottom, paddingLeft | a length | 0 | Space inside the box on one side. |
collapsingMargins | true, false | false | Whether this block's top margin collapses into the bottom margin of the block before it. |
The string form of margin and padding is CSS's shorthand, written as you would write it in a stylesheet:
| Form | Meaning |
|---|---|
"4" | All four sides 4 |
"4 8" | Top and bottom 4, left and right 8 |
"4 8 6" | Top 4, left and right 8, bottom 6 |
"4 8 6 2" | Top 4, right 8, bottom 6, left 2, clockwise from the top |
4 | A bare number: the same as "4" |
Each length may carry its unit: "6pt 12pt", "2mm 4mm". Keys apply in the order written, so a side key after the
shorthand overrides that side, and a shorthand after a side key replaces it:
{
"styles": {
"callout": { "padding": "6 12", "paddingLeft": 24, "backgroundColor": "#f3f4f6", "margin": "12 0" }
},
"content": [
{ "p": "Top and bottom 6, right 12, left 24.", "style": "callout" }
]
}
Adjoining margins
Unset, the bottom margin of one block and the top margin of the next add up, as every document written for this engine
expects. With collapsingMargins: true on the second block they collapse as CSS 2.1 8.3.1 has it: the larger wins, a
negative margin is taken from it, and an empty block with no border or padding lets them collapse through it. A border
between them keeps them apart. At a page boundary a collapsed margin is dropped after a break the layout chose, and kept
after a forced one.
{
"styles": {
"card": { "backgroundColor": "#dbeafe", "padding": 8, "marginTop": 24, "marginBottom": 24 },
"snug": { "backgroundColor": "#dbeafe", "padding": 8, "marginTop": 24, "marginBottom": 24, "collapsingMargins": true }
},
"content": [
{ "p": "First card.", "style": "card" },
{ "p": "48pt above: the two margins add.", "style": "card" },
{ "p": "24pt above: the two margins collapse.", "style": "snug" }
]
}
Width and height
| Key | Takes | Default | What it does |
|---|---|---|---|
width | a length | Width of the box: sets both its least and its most width. | |
height | a length | Height of the box: sets both its least and its most height. | |
minWidth, maxWidth | a length | The least and the most width the box takes. | |
minHeight, maxHeight | a length | The least height the box takes however little it holds, and the most it may take; content past maxHeight overflows as overflowY says. | |
boxSizing | contentBox, borderBox | contentBox | What the sizes measure: the content alone, the padding and border outside it (contentBox), or the whole box (borderBox). A table starts at borderBox, as HTML's stylesheet has it. |
A box narrower than its container stands at the start of the line; justifySelf
moves it. A width or minWidth wider than the container is held to the container, and a NOTICE names the key: a
page has no scroll for the overflow to go to. A table cell's height holds its row, measured as the cell's border box
unless its style says contentBox.
{
"styles": {
"content": { "width": 240, "padding": 10, "border": "4pt solid #1e3a5f" },
"whole": { "width": 240, "padding": 10, "border": "4pt solid #1e3a5f", "boxSizing": "borderBox" }
},
"content": [
{ "p": "268 points wide: its padding and border are outside the 240.", "style": "content" },
{ "p": "240 points wide, padding and border included.", "style": "whole" }
]
}
Overflow
| Key | Takes | Default | What it does |
|---|---|---|---|
overflowX | visible, hidden, clip, scroll, auto | visible | Content past the box's padding edge across: visible draws it, every other value cuts it there. |
overflowY | the same | visible | Content past the padding edge downward, as overflowX. |
A page does not scroll, so hidden, scroll and auto all cut at the padding edge, and, as CSS Overflow 3 has it,
setting one of them on one axis cuts the other axis too; clip cuts only its own. With a maxHeight the content
exceeds, a cutting overflowY holds the box to that height and a NOTICE says how tall it wanted to be, where
visible draws everything and warns. A line wholly under the cut is not written at all, so a link or a field there
does not stay live over what lies below; the links, fields and notes cut away are named. A table reports the key as not
applied.
{
"styles": {
"teaser": { "maxHeight": 40, "overflowY": "hidden", "padding": 6, "border": "1pt solid #b91c1c" }
},
"content": [
{ "p": "A long abstract held to forty points of content. The survey covered the north quay, the slipway and the two pontoons, and found the timber sound but the fixings corroded along the whole of the east face. Replacement is recommended before the winter storms, with the slipway closed for three weeks while the work is done. The lines past the box's padding edge are cut away at the inside of the red border, and the report says how tall the box wanted to be.", "style": "teaser" }
]
}
Placing a block across its container
| Key | Takes | Default | What it does |
|---|---|---|---|
justifySelf | start, center, end, left, right, selfStart, selfEnd, flexStart, flexEnd, auto, normal, stretch | auto | Where a block narrower than its container sits across it, as CSS Box Alignment's justify-self. auto, normal and stretch mean start. |
start and end follow the container's direction; selfStart and selfEnd follow the block's own direction, so a
right-to-left block with selfStart sits at the right of a left-to-right page. Written, justifySelf wins over
textAlign for an image or an svg.
{
"styles": {
"againstEdge": { "justifySelf": "end", "maxWidth": 220, "backgroundColor": "#eef2f7", "padding": "5 8" }
},
"content": [
{ "p": "A 220-point note against the end edge, still in the flow.", "style": "againstEdge" }
]
}
Floats
| Key | Takes | Default | What it does |
|---|---|---|---|
float | none, left, right | none | Takes the block out of the flow to the left or right edge; the lines after it run past its side. |
clear | none, left, right, both | none | Puts the block below the floats on the side it names. |
As in CSS 2.1 9.5, a float is drawn where the flow stands and takes no room in it: the paragraph after it begins level
with the float's top, its lines stop short of the float and run the full measure again below it. A float is as wide as
its style's width, or else as its content unbroken, plus its padding and border. A float cannot split: one that does
not fit the rest of the page moves to the next page whole. Inside a cell or a column, it shortens the lines of that box
alone.
{
"styles": {
"sidenote": { "float": "left", "width": 150, "padding": "8 10", "marginRight": 12, "marginBottom": 8,
"fontSize": 9, "color": "#1e3a5f", "backgroundColor": "#eef2f7" },
"after": { "clear": "both", "borderTop": "1pt solid #9ca3af", "paddingTop": 6 }
},
"content": [
{ "p": "A note the text runs past.", "style": "sidenote" },
{ "p": "This paragraph begins level with the note's top. Its first lines stop short of the note's right edge, and once the note has ended its lines run the full measure of the page again, as text runs past a floated box in a browser." },
{ "p": "This one clears both sides, so it starts below every float.", "style": "after" }
]
}
Positioned blocks
| Key | Takes | Default | What it does |
|---|---|---|---|
position | static, relative, fixed | static | In the flow (static), shifted from where the flow puts it (relative), or at page coordinates and out of the flow (fixed). |
left, top | a length, negative allowed | Under relative, the shift right and down. Under fixed, the distance from the page's left and top edges. | |
right, bottom | a length, negative allowed | Under relative, the shift left and up. Under fixed, the distance from the page's right and bottom edges. | |
pageNumber | a whole number | 1 | The page a fixed block is drawn on. |
relative moves what the block draws and nothing else: the block after it starts where it would have anyway.
Where both left and right, or both top and bottom, are given, the start side wins and a NOTICE says the other
was ignored (CSS Position 3 3.3). Under static, the offsets do nothing and are reported.
fixed draws the block at page coordinates and reserves no room in the flow. With no offsets it stands 100 points
from the left edge and 150 from the bottom. Its width and height are its content's, the padding and border around
them as anywhere else. With no width, it fills what left and right leave between them, or beside one of them fits its
text; with no height, it fills what top and bottom leave, or is as tall as its content. An image or svg keeps its own
size. Given left, right and a width, right is ignored, and bottom likewise beside top and a height. A pageNumber past the last page draws the block on the last page, with a WARNING.
Unlike CSS paged media, where a fixed box repeats on every page, the block is drawn once; a mark on every page is a
watermark.
{
"styles": {
"stamp": { "position": "fixed", "top": 40, "right": 40, "width": 170, "boxSizing": "borderBox",
"border": "1pt solid #7f1d1d", "padding": "5 8", "fontWeight": "bold", "color": "#7f1d1d" },
"nudged": { "position": "relative", "left": 24, "top": 6, "color": "#1e3a5f" }
},
"content": [
{ "p": "ASSESSED - claim 2026-0417", "style": "stamp" },
{ "p": "This paragraph starts at the top of the page: the stamp above took no room in the flow." },
{ "p": "Shifted 24 points right and 6 down from its place in the flow.", "style": "nudged" },
{ "p": "And this one starts where it would have anyway." }
]
}
Links and form fields inside a moved block move with it. A block in a header, a footer or a watermark is not pinned by
fixed, and a table cell is never moved out of its row and column; the report says so in both cases.
Placing content inside a box
| Key | Takes | Default | What it does |
|---|---|---|---|
alignContent | normal, start, center, end | normal | Where the content sits down a box taller than it (one with a height or a minHeight), as CSS's align-content: normal and start at the top, center, or end at the bottom. On a table cell it replaces verticalAlign. |
verticalAlign | top, middle, bottom, baseline | baseline | Where a table cell's content sits in its box; baseline lines up the first baselines of the row's cells, and a cell of blocks sits at its top. |
alignContent acts on a paragraph or a heading, a table cell, the box beside a list, and a columns node. A box as tall
as what it holds - a table of contents, a list's own style, a watermark - has no room to place anything in, and the
report says so.
{
"styles": {
"tide": { "height": 76, "width": 170, "padding": "0 10", "backgroundColor": "#dbe4f0",
"fontSize": 13, "fontWeight": "bold", "alignContent": "center" },
"foot": { "height": 76, "backgroundColor": "#dbe4f0", "alignContent": "end" }
},
"content": [
{ "h2": "High water 08:25", "style": "tide" },
{ "table": { "rows": [ [ { "td": "Berth" }, { "td": "Quay 4", "style": "foot" } ] ] } }
]
}
Columns in a row
| Key | Takes | Default | What it does |
|---|---|---|---|
alignItems | normal, stretch, start, end, center, baseline, firstBaseline, selfStart, selfEnd, flexStart, flexEnd | normal | Where each column of a columns block sits down its row, written on the columns node's style: normal stretches, baseline lines up the first baselines. |
alignSelf | auto and the same values | auto | One column's own placement, over alignItems. Written on the column's style node, { "style": name } first in the column. |
{
"styles": {
"row": { "alignItems": "center" },
"foot": { "alignSelf": "end" }
},
"content": [
{ "columns": { "style": "row", "rows": [
[ { "p": "A tall first column, three lines of text so that the row has height for the others to be placed in." } ],
[ { "p": "Centred in the row." } ],
[ { "style": "foot" }, { "p": "At the foot of the row." } ]
] } }
]
}
Where a key cannot act
A key a node's kind cannot act on is not refused; the render report names it once per style and kind, with the rule that decides it. The ones an author meets:
| Key | Does nothing on | Why |
|---|---|---|
the bounds minWidth, maxWidth, minHeight, maxHeight, margins, padding, boxSizing, float, clear, overflowX, overflowY, position and its offsets | svg shapes and svg text | a shape has no CSS box: its place and size are its own geometry (SVG 2 Chapter 7), and svg text takes only the keys that pick its glyphs and set its lines (SVG 2 11.10) |
width, height | svg text, and a shape other than a rect | they size a rect alone, over its own width and height (SVG 2 7.8) |
margins, justifySelf, clear, alignSelf, collapsingMargins | a table cell | a cell's place is its row and column |
alignItems | any node but a columns node | nothing else holds columns; this one is not reported |
justifyContent | any node but a columns node standing side by side | it places a grid's tracks; on a column flow a NOTICE says so |
alignSelf, verticalAlign | a columns node's own style | they belong on a column's style node and on a cell |
alignContent | a table, an image, an svg | none of them has room of its own to place content in |
columnCount, columnWidth, columnGap, columnFill | a table, an image, an svg | none of them is flowed through columns; see Columns |
objectFit | text, a list, a table, a rule, a columns node | it fits a picture to its box; see Images |
A list's own style draws no box: the box is the style on the node beside the list (see A style beside a list or a table).
In a DOCX
| Key | In the DOCX |
|---|---|
float | A floated paragraph is a Word text frame, its box the float's border box and its margins the frame's distance from the text; a float whose box is a fill inside a border is a floating table. Both stand within about a point of the PDF's. |
clear | Has no form in WordprocessingML, and is reported. |
overflowX, overflowY | WordprocessingML has no clip on a paragraph or a cell: the content is drawn in full and the key is reported. A maxHeight that is not cut is reported too. |
height on a table or an svg | Not carried, and reported. |
position: fixed | A text box anchored to the page by its bottom edge. |
position: relative | A paragraph moves by its indents and lowered runs; any other block that is shifted is reported. |
collapsingMargins | Not carried on a list, and reported. |