🔧 CSS resize
Property — Making Elements Resizable by Users
Sometimes you want users to be able to resize elements on your webpage, especially textareas or divs, to improve usability and customize their view. The CSS resize
property gives you control over whether and how an element can be resized by the user.
🔹 What is the resize
Property?
resize
controls if an element is resizable by the user and in which directions (horizontal, vertical, or both).
It mostly applies to elements with overflow
other than visible
(like textareas, or divs with scrollbars).
📘 Syntax
selector {
resize: value;
}
Common values:
Value | Description |
---|---|
none | Disables resizing |
both | Allows resizing horizontally and vertically |
horizontal | Allows resizing only left and right |
vertical | Allows resizing only up and down |
block * | Resize along the block axis (writing mode dependent) (experimental) |
inline * | Resize along the inline axis (writing mode dependent) (experimental) |
* Less commonly used and experimental.
✍️ Example: Resizable Textarea
<textarea class="resizable-textarea"></textarea>
.resizable-textarea {
width: 300px;
height: 150px;
resize: vertical;
overflow: auto;
}
🖱️ The user can resize the textarea only vertically by dragging the corner.
🖼️ Image 1: Resizable Textarea Directions
Description:
- A textarea shown with draggable handle at the bottom-right corner.
- Arrows indicating vertical-only resizing (up/down).
- A separate example showing horizontal and both directions resizing.
🎯 Purpose: Visualize how resize directions affect user interaction.
🧠 Browser Support & Behavior
- Most modern browsers support
resize
on textarea and block elements with scrollable content. resize: both
is default on<textarea>
in many browsers.- The property works only when
overflow
is not visible (e.g.,auto
,scroll
, orhidden
). - Note: Some browsers might ignore resize on certain elements for usability or security reasons.
🆚 resize
vs Manual JS Resizing
resize
provides native user resizing with minimal effort.- For more complex resizing (e.g., dragging anywhere on the element, snap grids), JavaScript libraries are used.
✅ Best Practices
- Use
resize: none
when layout integrity is critical. - Use
resize: vertical
orhorizontal
to give controlled flexibility. - Combine with
max-width
,max-height
,min-width
,min-height
for bounds.
Example:
.resizable-box {
resize: both;
overflow: auto;
max-width: 600px;
max-height: 400px;
min-width: 200px;
min-height: 100px;
}
🔚 Final Thought
The CSS resize
property is a simple but powerful way to enhance user experience by letting them adjust elements to their liking — without writing any JavaScript.