In the last lesson, you made a photo fit a box of a set shape. Text doesn’t always fit either. In Keep Sizes Flexible on Small Screens, a fixed height on the work day card left its Plot 7 line on the card’s bottom border because the browser drew the text outside the box. Rosa’s next addition to the card is a bigger misfit: the volunteers’ address, [email protected].
In this lesson, you’ll predict what each value of the overflow property does with content that’s bigger than its box. You’ll also keep a long address inside its card and cut a line of text short with an ellipsis. Start by making the work day card too small on purpose, so you can watch its content spill out.
Choose What Happens to Overflow
Content that’s bigger than its box is called overflow, and the overflow property decides what the browser does with it. To try its values, you need a box that’s too small for its content, which DevTools can make without touching your files.
Open events/upcoming.html in Chrome or Edge with DevTools docked, and select the work day card’s <article class="event-card"> line in the Elements panel. In the Styles pane, click inside the element.style rule at the top, add height: 100px, and scroll the page down to the Coming Up section:

The card is now 100 pixels tall, about 60 pixels short of what its content needs. The browser draws the card at the height you asked for, and the Plot 7 line hangs below its bottom border, across the gap, and onto the seed swap card. That’s the default, overflow: visible. The box keeps its size, the content keeps its size, and whatever doesn’t fit is drawn outside the box anyway.
Notice that the seed swap card didn’t move out of the way. Overflow takes up no space in normal flow, so it can land on top of whatever comes next.
Now add overflow: hidden below the height in element.style. The Plot 7 line disappears because the browser cuts the content off at the inside edge of the card’s border. You’ve met this value before, in the .visually-hidden rule, where it stops the text from being drawn outside a box one pixel wide.
Change hidden to auto:

The Plot 7 line is still hidden, but a scrollbar appears at the card’s right edge, and you can scroll inside the card to reach it. On macOS, scrollbars usually stay out of sight until you scroll over the box. With auto, the box becomes a small scrolling window onto its content, and it gets a scrollbar only in the direction that overflows.
Two more values complete the set. The scroll value works like auto but always shows scrollbars in both directions, even when nothing overflows. The clip value cuts the content off as hidden does, but the box never scrolls at all.