Overflow
Also called overflow: hidden or overflow: auto
A CSS property that decides what happens when content is bigger than its box: spill out, get clipped, or scroll inside it.
import { useEffect, useRef } from 'react';
type Message = { id: string; author: string; text: string };
export function ChatPanel({ messages }: { messages: Message[] }) {
const listRef = useRef<HTMLOListElement>(null);
// Start at the newest message.
useEffect(() => {
const list = listRef.current;
if (list) list.scrollTop = list.scrollHeight;
}, [messages.length]);
return (
// overflow-hidden clips the children to the rounded corners.
<section className='flex w-96 flex-col overflow-hidden rounded-2xl border'>
{/* A fixed height that scrolls inside, with a scrollbar only when needed;
overscroll-contain stops the page from scrolling at the ends. */}
<ol
ref={listRef}
className='h-[480px] space-y-3 overflow-y-auto overscroll-contain p-4'
>
{messages.map((message) => (
<li key={message.id} className='text-sm'>
<span className='font-medium'>{message.author}</span>{' '}
<span className='text-muted-foreground'>{message.text}</span>
</li>
))}
</ol>
<form className='border-t p-3'>
<input
aria-label='Message'
placeholder='Write a message'
className='w-full rounded-lg border bg-background px-3 py-2 text-sm'
/>
</form>
</section>
);
}Give the chat history a fixed height of 480px with overflow-y: auto so it scrolls inside the panel, keep the message input pinned below it, and scroll to the newest message on load. Let wide tables scroll sideways with overflow-x: auto on phones, and clip card images to the card’s 16px corner radius with overflow: hidden.
Paste into Layerwise or any AI coding tool.
What is Overflow?
When content does not fit its box, overflow decides what to do. visible, the default, lets it spill out over whatever comes next. hidden clips it at the edge. scroll makes the box scrollable and always reserves room for scrollbars, while auto shows scrollbars only when the content actually overflows. overflow-x and overflow-y set each direction on its own.
Use auto for panels with a fixed height, such as a chat history or a long sidebar list, and overflow-x: auto for wide tables on phones. Use hidden to crop images to a card’s rounded corners or to keep a decorative shape from making the page scroll sideways.
Watch for side effects. hidden on a parent also cuts off dropdowns and tooltips inside it, and hidden, scroll, and auto all make the parent the box that position: sticky children stick inside. If a phone page scrolls sideways, find the element that is too wide before hiding overflow on body; overflow: clip crops without creating a scroll container.
Related terms
All termsSticky header
A top bar that stays pinned to the top of the screen while the page scrolls underneath it, so navigation is always one click away.
Z-index
A CSS property that decides which element appears on top when elements overlap, with higher numbers sitting closer to the viewer.
Scroll snap
A CSS feature that makes a scroll container settle on set points, so carousels and full-screen sections come to rest neatly on an item.
Horizontal scroll section
A pinned section where scrolling down moves a row of cards sideways, turning vertical scrolling into horizontal movement.
Build it with Layerwise
Describe your app, watch it run in a live preview, and publish it with a database, storage, and sign-in built in.