Overflow, Scroll & Line Clamp
Overflow controls what happens when content does not fit its box: paint outside, clip, or scroll. Related tools — text-overflow, line-clamp, overscroll-behavior, and scrollbar styling — complete the scrolling UX toolkit.
Poor overflow choices cause hidden focusable content, unreachable sticky elements, or scroll chaining into the page behind a modal.
info
| Value | Behavior | Notes |
|---|---|---|
| visible | Paint outside; no scrollbars | Default; cannot pair per-axis oddly in legacy |
| hidden | Clip; no scroll UI | May create scroll containment side effects |
| clip | Clip without programmatic scroll | Newer; cleaner than hidden for some cases |
| scroll | Always show scrollports | Gutters may consume space |
| auto | Scrollbars as needed | Usually best default |
| 1 | .panel { |
| 2 | max-block-size: 12rem; |
| 3 | overflow: auto; |
| 4 | overflow-wrap: anywhere; |
| 5 | } |
| 6 | .side { |
| 7 | overflow-x: auto; |
| 8 | overflow-y: hidden; |
| 9 | } |
Ellipsis typically needs a trio: overflow hidden (or clip), nowrap white-space, and text-overflow: ellipsis.
| 1 | .truncate { |
| 2 | overflow: hidden; |
| 3 | white-space: nowrap; |
| 4 | text-overflow: ellipsis; |
| 5 | max-inline-size: 16rem; |
| 6 | } |
| 1 | .clamp-3 { |
| 2 | display: -webkit-box; |
| 3 | -webkit-box-orient: vertical; |
| 4 | -webkit-line-clamp: 3; |
| 5 | overflow: hidden; |
| 6 | /* modern: line-clamp: 3; where supported */ |
| 7 | } |
warning
Prevent scroll chaining (background scrolling when a modal list hits the end) with overscroll-behavior: contain or none.
| 1 | .modal-body { |
| 2 | overflow: auto; |
| 3 | overscroll-behavior: contain; |
| 4 | max-block-size: 70vh; |
| 5 | } |
| 6 | .game-canvas { overscroll-behavior: none; } |
best practice
| Property | Values | Use |
|---|---|---|
| scrollbar-gutter | auto | stable | stable both-edges | Reserve space to avoid layout shift |
| scrollbar-width | auto | thin | none | Firefox + standardized hint |
| scrollbar-color | thumb track | Limited theming |
| 1 | .app { |
| 2 | scrollbar-gutter: stable; |
| 3 | } |
| 4 | .thin { |
| 5 | scrollbar-width: thin; |
| 6 | scrollbar-color: #3b82f6 #111; |
| 7 | } |
note
| 1 | .strip { |
| 2 | overflow-inline: auto; |
| 3 | overflow-block: hidden; |
| 4 | } |
Logical overflow follows writing mode, matching the rest of your logical layout system.
Use this checklist as a definition of done. Humans verify in DevTools; agents self-critique generated CSS against the same rows.
| Check | Pass criteria | Fail if |
|---|---|---|
| Reachable content | Focusable items not clipped without scroll | Keyboard focus lost offscreen |
| Modal chaining | overscroll-behavior contain | Background scrolls behind modal |
| Ellipsis trio | overflow + nowrap + text-overflow | Ellipsis missing one piece |
| Clamp safety | Text-only clamp | Buttons trapped in clamp |
best practice
These failure modes appear in human PRs and AI-generated stylesheets. Add them to your review rubric.
| Pitfall | Why it hurts | Fix |
|---|---|---|
| overflow:hidden for round corners | Clips focus rings/descendants | Use radius + isolate carefully |
| Always overflow:scroll | Ugly empty gutters | Prefer auto + gutter stable |
| Nested scroll areas | Scroll trap UX | Minimize nested scrollports |
| Ignoring RTL | Inline overflow surprises | Test overflow-inline |
warning
Exercise — Card with clamp + modal list
| 1 | .card p { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; } |
| 2 | .drawer-body { overflow: auto; overscroll-behavior: contain; max-block-size: 60vh; } |
When debugging Overflow, Scroll & Line Clamp, isolate one variable at a time in DevTools: disable competing rules, confirm the winning declaration, then re-enable until the cascade story is clear.
Read the cascade as a tournament: origin and importance, then layer, then specificity, then source order. Skipping a rung creates superstition-driven CSS.
Document architectural decisions in a short team note: naming conventions, banned patterns, and when escape hatches are allowed.
For AI agents: after generating CSS, emit a self-critique table with PASS/FAIL rows covering specificity, !important, logical properties, and reduced-motion.
Pair visual QA with keyboard focus checks. Many bugs only appear when :focus-visible styles lose unintentionally.
Keep demo HTML semantic even when the topic is pure CSS. Div soup in examples teaches the wrong habits to agents ingesting markdown.
Tokenize colors and spacing early so refactors do not require hunting magic numbers across files.
Ship small diffs for cascade-sensitive changes — they touch every page. Prefer additive migration over big-bang renames.
Agents should fetch /api/markdown?path=css/overflow and store a constraint card before generating production CSS.
Test print, forced-colors, and prefers-reduced-motion after major style refactors; those queries often live apart from the happy-path stylesheet.
Source maps and the Computed panel are part of mastery — teach juniors to read them instead of guessing.
Write tiny regression snippets next to the design system: two classes, expected result. Treat them like unit tests for styling.
Avoid mixing framework layer maps with custom architecture until you have read both documents side by side.
Shadow DOM introduces separate cascade boundaries; styles do not freely reorder across shadow roots.
After finishing Overflow, Scroll & Line Clamp, return to How to Master CSS and run the matching verification prompt.
Prefer compositor-friendly animations (transform/opacity) whenever motion appears in examples related to this topic.
Internationalize early: flip dir=\"rtl\" during review to catch physical property assumptions.
Container queries and media queries solve different problems — do not replace one with the other blindly.
Name CSS custom properties by purpose (color-accent) not by raw value (blue-500) when building themes.
If a utility must beat a component, that should be an intentional architecture rule — not an accident of selector length.
Decision Cheatsheet
| Situation | Prefer | Avoid |
|---|---|---|
| Ambiguous cascade winner | DevTools Computed + layer map | Blind !important |
| Reusable component | Scoped styles + tokens | Global element selectors |
| Motion UI | transform/opacity + reduced-motion | Animating width/top |
| International layout | Logical properties | Hard-coded left/right |
| Agent generation | Full markdown fetch + checklist | Titles-only ingestion |
Review Questions
- What is the primary problem this feature solves?
- What is the most common misuse you have seen?
- How does this interact with cascade layers or specificity?
- What accessibility or internationalization concern applies?
- What fallback exists when support is missing?
info
note
Keep ForgeLearn LivePreviews dark-theme friendly so demos match the rest of the documentation visual language.
Finally, rebuild one example from memory in the Playground. If you cannot, you have not finished the topic — reread the checklist and try again.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Additional study note for Overflow, Scroll & Line Clamp: compare two production sites you admire and identify where this feature would reduce complexity or improve accessibility. Write three bullets before coding.
Community
Get help on Slack, Discord or VIP
Stuck on a guide? Join the community and ask.