GMT+1
Berlin

How to disable in one or both directions the resizable property of a textarea

Published on ·
By

As web developers, we often want to give users a seamless and consistent experience. While the default behavior of a <textarea> element allows users to resize it by dragging the bottom-right corner, there are times when you may want to restrict this functionality. For instance, you might want to maintain a specific layout or prevent a user from accidentally making a textarea too wide, which can disrupt the design of your page.

young woman stretches a fitness band
resize: vertical;

This is where the power of CSS comes in. While you might expect there to be a direct HTML attribute for this, like resizable="false", there isn't one. The CSS resize property is the standard and most flexible way to control a textarea's resizing behavior.

The Versatile CSS resize Property

The resize CSS property specifies whether an element is resizable by the user. It can take on a few different values, giving you precise control over how your text areas behave.

Real-World Examples.

To see these properties in action, let's look at two prominent websites.

upwork textarea
UpWork cover letter textarea

Example 1: UpWork Proposal Textarea

The user-friendly interface of UpWork, a popular freelancing platform, provides a great example of restricted resizing. The textarea where freelancers describe their proposals is a fantastic user experience. By default, the width is fixed to fit the layout, but you can see that the bottom-right corner has a handle that allows you to drag it vertically. This means you can add as much detail as you need without breaking the page's design. This is achieved with resize: vertical;.

nytimes textarea
New York Times Tips form textarea

Example 2: New York Times "Tips" Page

On the other end of the spectrum is the New York Times "Tips" page, where you can submit a tip to the newsroom. Here, the textarea uses the default browser behavior, allowing users to resize it in both horizontal and vertical directions. While this might seem to give the user maximum freedom, it can come with a significant risk.

Allowing unrestricted horizontal resizing can break the form's layout. For instance, if a user makes the textarea very narrow, the form's labels and other elements may no longer align correctly, or the text inside the textarea could become unreadable. This shows the potential downside of giving users too much control, as it can lead to unintended layout issues that disrupt the design and provide a poor user experience.

Why an HTML Attribute For Textarea Was Never Developed

You might wonder why a simple HTML attribute like resizable="false" was never created for the <textarea> tag. The reason lies in the separation of concerns. HTML's primary purpose is to define the structure and content of a web page. CSS, on the other hand, is designed to control the presentation and styling of that content.

The flexibility of the resize property is a testament to this design philosophy. Instead of a simple true/false switch that an HTML attribute would likely provide, the CSS property offers nuanced control, allowing you to choose between disabling resizing entirely or restricting it to a specific direction. This level of granular control is a core strength of CSS and is why it remains the ideal tool for managing the visual properties of your web elements.

Which communication tool
is best for you?