SA-21/06, C-11, Asapur, Varanasi, UP support@kamaldnp.com +91 8318013442
CSS
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10
Try this code live
Lesson 19 of 35

CSS Overflow Explained — Hidden, Scroll, Auto & More

4 min read · Free · No login needed

Sometimes the content is bigger than the box that holds it. A long notice in a small box, a wide table in a narrow column, a chat message that keeps growing. The overflow property decides what the browser does with the extra content: let it spill out, cut it off, or add scrollbars.

Diagram — see how it fits together
Diagram: CSS Overflow

Overflow only matters when the box has a fixed size — a set width and height. If the box is allowed to grow, the content simply makes it taller and there is nothing to overflow. So the first step is always a fixed height.

Visible — the default, content spills out

overflow: visible is the default. The extra content flows out of the box and overlaps whatever is below it. Nothing is hidden, but the page can look messy — text sitting on top of other text. Use it when you want the content to escape the box on purpose, almost never by accident.

Hidden — cut it off

overflow: hidden clips the extra content at the box's edge. Whatever does not fit simply disappears, and there is no way to scroll to it. It is useful for image cards and banners, where you want a clean edge and you do not care about the cut-off part.

Scroll — always show scrollbars

overflow: scroll adds scrollbars to the box, always — even when the content fits and there is nothing to scroll. The box stays the same size and the visitor can scroll inside it. It looks heavy, so it is rarely the best choice.

Auto — scrollbars only when needed

overflow: auto is the smart one. Scrollbars appear only when the content is actually too big for the box. If everything fits, the box looks plain. This is the value you will use most — for notice boards, chat windows, and long code blocks.

Overflow-x and overflow-y — one direction at a time

Sometimes you want to control the two directions separately. overflow-x handles the sideways direction, overflow-y handles up and down. A notice board usually needs overflow-y: auto — scroll down through the notices, but never sideways.

Syntax — the overflow values

.notice-board {
  width: 300px;
  height: 120px;
  overflow-y: auto;
}
.image-card {
  width: 200px;
  height: 150px;
  overflow: hidden;
}
Note: overflow: hidden has a useful side effect: it makes a parent box wrap around its floated children instead of collapsing. You will see why in the float lesson — but remember that the clipped content is gone for good, with no way to reach it.
Tip: Use overflow: auto instead of overflow: scroll. Scrollbars that appear only when needed look cleaner, and on a phone they take up no space at all until the visitor actually scrolls.

Common mistakes

  • Setting overflow on a box with no fixed height — the box just grows taller and nothing overflows.
  • Using overflow: hidden on text the visitor still needs, with no way to scroll to it.
  • Using overflow: scroll everywhere, so every box shows grey scrollbars even when empty.
  • Forgetting that overflow-x: hidden on the body can break position: sticky further down the page.
  • Expecting a horizontal scrollbar from overflow: auto when the real problem is a fixed-width table that needs a wrapper div.

Remember

  • Visible lets content spill out; hidden cuts it off; scroll always shows scrollbars; auto shows them only when needed.
  • Overflow needs a fixed height — without one, the box just grows.
  • overflow-x controls sideways, overflow-y controls up and down.
  • overflow: auto is the value you will use most, for notice boards and chat boxes.
  • Never hide content with overflow: hidden unless you are sure nobody needs it.

Example explained

  • .box { width: 220px; height: 100px; display: inline-block; } — each demo box has a fixed size so the content can overflow, and the four boxes sit side by side.
  • .visible { overflow: visible; } — the extra text spills out of the first box and overlaps the text below it.
  • .hidden { overflow: hidden; } — the extra text in the second box is cut off at the edge, with no way to scroll to it.
  • .scroll { overflow: scroll; } — the third box always shows scrollbars, even though its text is short.
  • .auto { overflow: auto; } — the fourth box shows scrollbars only because its text is too long — this is the one to use in real pages.
  • .notice { width: 300px; height: 120px; overflow-y: auto; } — the notice board scrolls up and down through the notices, but never sideways.

Example

Example
<!DOCTYPE html>
<html>
<head>
<title>Overflow Examples</title>
<style>
body {
  font-family: Arial, sans-serif;
}
h1, h2 {
  color: #1e3a5f;
}
.box {
  width: 220px;
  height: 100px;
  border: 2px solid #1e3a5f;
  margin: 16px;
  padding: 8px;
  display: inline-block;
  vertical-align: top;
}
.visible {
  overflow: visible;
}
.hidden {
  overflow: hidden;
}
.scroll {
  overflow: scroll;
}
.auto {
  overflow: auto;
}
.notice {
  width: 300px;
  height: 120px;
  overflow-y: auto;
  border: 2px solid #16a34a;
  padding: 10px;
}
</style>
</head>
<body>

<h1>CSS Overflow</h1>

