3234

I want to disable the resizable property of a textarea.

Currently, I can resize a textarea by clicking on the bottom right corner of the textarea and dragging the mouse. How can I disable this?

Enter image description here

Sunderam Dubey
  • 1
  • 11
  • 20
  • 40
user549757
  • 32,962
  • 4
  • 19
  • 20
  • 7
    @JDIsaaks - further, allowing resize in certain situations can break layout and printabilit (an important aspect of a current mission-critical project). – random_user_name Nov 23 '12 at 19:35
  • 19
    Sometimes you really do want a non-resizeable textarea. For instance, in this case, when you're (conditionally) converting a textarea into something that just looks like a label. It looks really odd to have a label with a random floating grabber way off to the side. – neminem Jan 21 '15 at 17:20
  • 7
    For the love of all that is good, please don't do this on an actual textarea or you will alienate your power users. Breaking core browser functionality should be considered a nuclear option. – superluminary Jan 30 '20 at 13:37

22 Answers22

4279

The following CSS rule disables resizing behavior for textarea elements:

textarea {
  resize: none;
}

To disable it for some (but not all) textareas, there are a couple of options.

You can use class attribute in your tag(<textarea class="textarea1">):

.textarea1 {
  resize: none;
}

To disable a specific textarea with the name attribute set to foo (i.e., <textarea name="foo"></textarea>):

textarea[name=foo] {
  resize: none;
}

Or, using an id attribute (i.e., <textarea id="foo"></textarea>):

#foo {
  resize: none;
}

The W3C page lists possible values for resizing restrictions: none, both, horizontal, vertical, and inherit:

textarea {
  resize: vertical; /* user can resize vertically, but width is fixed */
}

Review a decent compatibility page to see what browsers currently support this feature. As Jon Hulka has commented, the dimensions can be further restrained in CSS using max-width, max-height, min-width, and min-height.

Super important to know:

This property does nothing unless the overflow property is something other than visible, which is the default for most elements. So generally to use this, you'll have to set something like overflow: scroll;

Quote by Sara Cope, http://css-tricks.com/almanac/properties/r/resize/

JSman225
  • 96
  • 1
  • 16
