← Back to Bootstrap Course | Chapter 9: Layout Utilities | Lesson 4 of 7

Overflow

Overflow utilities decide what happens when content is bigger than its box.

In this page:

  1. Overflow
Syntax
markup
<div class="overflow-auto">scrolls when needed</div>
<div class="overflow-hidden">clipped</div>

Overflow

.overflow-auto adds scrollbars when needed, .overflow-hidden clips content, .overflow-visible lets it spill and .overflow-scroll always shows scrollbars.

Directional versions .overflow-x-auto and .overflow-y-auto exist. Give the box a fixed size for the effect.

Note: overflow-auto only shows a scrollbar when content overflows.

Example: Overflow

markup
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="p-3">
<div class="container">
  <div class="overflow-auto border p-2 mb-2" style="max-width: 16rem; max-height: 5rem">This box scrolls because its content is longer than the height allows. Keep writing text so it overflows the box height and shows a scrollbar.</div>
  <div class="overflow-hidden border p-2" style="max-width: 16rem; height: 2.5rem">This text is clipped by overflow-hidden when it is too long for the box.</div>
</div>
</body>
</html>
Live Example
Related Topics
Common Mistakes
  1. Not setting a height or width
  2. Hiding important content with overflow-hidden
  3. Nested scrolling areas
Chapter Summary
  • overflow-auto adds scrollbars as needed
  • overflow-hidden clips
  • overflow-x-* and overflow-y-*
  • Requires a limited box size
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.