Understanding and Using CSS `resize`: Enabling User-Controlled Element Resizing

Learn how to control user resizing of elements using CSS's `resize` property. This tutorial explains different `resize` values (`both`, `horizontal`, `vertical`, `none`), demonstrates their effects, and highlights best practices for implementing user-controlled resizing in your web designs.



Understanding the CSS `resize` Property

The CSS `resize` property controls whether and how a user can resize an element by dragging a small handle in the bottom-right corner. This is particularly useful for elements like textareas where you want to allow users to adjust the size.

How `resize` Works

The `resize` property adds a small triangular handle to the bottom-right corner of an element. Dragging this handle allows the user to resize the element. For `resize` to work correctly, the element must have its `overflow` property set to a value other than `visible` (e.g., `hidden`, `auto`, or `scroll`).

`resize` Property Values

The `resize` property accepts the following values:

  • none (default): The element cannot be resized.
  • horizontal: Only horizontal resizing is allowed (width only).
  • vertical: Only vertical resizing is allowed (height only).
  • both: Both horizontal and vertical resizing are allowed.
  • initial: Sets the property to its default value (none).
  • inherit: Inherits the value from its parent element.

Examples

Here are examples demonstrating each value. (Note that the "Test it Now" and "Output" sections below are placeholders and should be replaced with actual interactive examples showing the resizing behavior.)

Example 1: `horizontal`

Allows resizing only the width of the element.

Test it Now

Example 2: `vertical`

Allows resizing only the height of the element.

Test it Now

Example 3: `both`

Allows resizing both the width and height of the element.

Test it Now

Example 4: `none`

Disables resizing completely. No resize handle will appear.

Test it Now