THE GITHTML FIELD GUIDE
Balance long headings without hard-coded line breaks
Use normal wrapping as the baseline and consider text-wrap: balance as a progressive typographic enhancement for short headings. Avoid br elements added solely to force an attractive desktop line break. The heading must remain complete and readable when the enhancement is unsupported or when a reader enlarges the text.
Choose the right representation
An author-controlled line break can leave a single word on a line after the viewport narrows. The same heading may look perfect in a screenshot and awkward everywhere else. Balancing lets the browser distribute words while preserving the actual text.
Apply the pattern deliberately
Scope balancing to headings or short introductory text, not every long paragraph. Keep the wording concise independently of CSS. If a heading becomes unclear when it spans three lines, shortening it may be more effective than adding more layout rules.
- Remove visual-only br elements from headings before testing a wrapping enhancement.
- Keep default wrapping readable so unsupported CSS does not become a content failure.
- Check the longest heading after increasing the text size and narrowing the window.
h1, h2 { text-wrap: balance; }Fix the wording before tuning the line endings
Take the longest real heading in the library, not a short placeholder title. It should identify the topic even when it wraps into several lines. Remove redundant qualifiers and move secondary detail into the introduction when the title becomes difficult to scan. A wrapping property cannot repair a heading that combines three unrelated questions. Keeping one clear subject also makes navigation labels, search results, and copied links easier to understand.
Distinguish an intentional semantic break from a line break inserted for appearance. A poem or a postal address may need specific boundaries; a documentation heading usually does not. When a hard break leaves a short word stranded on a phone, removing it lets the browser use the available space. Balance can then be an enhancement, but ordinary wrapping must remain acceptable if the browser ignores the declaration or applies a different balancing limit.
Test with the actual production font and its fallback, because a font swap can change every line ending. Also inspect headings containing code identifiers or long product names. If one token cannot fit, choose a deliberate wrapping policy for that token rather than reducing every heading's font size. Do not demand identical line breaks across devices as the acceptance criterion. Check that the whole title is visible, readable, and clearly associated with the content that follows.
Check the finished reading experience
Compare default wrapping with the enhanced version at several widths. Do not judge success by identical line endings across browsers; judge whether the title stays legible and attached to the correct section.
Sources and further reading
AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.