One of the lesser-appreciated CSS3 properties, resize
does exactly what it says: it allows a user to resize almost any HTML element it is applied to. The property itself is something of a misnomer: it does not make content larger or smaller, and is perhaps more akin to a user-modifiable clip
property.
resize
can take four values, in addition to inherit
:
none | The element cannot be resized. This is the default for the majority of elements in most browser’s UA stylesheets. |
horizontal | The element may be resized by the user, but only horizontally. |
vertical
| The element is restricted to vertical resizing only |
both | The element may be resized both horizontally and vertically |
resize
does not apply to block
elements in which overflow
has been set to visible
, nor is it supported on images.
The first example of resize
I’ll provide is usually terrible from a UI perspective, but useful in illustrating the property: given a div
with some content, we’ll apply resize: both
, producing the following:
Try resizing this div element from the bottom right corner. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
On a more practical level, browsers that currently support resize
apply it to textarea
form elements by default. While this is a good idea – a user should be able to resize a textarea
box to get more room for what they are typing – unrestricted resizing can spoil some page designs. In most cases, it is better to rewrite the CSS rule to restrict resize
of the textarea
to one direction only:
textarea { resize: vertical; }
To this end, I have added the declaration to my suggested CSS reset and boilerplate code.
Enjoy this piece? I invite you to follow me at twitter.com/dudleystorey to learn more.