CSS inline box 2026-11-05
A CSS inline box is the box generated by an inline CSS non-replaced element, such as a text element styled with
display:inline. It participates in a CSS inline formatting context. When line breaking splits its content, fragments can occur on several CSS line boxes.[ref]For vertical line layout, its
line-height and the CSS leading calculation determine its allocated extent. A child can contribute a taller box to the same CSS line box without changing the parent's own allocated height. For example, take a parent with line height 14 CSS pixels and baseline extents 10 above and 4 below. A child with line height 24 and extents 17 above and 7 below enlarges the enclosing line to 24 CSS pixels, assuming the CSS strut adds no greater extent. The parent's 14-CSS pixel allocation and the final 24-CSS pixel line describe different boxes.[ref]Visual formatting model details in CSS 2.2 by W3C. §10.8.1, inline-box height and independent contributions of child boxes
The
height property does not supply a preferred height for a non-replaced CSS inline box; height:40px on such a text element therefore does not replace this line-layout calculation. The properties determining a CSS preferred size have different applicability from line-height.[ref]CSS Box Sizing Module Level 3 by World Wide Web Consortium. §3.1.1, applicability of preferred width and height properties
CSS line box 2026-11-05
A CSS line box is the rectangular region containing the inline content of one line in a CSS inline formatting context. The browser fits successive inline content into lines, using line breaking when necessary, then uses CSS vertical alignment to determine each line's extent. A CSS inline box supplies one contribution to this enclosing region.[ref]
For ordinary baseline-aligned text, the CSS leading calculation supplies each contribution's height above and depth below the text baseline. Include the CSS strut among those contributions. Enclosing them requiresFor example, extents and CSS pixels produce a line of CSS pixels, although the individual extents sum to 14 and 20. The largest upper extent and largest lower extent can come from different contributions. The CSS leading diagram illustrates the same geometry with another pair of hypothetical metrics.
A CSS replaced element, such as an inline image, contributes according to its CSS margin box; it need not follow the text's line height. Other settings of CSS vertical alignment require additional positioning rules. These effects explain why a line's final height can exceed the
line-height declared on its surrounding CSS block container.[ref]Visual formatting model details in CSS 2.2 by W3C. §10.8, sizing and vertical alignment of inline-level boxes
Discretionary break 2026-11-05
A discretionary break describes an optional line breaking choice whose printed material may depend on whether the break is selected. In TeX,
\discretionary{pre}{post}{none} supplies material before a chosen break, after it, or in the unbroken case.[ref]TeX source code by Donald E. Knuth. disc_node: pre_break, post_break and replacement material
For a purely mechanical example,
ab\discretionary{-}{X}{Y}cd can produce abYcd without the break, or ab- followed on the next line by Xcd when it is selected. The arbitrary strings make all three branches visible. A common hyphenation case simply inserts a hyphen before the break and supplies no material afterward.Each alternative has its own geometry. A typesetting box used only in the pre-break branch must contribute its width when that branch is tested. The natural line width, typesetting glue and typesetting penalty calculation must therefore use the selected representation. Treating the choice merely as an invisible marker could miss the width of the inserted hyphen.
First-line indentation 2026-11-05
First-line indentation shifts the beginning of the first formatted line of a text paragraph relative to its normal starting edge. In a left-to-right layout, a positive indent reserves space on the left; the corresponding starting edge is on the right in a right-to-left layout. In CSS,
text-indent controls this placement.[ref]Text in Cascading Style Sheets Level 2 Revision 2 by World Wide Web Consortium. §16.1: first formatted line, starting edge and indentation
In a simple left-to-right column of width with indentation , the first line begins at and has available typesetting line width . Later lines can begin at and use all 40 units. A negative indent instead places the start at , extending into the margin if no other layout constraint intervenes.
This changes the first line's geometry without adding printable glyphs. Replacing the indent by several stored spaces would couple the result to word spacing, white-space processing and the chosen computer font. A line breaking model can represent the change explicitly through its sequence of typesetting line widths.
Greedy line breaking 2026-11-05
Greedy line breaking commits each line after filling it with the longest available fitting prefix of the remaining input. In a fixed-width model, the input consists of ordered, indivisible typesetting boxes, a common typesetting line width , and nonnegative fixed word spacing. Assume every individual box fits. The greedy algorithm scans forward, adds the next item if it fits, and otherwise starts a new line. Incrementally maintaining the used width gives time complexity for input boxes.
This rule minimizes the number of lines under these assumptions. To see why, let be the last item covered by the first greedy lines, and the last item covered by the first lines of any feasible alternative. After a layout finishes, take its endpoint to remain for subsequent indices. The first greedy line reaches at least as far as the alternative's first line. Suppose . If the greedy layout has already reached , the next inequality is immediate. Otherwise, removing the alternative's already covered items from its next line leaves a fitting suffix, because widths and gaps are nonnegative. The next greedy line can reach at least that endpoint. By mathematical induction,Thus an alternative cannot finish in fewer lines.
Line count and paragraph appearance are different objectives. With widths , gap 1 and width 7, greedy grouping has lengths . The alternative also uses three lines. The line breaking with squared slack cost model assigns cost 20 to this alternative and 26 to the greedy layout when the final line is free. The line breaking diagram shows the two layouts. Global paragraph costs can justify dynamic programming even when greedy packing already uses the minimum line count.
The fixed-width assumptions matter when applying this result. Hyphenation introduces additional break opportunities, while adjustable typesetting glue changes how a candidate line fits. Those choices belong to richer layout models such as the Knuth-Plass line-breaking algorithm.
Hyphenation 2026-11-05
Hyphenation permits a word to be divided at an appropriate internal position during line breaking, usually displaying a hyphen when that division is taken. A hyphenation opportunity is a permitted choice, rather than an instruction to break every occurrence. The choice can help a narrow text paragraph fit without excessive word spacing.
A soft hyphen, Unicode U+00AD, marks such an optional position: in a suitable context,
ex followed by a soft hyphen and ample can display as example on one line or as ex- followed by ample on the next. The soft hyphen normally remains invisible when no split is taken. An always-visible hyphen already present in the word has different display behaviour.[ref]CSS Text Module Level 3 by World Wide Web Consortium. §5.3: conditional hyphens, visible hyphens and language-sensitive hyphenation
In CSS,
hyphens: manual uses explicit opportunities; hyphens: auto also permits opportunities supplied by a resource for the text's known language. The hyphenation resource and the line breaking algorithm answer different questions: where a split is linguistically allowed, and which allowed split best fits the layout. A discretionary break can also account for material inserted or replaced at the chosen split.[ref]CSS Text Module Level 3 by World Wide Web Consortium. §5.3: manual/auto values and content-language requirement
Hyphenation opportunity 2026-11-05
A hyphenation opportunity is a position where the language and chosen hyphenation rules permit a word to be divided across lines. An explicit soft hyphen can supply one; automatic hyphenation can find others using a language-appropriate resource. These permitted positions become choices for line breaking.[ref]
CSS Text Module Level 3 by World Wide Web Consortium. §5.3: explicit and automatic language-appropriate hyphenation opportunities
Two tests must then be applied. First, is the division permitted by the linguistic rules? Second, does the resulting geometry and cost make it a useful choice? If the material before a break has width 20, an inserted hyphen adds 2, and the available typesetting line width is 21, the resulting 22-unit line fails the rigid-width fitting test despite the linguistic permission.
A discretionary break represents the alternative printed material. The Knuth-Plass line-breaking algorithm can compare that option with later or earlier permitted breaks using typesetting badness and typesetting penalties.
Line breaking with squared slack cost 2026-11-05
Line breaking with squared slack cost is a simplified mathematical optimization model for paragraph layout. Treat the input as indivisible typesetting boxes with nonnegative widths , keep their order, use fixed word spacing , and require each line to fit a common typesetting line width . This model isolates the choice of breaks from adjustable spacing and hyphenation.
Let be the prefix sum, with . Placing items through on one line usesA line is feasible when . Charge for a nonfinal line and zero for the final line. If are the breaks, the objective isThe free final line is an explicit modelling choice. The convex function makes a doubled slack cost four times as much. For two slacks with fixed total,so greater imbalance increases their sum of squares. Actual break choices can also alter the line count and total slack; the whole paragraph still needs to be optimized.
Apply dynamic programming with andAn endpoint with no feasible predecessor has cost . The same recurrence finds a shortest path through the directed acyclic graph of feasible line choices. The principle of optimality explains the recurrence. Once the final breakpoint of a prefix is chosen, replacing its preceding layout by a cheaper layout with the same endpoint would improve the whole candidate. Conversely, each feasible predecessor and final line produces a valid candidate. Induction over therefore gives the optimum. Prefix states with charge their last line; only the final state gets the paragraph's free-last-line convention.
For widths , spacing 1 and capacity 7, the states areFollowing minimizing predecessors gives line lengths and cost 20. The line breaking diagram compares this with the cost 26 of greedy line breaking. With prefix sums, each candidate length takes constant time; at most candidates give time complexity and space complexity for costs and predecessors. The big O notation describes this fixed-space model; the Knuth-Plass line-breaking algorithm includes additional typography-specific choices.
Natural line width 2026-11-05
The natural line width is the width a candidate line occupies before any stretch or shrink of its typesetting glue. In a simple horizontal model with fixed typesetting box widths and nominal glue widths ,Additional fixed positioning adjustments must be included when the model contains them. If a discretionary break inserts a hyphen at the chosen endpoint, its width belongs to that candidate's natural width.
For example, boxes of widths 8, 6 and 10 and two nominal gaps of width 3 give . To reach a typesetting line width , the glue must absorb . A total finite stretch coefficient gives line adjustment ratio . The typesetting glue diagram shows the resulting adjustment.
Computing the natural width first separates the dimensions of the selected material from its later spacing adjustment. This also lets a line breaking algorithm compare several endpoints before committing to a final line. In the fixed-space model, prefix sums make repeated width calculations efficient.
Non-breaking space 2026-11-05
A non-breaking space is a separating character intended to keep adjacent text together during ordinary line breaking. The common Unicode character is U+00A0 NO-BREAK SPACE. It has line-break class GL; the surrounding rules determine which boundaries are prohibited.[ref]
Unicode Line Breaking Algorithm by the Unicode Consortium. §5.1, GL class; rules LB12 and LB12a
For an example,
25\u00a0µm is a visible spelling of an escape notation for a number, U+00A0, and a micrometre symbol. The actual text 25 µm keeps the number and unit together at that separator. Ordinary 25 µm instead uses U+0020 SPACE and can provide a wrap opportunity there. Neither choice fixes the physical width of the gap in every computer font.The rule is local. In the sequence
A\u0020\u00a0B, a break after the ordinary space can still be allowed, leaving the non-breaking space on the following line. Thus inserting U+00A0 does not make an entire text paragraph unbreakable.[ref]Unicode Line Breaking Algorithm by the Unicode Consortium. GL description: SPACE before NO-BREAK SPACE; LB12a exception
Soft hyphen 2026-11-05
A soft hyphen, or SHY, is the Unicode character U+00AD. It marks a preferred optional division inside a word and normally has no visible shape when that division is unused. Selecting it invokes the language-appropriate presentation for an intraword break, which can involve more than adding one hyphen.[ref]
Unicode Line Breaking Algorithm by the Unicode Consortium. §5.4: invisible format character and language-dependent break presentation
For example, a suitable renderer can show
ex followed by SHY and ample as example on one line, or as ex- and ample on successive lines. The visible hyphen then belongs to the chosen layout. In languages with spelling changes at a division, the layout implementation may also need to modify the divided parts.[ref]Unicode Line Breaking Algorithm by the Unicode Consortium. §5.4: spelling changes and responsibility of the line-breaking implementation
A soft hyphen supplies a hyphenation opportunity; it does not force the line breaking algorithm to use it. The algorithm can retain the unbroken word when its typesetting line width and paragraph cost permit that choice.
TeX 2026-11-05
TeX is Donald E. Knuth's programmable system for typography, particularly mathematical typesetting. A document supplies text and instructions; TeX macros and TeX primitives build material whose dimensions determine the eventual page layout. Computer fonts supply glyphs and font metrics, while line breaking selects how a text paragraph is divided. The Knuth-Plass line-breaking algorithm is one of the system's central layout methods.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. pp.1119–1122 and 1175–1176: paragraph optimization and development in TeX
A TeX format supplies a prepared collection of definitions. Plain TeX and LaTeX provide different document interfaces built on TeX technology. For example, in Plain TeX the input
$\sqrt{2}$\bye requests a square root expression, , and ends the document. The computer font, glyph positioning and mathematical typesetting rules determine the printed geometry; the source characters alone are not a picture of the result.The TeXbook by Donald E. Knuth is the system's user and reference manual. TeX source code by Donald E. Knuth exposes the implementation as a documented computer program, making the paragraph algorithm and its numerical conventions inspectable.[ref]
The TeXbook by Donald E. Knuth. Author’s official bibliography: Volume A as user/reference manual, Volume B as documented program
TeX line penalty 2026-11-05
The TeX line penalty, set by
\linepenalty, enters the per-line base used to calculate typesetting demerits. In the ordinary finite calculation, a line with typesetting badness contributes before breakpoint and neighbour-dependent terms, where denotes the chosen line penalty.[ref]TeX source code by Donald E. Knuth. try_break: line_penalty+b is squared before other contributions
The algebra shows how it affects a candidate with lines:Changing therefore changes both the line-count term and the way spacing costs enter the comparison.
For a chosen example, assume two feasible layouts have badness profiles and , with all other costs zero and values below saturation. At ,At ,The preferred candidate changes. These are illustrative profiles and parameter values. Actual line breaking must also account for feasible endpoints, typesetting penalties and possible line-breaking fitness class changes.
Text justification 2026-11-05
Text justification adjusts the contents of a line to occupy its available typesetting line width, often aligning both ends of the text. Changing word spacing is one method; permissible adjustments depend on the writing system. Typographic alignment more generally includes leaving the opposite edge ragged or centring a line.[ref]
CSS Text Module Level 3 by World Wide Web Consortium. §6: alignment versus justification; §6.4: script-sensitive expansion and compression
In an illustrative line with natural line width and target width , two equally flexible spaces can each gain 1. If their stretch coefficients are instead 1 and 3, proportional adjustment allocates the required extra 2 asBoth choices reach the same width; their internal spacing differs. Typesetting glue expresses that flexibility, and the line adjustment ratio computes the common proportional change.
Line breaking and text justification interact: a different break changes the number of spaces available to absorb the width difference. A good paragraph layout therefore considers spacing quality when choosing breaks, rather than merely stretching an already chosen set of lines. The Knuth-Plass line-breaking algorithm makes that interaction explicit.
Text paragraph 2026-11-05
A text paragraph is a group of text treated as one unit for paragraph layout. Its line breaking may change when the available typesetting line width or computer font changes, while its underlying paragraph boundary remains the same. A line in the source file therefore need not be a line of displayed output.[ref]
CSS Text Module Level 3 by World Wide Web Consortium. §3: white-space processing, wrapping and preserved versus collapsed segment breaks
For example, a sequence of four typesetting boxes may occupy two lines in a narrow container and one line in a wider container. Reflow changes the grouping of boxes without requiring a new paragraph. In TeX,
\par ends the current paragraph; in HTML, a p element marks a paragraph. Those mechanisms let the layout system work with a semantic group instead of relying on the writer to insert each visible line break.The Knuth-Plass line-breaking algorithm uses this grouping to compare costs across the whole paragraph. Its typesetting demerits can depend on both individual lines and changes between neighbouring lines, which cannot be evaluated by inspecting each source line in isolation.
Typesetting box 2026-11-05
A typesetting box is a piece of material treated as one unbreakable item at a given stage of line breaking. The simple paragraph model assigns it a width. A word already assembled from glyphs, or a small diagram placed within text, can be represented by such an item.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. pp.1123–1125: boxes as rigid-width items
For example, three boxes of widths 8, 6 and 10 separated by two spaces of width 3 occupy . Keeping the boxes fixed while changing only the spaces is the model used by typesetting glue. If hyphenation makes an internal split available, the word must instead be represented with that discretionary break; a single indivisible box would hide the choice.
A box's width describes layout advance, which need not equal the exact ink extent of its glyphs. A more complete TeX box also has height and depth relative to a text baseline. These measurements allow boxes to be combined while maintaining baseline geometry.[ref] The CSS box model uses its own rules for content, padding, borders and margins; interpreting every CSS box as an indivisible paragraph item would lose those distinctions.
Typesetting line width 2026-11-05
The typesetting line width is the horizontal measure that a layout assigns to a particular line. It supplies a target for text justification and a fitting constraint for line breaking. Write it as when it can depend on line number . The Knuth-Plass line-breaking algorithm permits a sequence of target widths, rather than requiring the entire text paragraph to be rectangular.[ref]
Breaking paragraphs into lines by Donald E. Knuth and Michael F. Plass. pp.1155–1156: line-number dependence and supplied positive line lengths
For example, suppose a text column is 40 units wide and first-line indentation reserves 10 units on its first line. ThenWith a fixed gap of width 2, three typesetting boxes of widths 12, 10 and 8 use units. They exceed the first line's available width, although they fit a later line in the fixed-space model. When typesetting glue can shrink, feasibility must also account for that permitted shrinkage.
Width and line height measure different directions. Changing the font size can alter both the widths of the typesetting boxes and their vertical metrics, so preserving the same column width does not preserve the same breaks.
Word separator 2026-11-05
A word separator is a text unit whose primary role is to separate words. Unicode SPACE U+0020 and non-breaking space U+00A0 are common examples. In CSS, the word-separator classification helps determine where word spacing is applied after white-space processing.[ref]
CSS Text Module Level 3 by World Wide Web Consortium. §7.1: word-separator characters and extra spacing
Separation and line breaking are related but distinct. In a suitable ordinary text context, a normal space between
10 and kg provides a possible break. Using a non-breaking space there keeps the number and unit together at that boundary. Both characters can still provide visible separation.[ref]Unicode Line Breaking Algorithm by the Unicode Consortium. Line-breaking properties: GL class and rules LB12/LB12a
A language can also write words without visible separators, so a count of space characters is not a universal word-counting method. Text shaping, word spacing and permitted breaks must follow the appropriate text-processing rules. A separator's stored character and the selected glyph advance jointly participate in the geometry.