html
/

CSS Overflow

Last Sync: Today

On this page

12
0%
5 min read
Remaining
5 minleft

Click any section to jump — progress syncs automatically

html

CSS Overflow

What is Overflow?

The overflow property controls what happens when content exceeds the size of its container.

Basic Example

CSSRead-only
1
div {
  width: 200px;
  height: 100px;
  overflow: hidden;
}

Overflow Values

ValueDescription
visibleDefault, content overflows
hiddenClips extra content
scrollAlways shows scrollbars
autoShows scrollbars if needed

Overflow Hidden

CSSRead-only
1
div {
  overflow: hidden;
}

Overflow Scroll

CSSRead-only
1
div {
  overflow: scroll;
}

Overflow Auto

CSSRead-only
1
div {
  overflow: auto;
}

Overflow X and Y

CSSRead-only
1
div {
  overflow-x: scroll;
  overflow-y: hidden;
}

Text Overflow (Ellipsis)

CSSRead-only
1
p {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

Scroll Behavior

CSSRead-only
1
html {
  scroll-behavior: smooth;
}

Best Practices

  • Use auto instead of scroll for better UX
  • Use hidden to prevent layout breaking
  • Use ellipsis for long text
  • Control overflow-x and overflow-y separately

Common Mistakes

  • Forgetting to set width/height
  • Using scroll unnecessarily
  • Clipping important content with hidden
  • Ignoring mobile scroll behavior

Conclusion

CSS overflow helps manage extra content effectively. Proper usage ensures clean layouts and better user experience.

Try it yourself

div {
  width: 200px;
  height: 100px;
  overflow: auto;
}

Test Your Knowledge

Q1
of 3

Which hides overflow?

A
visible
B
hidden
C
scroll
D
auto
Q2
of 3

Which shows scroll only if needed?

A
scroll
B
auto
C
hidden
D
visible
Q3
of 3

Which property adds ...?

A
overflow
B
text-overflow
C
white-space
D
display

Frequently Asked Questions

What is overflow?

Controls content outside container.

Difference between auto and scroll?

Auto shows scroll only if needed.

What is ellipsis?

Shows ... for overflowing text.

Previous

css float

Next

css z index

Related Content

Need help?

Explore our comprehensive docs or start a chat with our tech experts.