Donut
  • 110,061
  • 20
  • 134
  • 146
  • 1
    Is there a solution for Firefox, Opera and/or IE? – Šime Vidas Mar 08 '11 at 16:31
  • 8
    @Šime IE and FF3 (and earlier) do not add support resizing, so a solution for them is not needed. For FF4, this solution should work. – Donut Mar 08 '11 at 16:37
  • 33
    as per http://davidwalsh.name/textarea-resize - use resize:vertical or resize:horizontal to constrain resizing to one dimension. Or use any of max-width, max-height, min-width and min-height. – Jon Hulka Nov 17 '12 at 20:23
  • 6
    Am I the only one who finds it weird to set this using css and not attributes? Why can't I then set disabled or checked or other properties using CSS ... – Buksy Aug 08 '16 at 13:15
  • 9
    @Buksy Because "disabled" is a state, not a visual property. Thus it's logical that it shouldn't be decided by a *styling* language. – This company is turning evil. Sep 08 '16 at 13:01
  • This solution haven´t the best practices. You can do it with a MVC property. @Html.TextAreaFor(model => model.YourProperty, new { @style = "width: 90%; height: 180px; resize: none;" }) – Carlos de Jesus Baez Feb 06 '20 at 13:24
  • I initially attempted the above technique, but it did not work for me, so I then used textarea { resize: none; pointer-events: none; } That`s working perfectly fine on https://www.fireboxtools.com/tools/word-counter – jitendra rajput Jun 12 '23 at 10:07
248

In CSS ...

textarea {
    resize: none;
}
Jeff Parker
  • 7,367
  • 1
  • 22
  • 25
132

I found two things:

First

textarea{resize: none}

This is a CSS 3, which is not released yet, compatible with Firefox 4 (and later), Chrome, and Safari.

Another format feature is to overflow: auto to get rid of the right scrollbar, taking into account the dir attribute.

Code and different browsers

Basic HTML

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <textarea style="overflow:auto;resize:none" rows="13" cols="20"></textarea>
</body>
</html>

Some browsers

  • Internet Explorer 8

Enter image description here

  • Firefox 17.0.1

Enter image description here

  • Chrome

Enter image description here

Community
  • 1
  • 1
Rami Jamleh
  • 1,819
  • 1
  • 13
  • 10
74

CSS 3 has a new property for UI elements that will allow you to do this. The property is the resize property. So you would add the following to your stylesheet to disable resizing of all textarea elements:

textarea { resize: none; }

This is a CSS 3 property; use a compatibility chart to see browser compatibility.

Personally, I would find it very annoying to have resizing disabled on textarea elements. This is one of those situations where the designer is trying to "break" the user's client. If your design can't accommodate a larger textarea, you might want to reconsider how your design works. Any user can add textarea { resize: both !important; } to their user stylesheet to override your preference.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
James Sumners
  • 14,485
  • 10
  • 59
  • 77
  • 1
    But that would be the user _intentionally breaking_ their layout, rather than a user who just needs to resize his/her `texarea` and ends up making something not work – Radvylf Programs Apr 15 '19 at 12:35
34
<textarea style="resize:none" rows="10" placeholder="Enter Text" ></textarea>
27

If you need deep support, you can use an old school technique:

textarea {
    max-width: /* desired fixed width */ px;
    min-width: /* desired fixed width */ px;
    min-height: /* desired fixed height */ px;
    max-height: /* desired fixed height */ px;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
yevgeniy
  • 748
  • 9
  • 15
  • 8
    Also use `resize:none` with this solution to prevent the handle appearing in the bottom corner which frustratingly doesn't work. – MacroMan Jul 17 '15 at 09:55
23

This can be done in HTML easily:

<textarea name="textinput" draggable="false"></textarea>

This works for me. The default value is true for the draggable attribute.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Thusitha Wickramasinghe
  • 1,063
  • 2
  • 15
  • 30
15

Use this property resize: none;

textarea {
  resize: none;
}
Ismoil Shokirov
  • 2,213
  • 2
  • 16
  • 32
14

You simply use: resize: none; in your CSS.

The resize property specifies whether or not an element is resizable by the user.

Note: The resize property applies to elements whose computed overflow value is something other than "visible".

Also resize not supported in Internet Explorer at the moment.

Here are different properties for resize:

No Resize:

textarea {
  resize: none;
}

Resize both ways (vertically & horizontally):

textarea {
  resize: both;
}

Resize vertically:

textarea {
  resize: vertical;
}

Resize horizontally:

textarea {
  resize: horizontal;
}

Also if you have width and height in your CSS or HTML, it will prevent your textarea be resized, with a broader browsers support.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alireza
  • 100,211
  • 27
  • 269
  • 172
11

You can simply disable the textarea property like this:

textarea {
    resize: none;
}

To disable vertical or horizontal resizing, use

resize: vertical;

or

resize: horizontal;
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
11

you need to set the below CSS code in your component.css

textarea {
    resize: none;
}
Geeky Quentin
  • 2,469
  • 2
  • 7
  • 28
Umer Baba
  • 285
  • 3
  • 4
10

To disable the resize property, use the following CSS property:

resize: none;
  • You can either apply this as an inline style property like so:

    <textarea style="resize: none;"></textarea>
    
  • or in between <style>...</style> element tags like so:

    textarea {
        resize: none;
    }
    
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Webeng
  • 7,050
  • 4
  • 31
  • 59
8
textarea {
  resize: none;
}

The code above will disable the resizable property of all <textarea/> elements in your project. If you want that that is fine, otherwise you would want to use a specific class for your textarea elements.

.not-resizable {
   resize: none;
}

In your HTML

<textarea class="not-resizable"></textarea>
Ismoil Shokirov
  • 2,213
  • 2
  • 16
  • 32
8

You can disable resizeable property of textarea using textarea {resize: none;}

textarea {
   resize: none;
}

Demo

Kabeer
  • 117
  • 1
  • 4
7

CSS 3 can solve this problem. Unfortunately it's only supported on 60% of used browsers nowadays.

For Internet Explorer and iOS you can't turn off resizing, but you can limit the textarea dimension by setting its width and height.

/* One can also turn on/off specific axis. Defaults to both on. */
textarea { resize:vertical; } /* none|horizontal|vertical|both */

See Demo

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Oriol
  • 11,660
  • 5
  • 35
  • 37
7

To disable resize for all textareas:

textarea {
    resize: none;
}

To disable resize for a specific textarea, add an attribute, name, or an id and set it to something. In this case, it is named noresize

HTML

<textarea name='noresize' id='noresize'> </textarea>

CSS

/* Using the attribute name */
textarea[name=noresize] {
    resize: none;
}
/* Or using the id */

#noresize {
    resize: none;
}
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Abk
  • 2,137
  • 1
  • 23
  • 33
6

I have created a small demo to show how resize properties work. I hope it will help you and others as well.

.resizeable {
  resize: both;
}

.noResizeable {
  resize: none;
}

.resizeable_V {
  resize: vertical;
}

.resizeable_H {
  resize: horizontal;
}
<textarea class="resizeable" rows="5" cols="20" name="resizeable" title="This is Resizable.">
This is Resizable. Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.
</textarea>

<textarea class="noResizeable" rows="5" title="This will not Resizable. " cols="20" name="resizeable">
This will not Resizable. Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.
</textarea>

<textarea class="resizeable_V" title="This is Vertically Resizable." rows="5" cols="20" name="resizeable">
This is Vertically Resizable. Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.
</textarea>

<textarea class="resizeable_H" title="This is Horizontally Resizable." rows="5" cols="20" name="resizeable">
This is Horizontally Resizable. Lorem ipsum, or lipsum as it is sometimes known, is dummy text used in laying out print, graphic or web designs. The passage is attributed to an unknown typesetter in the 15th century who is thought to have scrambled parts of Cicero's De Finibus Bonorum et Malorum for use in a type specimen book.
</textarea>
Ambuj Khanna
  • 1,131
  • 3
  • 12
  • 32
4

With @style, you can give it a custom size and disable the resize feature (resize: none;).

@Html.TextAreaFor(model => model.YourProperty, new { @style = "width: 90%; height: 180px; resize: none;" })
Baptiste Mille-Mathias
  • 2,144
  • 4
  • 31
  • 37
1

You can try with jQuery also

$('textarea').css("resize", "none");
Santosh Khalse
  • 12,002
  • 3
  • 36
  • 36
  • 3
    You should [use more jquery](https://www.doxdesk.com/img/updates/20091116-so-large.gif). You're not using it enough. :) – Filip Savic Jun 25 '18 at 10:01
  • 1
    [It is a meme](https://meta.stackexchange.com/questions/19478/the-many-memes-of-meta/19492#19492) - e.g., *"You should totally drop that and try jQuery."*. – Peter Mortensen Sep 26 '19 at 09:38
0

Adding !important makes it work:

width:325px !important; height:120px !important; outline:none !important;

outline is just to avoid the blue outline on certain browsers.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kaelds
  • 317
  • 2
  • 3
0

If anyone is looking for a way to this in plain Javascript:

textArea = document.createElement("textarea");
textArea_input.setAttribute("style","resize:none");

Note: Setting the style property this way will overwrite all your prior css style declarations.

-1

Yes, you can disable the resizable property of a textarea using CSS. The following code will disable the resizable property of a textarea with the id my-textarea:

CSS Code:-

textarea#my-textarea {
  resize: none;
}

You can also disable the resizable property of all textareas on a page by adding the following code to your CSS stylesheet:

CSS Code:-

textarea {
  resize: none;
}

The resize property can have three values:

  • none: The textarea cannot be resized.
  • horizontal: The text area can only be resized horizontally.
  • vertical: The text area can only be resized vertically.

The default value of the resize property is none.

In addition to using CSS, you can also disable the resizable property of a textarea using JavaScript. The following code will disable the resizable property of a textarea with the id my-textarea:

JavaScript Code:-

const textarea = document.getElementById('my-textarea');
textarea.style.resize = 'none';

This code will overwrite any CSS styles that have been applied to the textarea.

To reduce the size of a textarea, you can use the rows and cols attributes in the HTML code. The rows attribute specifies the number of rows in the textarea, and the cols attribute specifies the number of columns. For example, the following code will create a textarea with 10 rows and 50 columns:

HTML Code:-

<textarea rows="10" cols="50"></textarea>

You can also use CSS to set the size of a textarea. The following code will set the height and width of a textarea with the id my-textarea to 100px and 200px, respectively:

CSS Code:-

textarea#my-textarea {
  height: 100px;
  width: 200px;
}
Parth Raval
  • 4,097
  • 3
  • 23
  • 36