<div class="box visible"><strong>visible:</strong> The extra text spills out of the box and overlaps what is below it.</div>
<div class="box hidden"><strong>hidden:</strong> The extra text is cut off at the edge of the box and you cannot scroll to it.</div>
<div class="box scroll"><strong>scroll:</strong> Scrollbars are always shown, even when the text fits inside the box.</div>
<div class="box auto"><strong>auto:</strong> Scrollbars appear only when the text is too long for the box. This is the one you will use most.</div>

<h2>School Notice Board</h2>
<div class="notice">
<p>1. Exams start on Monday, 9 AM sharp.</p>
<p>2. Library timing changed: 8 AM to 5 PM.</p>
<p>3. Cricket trials on Friday at the main ground.</p>
<p>4. Fee last date is the 10th of this month.</p>
<p>5. Science exhibition entries close next week.</p>
</div>

</body>
</html>

Output

Output — how it looks in the browser
Output of CSS Overflow Explained — Hidden, Scroll, Auto & More

Try it yourself — live editor

Change the code below and press Run to see the result instantly. No file to save, no login needed.

Result

Frequently asked questions

The questions learners ask most about this lesson — read the question, then open it to see the answer.

1. What is the difference between overflow: auto and overflow: scroll?

auto shows scrollbars only when needed; scroll always shows them, even when the content fits.

2. Why does overflow do nothing without a fixed height?

Without a fixed height, the box just grows taller to fit the content, so nothing overflows.

3. Which overflow value will you use most?

overflow: auto — for notice boards and chat boxes, where scrollbars should appear only when needed.

Why learn this yourself — and not just ask AI?

AI can write code for you, but it cannot think for you. When you learn HTML yourself, your brain builds the real skill: you understand why a page looks the way it does, you can fix it when it breaks, and you can answer it in an exam or an interview without help. That is the skill that gets you a job — not a copied answer.

Get certified — just ₹10

Finish all 35 lessons, pass the test (80%), pay ₹10 and get your certificate.

Take the test

Prefer watching? Video courses teach the same topics step by step.

Go further with a full course

Free tutorials teach you the basics. Our paid courses add live projects, mentorship and a certificate.

CapCut Mobile Video Editing Course Beginner to Advance
₹99
View
AI & ML with Azure AI, AWS AI & Generative AI
₹10,000
View
Master Python + AI Skills in 30 Days
₹499
View
Browse all courses
CSS — Lessons
1. CSS Tutorial for Beginners — Learn CSS from Scratch 2. CSS Syntax Explained — Selectors, Properties & Values 3. CSS Selectors Tutorial — Class, ID, Attribute & More 4. How to Add CSS to HTML — Inline, Internal, External 5. CSS Colors Tutorial — HEX, RGB, RGBA, HSL Explained 6. CSS Backgrounds Tutorial — Images, Size & Position 7. CSS Borders Tutorial — Style, Width, Radius & Shadow 8. CSS Margin Explained — Shorthand, Auto & Collapse 9. CSS Padding Explained — Shorthand & Margin Difference 10. CSS Height and Width — px, %, em, rem, vw, vh Units 11. CSS Box Model Explained — Content, Padding, Border 12. CSS Text Styling Tutorial — Color, Align & Spacing 13. CSS Fonts Tutorial — font-family, Sizes & Google Fonts 14. CSS Link Styling — Hover, Visited, Active & Buttons 15. CSS Lists Styling — Markers, Counters & Shorthand 16. CSS Tables Styling — Zebra Stripes & Hover Rows 17. CSS Display Property — Block, Inline, None Explained 18. CSS Position Explained — Relative, Absolute, Fixed 19. CSS Overflow Explained — Hidden, Scroll, Auto & More 20. CSS Float and Clear — Layouts & Clearfix Trick 21. CSS Pseudo-classes — Hover, Focus, nth-child & More 22. CSS Pseudo-elements — ::before, ::after & ::first-line 23. CSS Form Styling — Inputs, Labels & Buttons Tutorial 24. CSS Navigation Bar Tutorial — Dropdown Menu Included 25. CSS Website Layout Tutorial — Header, Sidebar, Footer 26. CSS Flexbox Tutorial — Complete Guide with Examples 27. CSS Grid Tutorial — Columns, Rows & Layouts Guide 28. CSS Responsive Design — Media Queries Tutorial 29. CSS Transitions & Animations — No JavaScript Needed 30. CSS Variables Tutorial — :root, var() & Theming 31. CSS Transforms Explained — Rotate, Scale, Translate 32. CSS Filters Tutorial — Blur, Grayscale, Sepia & More 33. CSS Text Effects — Shadows, Wrapping & Overflow 34. CSS Keyframes Tutorial — Bouncing Ball Animation 35. CSS Grid Template Areas — Layout in Words, Not Numbers
Final Test — Certificate ₹10

🤖 KAMALDNP AI Assistant

Ask about courses, website & more

Hi! I'm KAMALDNP AI Assistant. Ask me about our courses, website features, or anything else! 😊
Please wait 5s...
🤖 KAMALDNP Assistant ✕

Request human callback:

🔐 Login Required
✕

Please log in to download. You will stay on this page after logging in!

New here? Register now →