CSS properties reference
Every CSS property htmlbag reads, with the values it accepts. The list is generated from the code, so it is complete for the htmlbag version the site documents. Both bagme and glu render through htmlbag and support the same set. How stylesheets reach the renderer, and the reasoning behind page rules, counters and running elements, is on the CSS support page.
Lengths take pt, mm, cm, in, px, pc, em, rem, ex and ch. Percentages are relative to the font size or the containing block as in CSS. Colors are CSS colors (#rgb, #rrggbb, rgb(), named colors) or a name defined with @-bag-color.
Text
| Property | Values | Example |
|---|---|---|
font-family |
Font family name or a comma separated list. A list falls back per glyph, the first family that has the glyph renders it | font-family: "Minion Pro", serif; |
font-size |
Length, em, %, the keywords xx-small to xxx-large, smaller and larger |
font-size: 12pt; |
font-weight |
normal, bold, bolder, lighter, the names thin to black, or a number from 100 to 900 |
font-weight: 600; |
font-style |
normal, italic. oblique is not recognized |
font-style: italic; |
font-synthesis-style |
auto, none. auto slants a family’s upright for an italic it lacks; the default is none, where the upright is used as it is |
font-synthesis-style: auto; |
font-synthesis |
none, or any of weight, style, small-caps, position. Only style and small-caps are read, as font-synthesis-style and font-synthesis-small-caps |
font-synthesis: style; |
font-synthesis-small-caps |
auto, none. auto (the default) sets small caps for a face without smcp as capitals at 70% of the size; none leaves the text as it is. Synthesized small caps are capitals in the PDF, so text extraction and search see SMALL CAPS, not Small Caps; a face with smcp keeps the original text |
font-synthesis-small-caps: none; |
font-variant-caps |
normal, small-caps. Inherited. The face’s smcp feature when it has one, else synthesized (see font-synthesis-small-caps). Other values are read as normal |
font-variant-caps: small-caps; |
font-variant |
normal, or values including small-caps. Only small-caps is read, as font-variant-caps |
font-variant: small-caps; |
font |
Shorthand: optional font-style, small-caps and font-weight, then the size with an optional /line-height, then the family. Style, caps, weight and line height reset to normal when omitted, as in CSS. Size and family are required |
font: italic bold 10pt/12pt serif; |
font-feature-settings |
Comma separated OpenType feature tags, each optionally followed by on, off or a number. normal removes all features |
font-feature-settings: "smcp", "onum"; |
font-variation-settings |
Comma separated pairs of an axis tag and a number, for variable fonts | font-variation-settings: "wght" 650; |
color |
Color value or a defined color name | color: #333; |
text-align |
left, right, center, justify, start, end |
text-align: justify; |
text-box |
normal, or a text-box-trim and a text-box-edge value. Shorthand; without a trim value it is trim-both |
text-box: trim-both text; |
text-box-edge |
auto, text. The edges a block’s lines are trimmed to: the block’s font’s text-over and text-under edges, its content area. Other edges warn and use text |
text-box-edge: text; |
text-box-trim |
none, trim-start, trim-end, trim-both. Not inherited. Takes the space above the block’s font’s text-over edge off its first line and below its text-under edge off its last line, such as half-leading, so the block’s box ends at its text. Lines set tighter than the content area make the block grow to its text. Split across pages, only the first fragment’s start and the last fragment’s end are trimmed under box-decoration-break: slice; under clone every fragment of a paragraph is, so the last line before a break may fit by its text. On a container of other blocks, the first and last line are those of its first and last block, through nested containers, unless padding or a border lies between. A table cell is such a container too, and a table in a container holds none of its lines |
text-box-trim: trim-both; |
text-indent |
Length, indents the first line | text-indent: 1em; |
text-decoration |
Shorthand for line, style and color | text-decoration: underline dotted red; |
text-decoration-line |
none, underline, overline, line-through |
text-decoration-line: underline; |
text-decoration-style |
solid, double, dotted, dashed, wavy |
text-decoration-style: wavy; |
text-decoration-color |
Color value | text-decoration-color: red; |
line-height |
normal, a number (factor of the font size) or a length |
line-height: 1.4; |
letter-spacing |
normal or a length |
letter-spacing: 0.05em; |
white-space |
normal, nowrap, pre, pre-wrap, pre-line |
white-space: pre; |
hyphens |
auto, manual, none. manual and none both switch the language patterns off, soft hyphens (U+00AD) stay break opportunities |
hyphens: none; |
hanging-punctuation |
none, allow-end |
hanging-punctuation: allow-end; |
vertical-align |
baseline, sub, super, top, text-top, middle, bottom, text-bottom, a length or a percentage of the line height. Under a line model registered with CSSBuilder.RegisterLineModel, the shift of sub, super, a length or a percentage is passed to the model, which may grow the line with it |
vertical-align: super; |
direction |
ltr, rtl |
direction: rtl; |
unicode-bidi |
normal, embed, isolate, bidi-override, isolate-override, plaintext |
unicode-bidi: isolate; |
tab-size |
Number of spaces or a length | tab-size: 4; |
initial-letter |
Number of lines for a drop cap, or normal, see Dropcaps |
initial-letter: 3; |
user-select |
Any value. Accepted and ignored, there is no selection in PDF | user-select: none; |
Box model
| Property | Values | Example |
|---|---|---|
margin |
One to four lengths, shorthand for the four sides | margin: 10pt; |
margin-top, margin-right, margin-bottom, margin-left |
Length | margin-top: 12pt; |
padding |
One to four lengths, shorthand for the four sides | padding: 5pt 10pt; |
padding-top, padding-right, padding-bottom, padding-left |
Length | padding-left: 10pt; |
padding-inline-start |
Length. Maps to padding-left for ltr and to padding-right for rtl |
padding-inline-start: 2em; |
width |
Length or percentage, on blocks, images and table cells | width: 100%; |
height |
Length, on blocks, images, table rows and table cells. A minimum: content taller than the height is never clipped, a table row grows to fit its cells | height: 4cm; |
max-width |
Length or percentage, on images | max-width: 100%; |
object-view-box |
none, or inset() with one to four lengths or percentages, on images (<img>, also with an SVG or PDF source). Not inherited. The region becomes the image’s natural size and aspect ratio, and width, height and max-width size it as they size a whole image. xywh() and rect() are not supported and warn, as do the round corners of inset(), which are ignored. A bitmap’s natural size is one point per pixel, as for its sizing, so inset(10pt) takes 10 pixels off each edge. Not read on an inline <svg> |
object-view-box: inset(10% 20%); |
background-color |
Color value, painted on block elements, inline elements and table cells | background-color: #ffffcc; |
background |
Shorthand, only the color is read | background: #ffffcc; |
display |
block, inline, none. Other values are ignored, the table parts follow from the HTML tags |
display: none; |
Borders
| Property | Values | Example |
|---|---|---|
border |
Width, style and color in any order, all four sides | border: 1pt solid black; |
border-top, border-right, border-bottom, border-left |
Width, style and color for one side | border-top: 2pt solid red; |
border-width |
One to four lengths or thin, medium, thick |
border-width: 1pt 0; |
border-style |
One to four border styles | border-style: solid none; |
border-color |
One to four colors | border-color: red black; |
border-top-width, border-right-width, border-bottom-width, border-left-width |
Length | border-left-width: 3pt; |
border-top-style, border-right-style, border-bottom-style, border-left-style |
none, solid. Every other CSS border style is drawn as solid |
border-left-style: solid; |
border-top-color, border-right-color, border-bottom-color, border-left-color |
Color value | border-left-color: red; |
border-radius |
One length, the same for all four corners. Several values, one per corner, are not supported | border-radius: 3pt; |
border-top-left-radius, border-top-right-radius, border-bottom-right-radius, border-bottom-left-radius |
Length | border-top-left-radius: 3pt; |
border-collapse |
separate (the default, as in CSS), collapse; on tables |
border-collapse: collapse; |
border-spacing |
One or two lengths, on tables in the separated model; the default is 2pt | border-spacing: 4pt 2pt; |
Layout
| Property | Values | Example |
|---|---|---|
float |
left, right, none; inside and outside pick the side towards or away from the binding on the page the float lands on, with the declared margin-left/margin-right swapped on left pages; top (or before) and bottom (or after) lift the element out of the flow to the top or bottom of the page, see Inserts |
float: outside; |
clear |
left, right, inside, outside, both, none |
clear: both; |
position |
static, relative, absolute, running(name) for running elements that repeat in page margin boxes. fixed and sticky are not supported. A relative block is offset by left or right only; a relative inline element by top or bottom only, which moves its text after the lines are set |
position: absolute; |
top, right, bottom, left |
Length or auto, with position. On a relative inline element top wins over bottom, a percentage computes to auto, and left and right have no effect. The text and its background move; an underline stays where it was |
top: 1cm; |
z-index |
Integer or auto, with position |
z-index: 1; |
page-break-before, break-before |
auto, always, avoid; break-before also takes page, left, right, recto, verso and column. The page side variants break the page but do not pick a side. column starts the next column of a multi-column layout, and the next page after its last column; elsewhere it has no effect. A forced break is taken at any depth; on a block’s first child it applies to the block itself |
page-break-before: always; |
page-break-after, break-after |
Same values as page-break-before. A forced break is taken at any depth; on a block’s last child it applies to the block itself |
page-break-after: avoid; |
page-break-inside, break-inside |
auto, avoid. On a table row, auto lets the row break across pages; a row without the property stays whole, as with avoid |
page-break-inside: avoid; |
widows |
Positive integer, the default is 2; 1 switches the control off. Counts the lines of a paragraph, a list item or <pre>, also inside a container; the blocks of a container are not counted |
widows: 3; |
orphans |
Positive integer, the default is 2; 1 switches the control off. Counts as widows does |
orphans: 3; |
column-count |
auto (the initial value) or a positive integer. Laid out on body, or on a direct child of body without a border, a background or padding, whose siblings then span the columns. Every page holds that many columns side by side, filled one after the other, and the floats and footnotes of a column are placed in it at its width. On another element the content is set in one column, with a warning |
column-count: 2; |
columns |
Shorthand for column-width and column-count. Only the count is read, a width is ignored |
columns: 2; |
column-gap |
normal (1em, the initial value) or a length |
column-gap: 6mm; |
column-span |
none (the initial value), all. On a direct child of the element with column-count. The spanner stands below the tallest column before it, whose row is balanced, and the columns go on below it. Floats and footnotes inside a spanner are placed at the foot of the page, where the columns below do not make room for them |
column-span: all; |
column-fill |
balance (the initial value), auto; balance-all counts as balance. balance evens out the columns of the last page, auto fills them one after the other; the columns above a spanner are balanced either way. Floats and footnotes of a balanced row are placed at the foot of its columns. A row whose content starts in its last column stays full |
column-fill: auto; |
column-rule |
Shorthand for column-rule-width, column-rule-style and column-rule-color, as border. Drawn in the middle of the gap between two columns that both hold content, as high as the tallest column of the row. As with borders, solid is the only style drawn |
column-rule: 0.5pt solid gray; |
column-rule-width, column-rule-style, column-rule-color |
As border-width, border-style and border-color. The color defaults to the color of the element |
column-rule-color: #999; |
box-decoration-break |
slice (the initial value), clone. Not inherited. On a block split across pages or regions, clone gives every fragment the block’s padding and border on both sides, and its background. With text-box-trim on a paragraph, every fragment is trimmed. Applies to blocks and block containers; tables and inline boxes are not cloned |
box-decoration-break: clone; |
Lists and generated content
| Property | Values | Example |
|---|---|---|
list-style-type |
disc, circle, square, none, decimal, decimal-leading-zero, lower-alpha, upper-alpha, lower-latin, upper-latin, lower-roman, upper-roman, lower-greek |
list-style-type: lower-roman; |
list-style |
Shorthand for list-style-type and list-style-position |
list-style: square; |
list-style-position |
inside, outside. Accepted for compatibility, markers are always placed outside |
list-style-position: outside; |
counter-reset |
Counter name with an optional start value, repeated for several counters | counter-reset: section; |
counter-increment |
Counter name with an optional step, repeated for several counters | counter-increment: section; |
content |
On ::before, ::after, ::marker and in page margin boxes: strings, attr(), counter(), counters(), target-counter(), target-counters(), target-text(), element(), leader(). The counter functions take a counter style as their last argument, see Cross-references for the target functions |
content: counter(section, upper-roman) ". "; |
Custom properties
| Property | Values | Example |
|---|---|---|
-bag-font-expansion |
Percentage of allowed glyph stretching, 0% turns it off. Only justified text uses it; ragged text is set at its natural width |
-bag-font-expansion: 0%; |
-bag-horizontal-scale |
A positive percentage or number, 90% and 0.9 are the same, default 100%. Inherited. Draws the glyphs narrower or wider by a fixed factor (PDF horizontal scaling, Tz); the advances, kerns and spaces are scaled, so the line breaker sees the scaled width. The factor does not compound, 90% inside 90% stays 90%, so an element inside a scaled one returns to normal with 100%. letter-spacing is not scaled, it stays an absolute length. Font expansion applies on top. Zero, negative or unparsable values are ignored with a warning |
-bag-horizontal-scale: 90%; |
-bag-italic-correction |
auto, none |
-bag-italic-correction: none; |
-bag-line-breaker |
auto (Knuth-Plass, the default) or a name registered with CSSBuilder.RegisterBreaker. Chooses where a paragraph breaks among its legal breakpoints; the lines are measured and set as with Knuth-Plass. Inherited. An unregistered name keeps Knuth-Plass and logs a warning once |
-bag-line-breaker: greedy; |
-bag-leading-model |
half (CSS line boxes, the default), trailing (TeX style), or a name registered with CSSBuilder.RegisterLineModel. An unregistered name keeps the built-in leading and logs a warning once |
-bag-leading-model: trailing; |
-bag-linebreak-tolerance |
Number, the largest adjustment ratio a line may have, default 4. How far the spaces of a line may stretch, as a multiple of their stretchability. A ratio, not a badness as TeX’s \tolerance: TeX’s 200 is about 1.26 |
-bag-linebreak-tolerance: 8; |
-bag-linebreak-hyphen-penalty |
Number, the TeX hyphen penalty | -bag-linebreak-hyphen-penalty: 200; |
-bag-tab-stops |
none, or a comma separated list of stops: a length or percentage of the line width, optionally start, end, center, decimal or decimal(","), optionally leader(" . ") (or dotted, solid, space). Inherited. A tab advances to the next stop past the text before it, left and right are synonyms of start and end. Tabs within a line survive any white-space mode, whitespace with a newline stays source formatting |
-bag-tab-stops: 12mm, 100% end leader(dotted); |
-bag-fixed-height |
Length, or none (the default). On table rows only, not inherited. The row is exactly this high and never breaks inside: content that does not fit draws past the row, background and borders keep the height. Wins over height on the same row, and a cell’s height in a fixed row is ignored. On a cell the property has no effect |
-bag-fixed-height: 16pt; |
-bag-float-gutter |
Non-negative length, default 9pt. Inherited. The space between a float and the text beside it where the float declares no positive margin on the side of the text; a declared margin replaces it. margin: 0 cannot be told from no margin, so -bag-float-gutter: 0 is how to get a browser’s spacing |
-bag-float-gutter: 0; |
-bag-text-box-trim-at-break |
none (the default), trim-end. Not inherited. At an unforced break, the last line of the block before it may fit by its text: the space below its font’s text-under edge (as text-box-trim: trim-end takes off) is trimmed there. Nothing else changes: the block keeps its height where it ends mid-page, its first line is not trimmed, and its decorations are not repeated. A negative trim (lines set tighter than the content area) gains no room and is left alone. Under box-decoration-break: clone with text-box-trim: trim-end, which trims every fragment of a paragraph already, it changes nothing. Applies only to a block that holds its own lines |
-bag-text-box-trim-at-break: trim-end; |
-bag-trace |
boxmodel or none (the default). Not inherited. Paints the box model overlay (margin, border, padding and content) on the matched elements only, as the global box model trace does on every block. none turns it off again in a more specific rule; it cannot turn off the global trace |
-bag-trace: boxmodel; |
-bag-bookmark |
none, or a level number optionally followed by open or closed, see PDF bookmarks. Adds the element to the PDF outline |
-bag-bookmark: 2 closed; |
Selectors
The CSS3 selector grammar is supported, see selector support.
@-rules
@page
Sets the page geometry. The pseudo-classes :first, :left and :right cascade over the plain @page rule, see per-page rules.
| Property | Values | Example |
|---|---|---|
size |
A paper name (a0 to a8, b0 to b8, jis-b4, jis-b5, letter, legal, ledger) with optional portrait or landscape, or width and height as two lengths |
size: a4 landscape; |
margin |
One to four lengths, the page margins | margin: 2cm 1.5cm; |
margin-top, margin-right, margin-bottom, margin-left |
Length, one page margin | margin-left: 3cm; |
border, border-top, border-right, border-bottom, border-left, border-width, border-style, border-color, border-radius |
As on elements, drawn around the page content area on every page | border-left: 4pt solid navy; |
padding, padding-top, padding-right, padding-bottom, padding-left |
Length, space between the page border and the content | padding: 5mm; |
background-color |
Color value, fills the sheet. Painted on the first page only | background-color: #fafafa; |
background-image |
url() of an image or PDF file, scaled to the full sheet on every page that uses this @page rule |
background-image: url("letterhead.pdf"); |
-bag-background-page |
Page number of a multi page PDF used as background-image, the default is 1 |
-bag-background-page: 2; |
The margin boxes @top-left-corner, @top-left, @top-center, @top-right, @top-right-corner, @left-top, @left-middle, @left-bottom, @right-top, @right-middle, @right-bottom, @bottom-left-corner, @bottom-left, @bottom-center, @bottom-right and @bottom-right-corner are nested in the @page rule. They take content, width, height and the text and border properties above, see page margin boxes.
@font-face
Defines a font face. The descriptors are:
| Property | Values | Example |
|---|---|---|
font-family |
The name the font is used by | font-family: "Minion Pro"; |
font-style |
normal, italic |
font-style: italic; |
font-weight |
A weight name or number, or two of them for the range a variable font covers | font-weight: 300 700; |
src |
Comma separated list of url() or local() sources, each optionally followed by format() and tech() |
src: url("minion.otf"); |
font-feature-settings |
OpenType features switched on for this face, as on elements | font-feature-settings: "onum"; |
font-variation-settings |
Axis values of a variable font, as on elements | font-variation-settings: "wght" 450; |
size-adjust |
Percentage that scales the glyphs of this face | size-adjust: 95%; |
ascent-override |
normal or a percentage of the em, in place of the face’s ascent. Read only by a line model registered with CSSBuilder.RegisterLineModel (see -bag-leading-model); the built-in half and trailing models do not use it |
ascent-override: 107.91%; |
descent-override |
normal or a percentage of the em, in place of the face’s descent. Read only by a line model registered with CSSBuilder.RegisterLineModel (see -bag-leading-model); the built-in half and trailing models do not use it |
descent-override: 25.1%; |
line-gap-override |
normal or a percentage of the em, in place of the face’s line gap. Read only by a line model registered with CSSBuilder.RegisterLineModel (see -bag-leading-model); the built-in half and trailing models do not use it |
line-gap-override: 0%; |
@-bag-color
Defines a named color, see named colors. The color name follows the at-rule, the descriptors are:
| Property | Values | Example |
|---|---|---|
model |
cmyk, rgb, RGB, gray, GRAY, spotcolor. Upper case RGB and GRAY take components from 0 to 255, lower case from 0 to 100 |
model: cmyk; |
value |
A CSS color such as #ff0000 or rgb(255, 0, 0), used instead of a model with components |
value: #c00; |
colorname |
Name of the separation for a spot color | colorname: PANTONE 300 C; |
c, m, y, k, r, g, b |
Number, one component of the chosen model | c: 100; |