w3docs logo
  1. Snippets
  2. HTML
  3. How to Set the Size of the <textarea> Element

How to Set the Size of the <textarea> Element

Solutions with HTML and CSS

There are two ways of setting the size of the HTML <textarea> element. You can use HTML or CSS.

In HTML, you can use the cols and rows attributes. Let’s see this solution in use.

Example of setting the textarea size with HTML:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
  </head>
  <body>
    <form action="/form/submit" method="post">
      <textarea name="textarea" rows="5" cols="40">Write something here</textarea>
      <br>
      <input type="submit" name="submitInfo" value="Submit">
    </form>
  </body>
</html>

Result


In CSS, you need to use the width and height properties for the <textarea> element.

Example of setting the textarea size with CSS:

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      textarea {
        width: 250px;
        height: 100px;
      }
    </style>
  </head>
  <body>
    <form action="/form/submit" method="post">
      <textarea> </textarea>
      <br>
      <input type="submit" name="submitInfo" value="Submit">
    </form>
  </body>
</html>
Do you find this helpful?