HTML & CSS Course
HTML & CSS
/
Beginner

Overflow

Definition

The `overflow` property specifies whether to clip the content, add a scrollbar, or display overflow content when it is too large to fit in its block-level container.

Explain Like I'm New

If you have a tiny cardboard box, and you try to shove a massive book into it, what happens? By default in CSS, the book just sticks out the side of the box (it overflows). The `overflow` property lets you tell the browser to either cut off the part sticking out, or create a scrollbar inside the box.

Real World Example

A Terms and Conditions box. You have 50 paragraphs of legal text, but you only want it to take up 300px of screen height. You use `overflow-y: scroll` to put a scrollbar inside the box.

Common Use Cases

  • •Scrollable sidebars
  • •Hiding elements that animate off-screen
  • •Terms of service text boxes

Interactive Example

Interview Questions

basic

  • What is the default value of the `overflow` property?

intermediate

  • What is the difference between `overflow: hidden` and `overflow: auto`?

Flash Cards

Question

Default value?

Click to reveal answer
Answer

`visible`. The content just spills out of the container.

Question

hidden vs auto?

Click to reveal answer
Answer

`hidden` physically chops off any text that doesn't fit. The user cannot scroll to see it. `auto` is smart: if the text fits, it does nothing. If the text is too big, it automatically adds a scrollbar so the user can read it.