agyanadda@gmail.com

CSS Overflow

CSS Layout 1 min read Updated Dec 1, 2026 Topic 22 of 39

overflow controls content that is too big for its box.

Value Result
visible content spills out (default)
hidden extra content is cut off
scroll scrollbars always shown
auto scrollbars only when needed

Use overflow-x and overflow-y for one direction only.

Text ellipsis

.title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

This shows ... when a single line of text is too long.

Example

Example — Overflow values HTML
<style>
  .box { width: 200px; height: 70px; border: 1px solid #333; margin-bottom: 12px; }
  .hidden { overflow: hidden; }
  .auto { overflow: auto; }
  .ellipsis { width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
</style>

<div class="box hidden">overflow: hidden cuts this long text so that you cannot see the rest of it at all.</div>
<div class="box auto">overflow: auto adds a scrollbar when the text is longer than the box can hold.</div>
<p class="ellipsis">This very long single line of text ends with three dots</p>

Test Yourself With Exercises

Exercise 1 Multiple Choice

Which value shows scrollbars only when needed?

Exercise 2 Fill in the Blank

text-overflow: ___; shows three dots for cut-off text.

Exercise 3 True / False

visible is the default overflow value.

Frequently Asked Questions

Find the element wider than the screen (often a fixed width or a large image) and use max-width: 100%. overflow-x: hidden on body hides the symptom only.