Microtypography and the -bag properties
The engine exposes a handful of controls that plain CSS does not
know. They all carry the -bag- prefix, cascade and inherit like
normal properties, and are safe to leave in stylesheets that are also
used in browsers (unknown properties are ignored there).
Font expansion
Justification usually has only the word spaces to work with. Font expansion (the hz-program idea) additionally lets the glyphs themselves stretch or shrink by a small percentage, which evens out word spacing and helps the line breaker find better breaks. It is on by default at 5%; the percentage is the maximum change of a glyph’s width:
body { -bag-font-expansion: 0%; } /* switch it off */
body { -bag-font-expansion: 2%; } /* more conservative than the default */
At sane values (2 to 5 percent) the distortion is invisible at reading distance; what remains visible is the calmer word spacing.
Font expansion only acts on justified text (text-align: justify).
Ragged text, which includes the default text-align: start, is set
at its natural width: neither the glyphs nor the word spaces are
squeezed, and a word that does not fit moves to the next line.
Line breaker tuning
Two knobs steer the paragraph breaker directly:
blockquote { -bag-linebreak-tolerance: 8; }
th { -bag-linebreak-hyphen-penalty: 200; }-bag-linebreak-tolerance(default 4) is how far the spaces of a line may stretch, as a multiple of their stretchability, before the breaker refuses the line. It is a ratio, not a badness as TeX’s\tolerance: TeX’s 200 is about 1.26. Raise it for very narrow measures (table cells, margin columns) where the default finds no acceptable break and lines come out overfull; the price is looser word spacing. A value below 1 also limits shrinking: the spaces may then shrink by at most that fraction of their shrinkability.-bag-linebreak-hyphen-penaltymakes hyphenated line ends more expensive. Raise it to hyphenate less without forbidding hyphenation outright (hyphens: nonedoes that); it is the gentler tool because emergencies can still hyphenate. A value of 10000 or more forbids breaks at hyphens altogether, soft hyphens included.
Reference: all -bag properties
| Property | Effect | Details |
|---|---|---|
-bag-leading-model |
half (CSS, default) or trailing (TeX): where the leading of a line goes. |
Lines and leading |
-bag-font-expansion |
Maximum glyph width change for justification, default 5%. |
this page |
-bag-linebreak-tolerance |
How far a line’s spaces may stretch, as a multiple of their stretchability, default 4. | this page |
-bag-linebreak-hyphen-penalty |
Extra cost of a hyphenated line end. | this page |
-bag-horizontal-scale |
Draws glyphs narrower or wider by a fixed factor, default 100%. |
Letterforms |
-bag-italic-correction |
auto inserts kerns at italic-to-upright boundaries, none (default) does not. |
Letterforms |
-bag-bookmark |
Adds any element to the PDF outline, or removes a heading from it. | PDF bookmarks |
-bag-background-page |
Uses an image or PDF page as the page background in @page rules. |
how-to: letterhead |
-bag-float-gutter |
Space between a float and the text beside it where the float has no margin on that side, default 9pt. |
how-to: image runaround |
-bag-text-box-trim-at-break |
trim-end trims the last line before an unforced break to its text. |
Lines and leading |
-bag-tab-stops |
Tab stops for tab characters in the text, with alignment and leaders. | how-to: tab stops |
-bag-fixed-height |
Makes a table row exactly this high; it never breaks inside. | CSS properties |
-bag-line-breaker |
Chooses a line breaker that a Go program registered; glu alone has none besides the default Knuth-Plass. | htmlbag library |
-bag-trace |
boxmodel draws the box model overlay on the matched elements only. |
Debugging |