HTML textarea resize: How to disable with 3 demos
How to disable textarea resizing
You may use the resize: none property to disable resizing of a textarea in a web browser.
Generally, the textarea can be stretched to expand that may affect different sections of a webpage.
By using the CSS, you may disable this overall or by specifying a particular direction as shown in the examples below.
A fixed size textarea example
By simply using resize: none property, you may disable resizing of a textarea. See this demo where this is assigned to the textarea in <style> section:
See online demo and code
You can see, textarea size cannot be increased or decreased horizontally or vertically. The size is specified by height and width properties by using CSS and it is fixed.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
<!DOCTYPE html> <html> <head> <style> textarea { resize: none; height:300px; width:300px; } </style> </head> <body> <h3>A demo of disabling textarea resize</h3> <textarea readonly > <!DOCTYPE html> <html> <head> <style> textarea { resize: none; } </style> </head> <body> <h3>A demo of disabling textarea resize</h3> </body> </html> </textarea> </body> </html> |
Allowing resizing of textarea vertically only
By using resize: vertical; property, you may restrict resizing of the textarea vertically. Click on the link or image below to open the demo page and try resizing the textarea vertically and horizontally:
See online demo and code
The code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
<!DOCTYPE html> <html> <head> <style> .txtarea { resize: vertical; height:200px; width:200px; } </style> </head> <body> <h3>A demo of resize vertically</h3> <textarea class="txtarea" readonly > <!DOCTYPE html> <html> <head> <style> textarea { resize: none; } </style> </head> <body> <h3>A demo of disabling textarea resize</h3> </body> </html> </textarea> </body> </html> |
A demo of horizontal resizing
In this demo, only horizontal resizing is enabled.
See online demo and code
The code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
<!DOCTYPE html> <html> <head> <style> .txtarea { resize: horizontal; height:250px; width:250px; } </style> </head> <body> <h3>A demo of resize horizontally</h3> <textarea class="txtarea" readonly > <!DOCTYPE html> <html> <head> <style> textarea { resize: none; } </style> </head> <body> <h3>Horizontally resize</h3> </body> </html> </textarea> </body> </html> |
In above two examples, you can see the CSS classes are used rather generally specifying the textarea in style section.
This is because the specific properties will apply to only particular textarea where you assign this class. If textarea was used like in the first example, the restriction would have applied to all textarea in the web page.