Scrollbars, interaction and resize
Definition and purpose
Scrollable regions and resizable inputs give users control over how they view content. CSS can customize these affordances without hiding essential functionality. Native scrollbars vary across operating systems.
Bounded scroll area
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>CSS practice</title><style>body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #a { height: 80px; overflow: auto; scrollbar-width: thin; scrollbar-color: navy white; }</style></head><body><div id="a" tabindex="0" aria-label="Scrollable list"><p style="height:200px">Scrollable content</p></div><label for="b">Notes</label><textarea id="b"></textarea></body></html>The content extends beyond the 80px region.
Syntax and mental model
Use overflow: auto when content may exceed a bounded size. scrollbar-width: thin asks for a thinner scrollbar, not an exact width. scrollbar-color specifies thumb then track colors. resize: vertical permits vertical resizing on eligible elements; overflow must not be visible or clip for ordinary boxes. overscroll-behavior: contain limits scroll chaining.
Resizable notes
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>CSS practice</title><style>body { margin: 0; font: 16px sans-serif; color: #172033; background: white; } #b { resize: vertical; overflow: auto; min-height: 60px; }</style></head><body><div id="a" tabindex="0" aria-label="Scrollable list"><p style="height:200px">Scrollable content</p></div><label for="b">Notes</label><textarea id="b"></textarea></body></html>The user can enlarge the text area vertically.
Common mistakes
Avoid scrollbar-width: none on user-scrollable content without an equivalent affordance. Do not disable textarea resize just to preserve a fixed composition.
Practice and next steps
After trying the examples, complete the linked coding exercise and review questions. Predict the result before running your code. Prerequisite: Dialogs and popovers. Next lesson: Accessible registration project.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Scrollbars, interaction and resize — knowledge check
Five questions on scrollbars, interaction and resize.
What does scrollbar-width: thin specify?
In scrollbar-color, which color comes first?
Which resize value permits vertical resizing?
Which overflow value makes a clipped box non-scrollable?
What does overscroll-behavior: contain limit?