THE GITHTML FIELD GUIDE

Fix sticky headings that cover the next paragraph

A sticky heading can cover content when its size, offset, or scrolling ancestor differs from the author's assumptions. Inspect the containing elements and test enlarged text before adding more z-index. For a reading copy, removing sticky positioning may be the clearest fix when the heading consumes too much of the screen.

Identify the specific failure

Sticky positioning follows a scrolling context, not always the visible page. An ancestor with overflow can change that context. A heading that wraps onto three lines can also occupy far more space than the fixed offset used by the surrounding layout.

Make a narrow correction

First compare the same heading with position: static. If the obscured content becomes readable, inspect the sticky rule and its ancestors. Keep any retained sticky region compact, and avoid forcing a fixed height that clips the heading itself.

  1. Identify the ancestor that establishes the sticky element's scrolling context.
  2. Temporarily remove sticky positioning and compare the affected passage.
  3. Retain stickiness only if narrow-screen and enlarged-text checks remain usable.
css
.report-heading { position: static; }

Work through a heading that grows while scrolling

Consider a report with a two-line section heading beneath a persistent toolbar. At normal text size, the heading occupies a small part of the view. After enlargement it becomes five lines, but its top offset still assumes the original toolbar height. Scroll until the heading becomes stuck, then compare its occupied area with the first sentence below it. Record whether the sentence is covered continuously or only after a section link is followed; those observations distinguish persistent overlap from a destination-position problem.

Next inspect the containers between the heading and the page. An overflow rule added to contain a wide table can also introduce the scrolling mechanism that sticky positioning follows. Temporarily remove that rule on a copy and repeat the same scroll. If the behavior changes, decide whether the container needs its own scrolling region at all. Moving the table's horizontal overflow to a smaller wrapper can preserve the table without making an entire report section act like a separate scrolling panel.

Do not compensate with a large blank spacer above every paragraph. That spacer is tied to one heading size and wastes space elsewhere. A reading-oriented resolution might keep only a short document title sticky, let section headings move normally, or remove the persistent header entirely on narrow layouts. Whichever option is chosen, inspect the last lines of a section as its containing block ends. A heading that behaves well at the beginning can still overlap another element near that boundary.

Verify the repaired artifact

Test a long heading and a fragment jump with enlarged text. The destination and its first paragraph should both remain readable.

Sources and further reading

AI-assisted writing with source-linked guidance and illustrative examples. Read our editorial approach or report a correction.

All html troubleshooting guides →

Read as MarkdownAll guides

Fix sticky headings that cover the next paragraph · gitHtml