Textarea

Bootstrap Textarea input - forms examples & tutorial

Responsive textarea built with Bootstrap 5. How to change size, height, width and style. Examples of comments, contact form, checkout and chat.

To learn more read Form Docs.


Basic example

A basic example of a simple textarea.

        
            
          <div class="form-outline">
            <textarea class="form-control" id="textAreaExample1" rows="4"></textarea>
            <label class="form-label" for="textAreaExample">Message</label>
          </div>
        
        
    

Definition

A Bootstrap Textarea is an input dedicated to a large volume of text. It may be used in a variety of components like forms, comment sections, chats and forums.

Textarea can hold an unlimited number of characters, and the text renders in a fixed-width font.

The name attribute is needed to reference the form data after the form is submitted (if you omit the name attribute, no data from the text area will be submitted).

The id attribute is needed to associate the text area with a label. 


Height

To change the height of the textarea you need to change the value of rows attribute.

        
            
          <!-- Textarea 8 rows height -->
          <div class="form-outline">
            <textarea class="form-control" id="textAreaExample2" rows="8"></textarea>
            <label class="form-label" for="textAreaExample2">Message</label>
          </div>

          <!-- Textarea 2 rows height -->
          <div class="form-outline">
            <textarea class="form-control" id="textAreaExample3" rows="2"></textarea>
            <label class="form-label" for="textAreaExample3">Message</label>
          </div>
        
        
    

Width

To change the width of the textarea use bootstrap sizing utilities or bootstrap grid system.

To learn more read Sizing docs.

Textarea with class .w-25

Textarea with class .w-50

Textarea with class .w-75

Textarea without sizing class

        
            
          <!-- Textarea with class .w-25 -->
          <div class="form-outline w-25 mb-4">
            <textarea class="form-control" id="textAreaExample4" rows="3"></textarea>
            <label class="form-label" for="textAreaExample4">25% width of the parent</label>
          </div>

          <!-- Textarea with class .w-50 -->
          <div class="form-outline w-50 mb-4">
            <textarea class="form-control" id="textAreaExample5" rows="3"></textarea>
            <label class="form-label" for="textAreaExample5">50% width of the parent</label>
          </div>

          <!-- Textarea with class .w-75 -->
          <div class="form-outline w-75 mb-4">
            <textarea class="form-control" id="textAreaExample6" rows="3"></textarea>
            <label class="form-label" for="textAreaExample6">75% width of the parent</label>
          </div>

          <!-- Textarea without sizing class -->
          <div class="form-outline mb-4">
            <textarea class="form-control" id="textAreaExample6" rows="3"></textarea>
            <label class="form-label" for="textAreaExample6">100% width of the parent</label>
          </div>
        
        
    

Usage examples

A few practical examples of textarea usage.

Contact form

A typical subscription form used when subscribing to the newsletter.

        
            
            <form>
              <!-- Name input -->
              <div class="form-outline mb-4">
                <input type="text" id="form4Example1" class="form-control" />
                <label class="form-label" for="form4Example1">Name</label>
              </div>

              <!-- Email input -->
              <div class="form-outline mb-4">
                <input type="email" id="form4Example2" class="form-control" />
                <label class="form-label" for="form4Example2">Email address</label>
              </div>

              <!-- Message input -->
              <div class="form-outline mb-4">
                <textarea class="form-control" id="form4Example3" rows="4"></textarea>
                <label class="form-label" for="form4Example3">Message</label>
              </div>

              <!-- Checkbox -->
              <div class="form-check d-flex justify-content-center mb-4">
                <input
                  class="form-check-input me-2"
                  type="checkbox"
                  value=""
                  id="form4Example4"
                  checked
                />
                <label class="form-check-label" for="form4Example4">
                  Send me a copy of this message
                </label>
              </div>

              <!-- Submit button -->
              <button type="submit" class="btn btn-primary btn-block mb-4">
                Send
              </button>
            </form>
          
        
    

Checkout form

An example of the extended form with typical checkout inputs.

        
            
            <form>
              <!-- 2 column grid layout with text inputs for the first and last names -->
              <div class="row mb-4">
                <div class="col">
                  <div class="form-outline">
                    <input type="text" id="form6Example1" class="form-control" />
                    <label class="form-label" for="form6Example1">First name</label>
                  </div>
                </div>
                <div class="col">
                  <div class="form-outline">
                    <input type="text" id="form6Example2" class="form-control" />
                    <label class="form-label" for="form6Example2">Last name</label>
                  </div>
                </div>
              </div>

              <!-- Text input -->
              <div class="form-outline mb-4">
                <input type="text" id="form6Example3" class="form-control" />
                <label class="form-label" for="form6Example3">Company name</label>
              </div>

              <!-- Text input -->
              <div class="form-outline mb-4">
                <input type="text" id="form6Example4" class="form-control" />
                <label class="form-label" for="form6Example4">Address</label>
              </div>

              <!-- Email input -->
              <div class="form-outline mb-4">
                <input type="email" id="form6Example5" class="form-control" />
                <label class="form-label" for="form6Example5">Email</label>
              </div>

              <!-- Number input -->
              <div class="form-outline mb-4">
                <input type="number" id="form6Example6" class="form-control" />
                <label class="form-label" for="form6Example6">Phone</label>
              </div>

              <!-- Message input -->
              <div class="form-outline mb-4">
                <textarea class="form-control" id="form6Example7" rows="4"></textarea>
                <label class="form-label" for="form6Example7">Additional information</label>
              </div>

              <!-- Checkbox -->
              <div class="form-check d-flex justify-content-center mb-4">
                <input
                  class="form-check-input me-2"
                  type="checkbox"
                  value=""
                  id="form6Example8"
                  checked
                />
                <label class="form-check-label" for="form6Example8">
                  Create an account?
                </label>
              </div>

              <!-- Submit button -->
              <button type="submit" class="btn btn-primary btn-block mb-4">
                Place order
              </button>
            </form>
          
        
    

Simple comment card

avatar
Lily Coleman

Shared publicly - Jan 2020

Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip consequat.

        
            
            <section style="background-color: #eee;">
              <div class="container my-5 py-5">
                <div class="row d-flex justify-content-center">
                  <div class="col-md-12 col-lg-10 col-xl-8">
                    <div class="card">
                      <div class="card-body">
                        <div class="d-flex flex-start align-items-center">
                          <img
                            class="rounded-circle shadow-1-strong me-3"
                            src="https://mdbootstrap.com/img/Photos/Avatars/img%20(19).jpg"
                            alt="avatar"
                            width="60"
                            height="60"
                          />
                          <div>
                            <h6 class="fw-bold text-primary mb-1">
                              Lily Coleman
                            </h6>
                            <p class="text-muted small mb-0">
                              Shared publicly - Jan 2020
                            </p>
                          </div>
                        </div>

                        <p class="mt-3 mb-4 pb-2">
                          Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
                          tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
                          veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
                          consequat.
                        </p>

                        <div class="small d-flex justify-content-start">
                          <a href="#!" class="d-flex align-items-center me-3">
                            <i class="far fa-thumbs-up me-2"></i>
                            <p class="mb-0">Like</p>
                          </a>
                          <a href="#!" class="d-flex align-items-center me-3">
                            <i class="far fa-comment-dots me-2"></i>
                            <p class="mb-0">Comment</p>
                          </a>
                          <a href="#!" class="d-flex align-items-center me-3">
                            <i class="fas fa-share me-2"></i>
                            <p class="mb-0">Share</p>
                          </a>
                        </div>
                      </div>
                      <div class="card-footer py-3 border-0" style="background-color: #f8f9fa;">
                        <div class="d-flex flex-start w-100">
                          <img
                            class="rounded-circle shadow-1-strong me-3"
                            src="https://mdbootstrap.com/img/Photos/Avatars/img%20(19).jpg"
                            alt="avatar"
                            width="40"
                            height="40"
                          />
                          <div class="form-outline w-100">
                            <textarea
                              class="form-control"
                              id="textAreaExample"
                              rows="4"
                              style="background: #fff;"
                            ></textarea>
                            <label class="form-label" for="textAreaExample">Message</label>
                          </div>
                        </div>
                        <div class="float-end mt-2 pt-1">
                          <button type="button" class="btn btn-primary btn-sm">
                            Post comment
                          </button>
                          <button type="button" class="btn btn-outline-primary btn-sm">
                            Cancel
                          </button>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </section>
          
        
    

Add a comment

avatar
Add a comment
        
            
            <section style="background-color: #d94125;">
              <div class="container my-5 py-5 text-dark">
                <div class="row d-flex justify-content-center">
                  <div class="col-md-10 col-lg-8 col-xl-6">
                    <div class="card">
                      <div class="card-body p-4">
                        <div class="d-flex flex-start w-100">
                          <img
                            class="rounded-circle shadow-1-strong me-3"
                            src="https://mdbootstrap.com/img/Photos/Avatars/img%20(21).jpg"
                            alt="avatar"
                            width="65"
                            height="65"
                          />
                          <div class="w-100">
                            <h5>Add a comment</h5>
                            <ul class="rating mb-3" data-mdb-toggle="rating">
                              <li>
                                <i class="far fa-star fa-sm text-danger" title="Bad"></i>
                              </li>
                              <li>
                                <i class="far fa-star fa-sm text-danger" title="Poor"></i>
                              </li>
                              <li>
                                <i class="far fa-star fa-sm text-danger" title="OK"></i>
                              </li>
                              <li>
                                <i class="far fa-star fa-sm text-danger" title="Good"></i>
                              </li>
                              <li>
                                <i class="far fa-star fa-sm text-danger" title="Excellent"></i>
                              </li>
                            </ul>
                            <div class="form-outline">
                              <textarea
                                class="form-control"
                                id="textAreaExample"
                                rows="4"
                              ></textarea>
                              <label class="form-label" for="textAreaExample"
                                >What is your view?</label
                              >
                            </div>
                            <div class="d-flex justify-content-between mt-3">
                              <button type="button" class="btn btn-success">
                                Danger
                              </button>
                              <button type="button" class="btn btn-danger">
                                Send
                                <i class="fas fa-long-arrow-alt-right ms-1"></i>
                              </button>
                            </div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
            </section>
          
        
    

Chat

  • avatar

    Brad Pitt

    12 mins ago

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

  • Lara Croft

    13 mins ago

    Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium.

    avatar
  • avatar

    Brad Pitt

    10 mins ago

    Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

        
            
            <section class="gradient-custom">
              <div class="container py-5">
                <div class="row">
                  <div class="col-md-6 col-lg-5 col-xl-5 mb-4 mb-md-0">
                    <h5 class="font-weight-bold mb-3 text-center text-white">
                      Member
                    </h5>

                    <div class="card mask-custom">
                      <div class="card-body">
                        <ul class="list-unstyled mb-0">
                          <li
                            class="p-2 border-bottom"
                            style="border-bottom: 1px solid rgba(255, 255, 255, 0.3) !important;"
                          >
                            <a href="#!" class="d-flex justify-content-between link-light">
                              <div class="d-flex flex-row">
                                <img
                                  src="https://mdbootstrap.com/img/Photos/Avatars/avatar-8.jpg"
                                  alt="avatar"
                                  class="rounded-circle d-flex align-self-center me-3 shadow-1-strong"
                                  width="60"
                                />
                                <div class="pt-1">
                                  <p class="fw-bold mb-0">
                                    John Doe
                                  </p>
                                  <p class="small text-white">
                                    Hello, Are you there?
                                  </p>
                                </div>
                              </div>
                              <div class="pt-1">
                                <p class="small text-white mb-1">
                                  Just now
                                </p>
                                <span class="badge bg-danger float-end">1</span>
                              </div>
                            </a>
                          </li>
                          <li
                            class="p-2 border-bottom"
                            style="border-bottom: 1px solid rgba(255, 255, 255, 0.3) !important;"
                          >
                            <a href="#!" class="d-flex justify-content-between link-light">
                              <div class="d-flex flex-row">
                                <img
                                  src="https://mdbootstrap.com/img/Photos/Avatars/avatar-1.jpg"
                                  alt="avatar"
                                  class="rounded-circle d-flex align-self-center me-3 shadow-1-strong"
                                  width="60"
                                />
                                <div class="pt-1">
                                  <p class="fw-bold mb-0">
                                    Danny Smith
                                  </p>
                                  <p class="small text-white">
                                    Lorem ipsum dolor sit.
                                  </p>
                                </div>
                              </div>
                              <div class="pt-1">
                                <p class="small text-white mb-1">
                                  5 mins ago
                                </p>
                              </div>
                            </a>
                          </li>
                          <li
                            class="p-2 border-bottom"
                            style="border-bottom: 1px solid rgba(255, 255, 255, 0.3) !important;"
                          >
                            <a href="#!" class="d-flex justify-content-between link-light">
                              <div class="d-flex flex-row">
                                <img
                                  src="https://mdbootstrap.com/img/Photos/Avatars/avatar-2.jpg"
                                  alt="avatar"
                                  class="rounded-circle d-flex align-self-center me-3 shadow-1-strong"
                                  width="60"
                                />
                                <div class="pt-1">
                                  <p class="fw-bold mb-0">
                                    Alex Steward
                                  </p>
                                  <p class="small text-white">
                                    Lorem ipsum dolor sit.
                                  </p>
                                </div>
                              </div>
                              <div class="pt-1">
                                <p class="small text-white mb-1">
                                  Yesterday
                                </p>
                              </div>
                            </a>
                          </li>
                          <li
                            class="p-2 border-bottom"
                            style="border-bottom: 1px solid rgba(255, 255, 255, 0.3) !important;"
                          >
                            <a href="#!" class="d-flex justify-content-between link-light">
                              <div class="d-flex flex-row">
                                <img
                                  src="https://mdbootstrap.com/img/Photos/Avatars/avatar-3.jpg"
                                  alt="avatar"
                                  class="rounded-circle d-flex align-self-center me-3 shadow-1-strong"
                                  width="60"
                                />
                                <div class="pt-1">
                                  <p class="fw-bold mb-0">
                                    Ashley Olsen
                                  </p>
                                  <p class="small text-white">
                                    Lorem ipsum dolor sit.
                                  </p>
                                </div>
                              </div>
                              <div class="pt-1">
                                <p class="small text-white mb-1">
                                  Yesterday
                                </p>
                              </div>
                            </a>
                          </li>
                          <li
                            class="p-2 border-bottom"
                            style="border-bottom: 1px solid rgba(255, 255, 255, 0.3) !important;"
                          >
                            <a href="#!" class="d-flex justify-content-between link-light">
                              <div class="d-flex flex-row">
                                <img
                                  src="https://mdbootstrap.com/img/Photos/Avatars/avatar-4.jpg"
                                  alt="avatar"
                                  class="rounded-circle d-flex align-self-center me-3 shadow-1-strong"
                                  width="60"
                                />
                                <div class="pt-1">
                                  <p class="fw-bold mb-0">
                                    Kate Moss
                                  </p>
                                  <p class="small text-white">
                                    Lorem ipsum dolor sit.
                                  </p>
                                </div>
                              </div>
                              <div class="pt-1">
                                <p class="small text-white mb-1">
                                  Yesterday
                                </p>
                              </div>
                            </a>
                          </li>
                          <li
                            class="p-2 border-bottom"
                            style="border-bottom: 1px solid rgba(255, 255, 255, 0.3) !important;"
                          >
                            <a href="#!" class="d-flex justify-content-between link-light">
                              <div class="d-flex flex-row">
                                <img
                                  src="https://mdbootstrap.com/img/Photos/Avatars/avatar-5.jpg"
                                  alt="avatar"
                                  class="rounded-circle d-flex align-self-center me-3 shadow-1-strong"
                                  width="60"
                                />
                                <div class="pt-1">
                                  <p class="fw-bold mb-0">
                                    Lara Croft
                                  </p>
                                  <p class="small text-white">
                                    Lorem ipsum dolor sit.
                                  </p>
                                </div>
                              </div>
                              <div class="pt-1">
                                <p class="small text-white mb-1">
                                  Yesterday
                                </p>
                              </div>
                            </a>
                          </li>
                          <li class="p-2">
                            <a href="#!" class="d-flex justify-content-between link-light">
                              <div class="d-flex flex-row">
                                <img
                                  src="https://mdbootstrap.com/img/Photos/Avatars/avatar-6.jpg"
                                  alt="avatar"
                                  class="rounded-circle d-flex align-self-center me-3 shadow-1-strong"
                                  width="60"
                                />
                                <div class="pt-1">
                                  <p class="fw-bold mb-0">
                                    Brad Pitt
                                  </p>
                                  <p class="small text-white">
                                    Lorem ipsum dolor sit.
                                  </p>
                                </div>
                              </div>
                              <div class="pt-1">
                                <p class="small text-white mb-1">
                                  5 mins ago
                                </p>
                                <span class="text-white float-end"
                                  ><i class="fas fa-check" aria-hidden="true"></i
                                ></span>
                              </div>
                            </a>
                          </li>
                        </ul>
                      </div>
                    </div>
                  </div>

                  <div class="col-md-6 col-lg-7 col-xl-7">
                    <ul class="list-unstyled text-white">
                      <li class="d-flex justify-content-between mb-4">
                        <img
                          src="https://mdbootstrap.com/img/Photos/Avatars/avatar-6.jpg"
                          alt="avatar"
                          class="rounded-circle d-flex align-self-start me-3 shadow-1-strong"
                          width="60"
                        />
                        <div class="card mask-custom">
                          <div
                            class="card-header d-flex justify-content-between p-3"
                            style="border-bottom: 1px solid rgba(255, 255, 255, 0.3);"
                          >
                            <p class="fw-bold mb-0">Brad Pitt</p>
                            <p class="text-light small mb-0">
                              <i class="far fa-clock"></i> 12 mins ago
                            </p>
                          </div>
                          <div class="card-body">
                            <p class="mb-0">
                              Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
                              eiusmod tempor incididunt ut labore et dolore magna aliqua.
                            </p>
                          </div>
                        </div>
                      </li>
                      <li class="d-flex justify-content-between mb-4">
                        <div class="card mask-custom w-100">
                          <div
                            class="card-header d-flex justify-content-between p-3"
                            style="border-bottom: 1px solid rgba(255, 255, 255, 0.3);"
                          >
                            <p class="fw-bold mb-0">Lara Croft</p>
                            <p class="text-light small mb-0">
                              <i class="far fa-clock"></i> 13 mins ago
                            </p>
                          </div>
                          <div class="card-body">
                            <p class="mb-0">
                              Sed ut perspiciatis unde omnis iste natus error sit voluptatem
                              accusantium doloremque laudantium.
                            </p>
                          </div>
                        </div>
                        <img
                          src="https://mdbootstrap.com/img/Photos/Avatars/avatar-5.jpg"
                          alt="avatar"
                          class="rounded-circle d-flex align-self-start ms-3 shadow-1-strong"
                          width="60"
                        />
                      </li>
                      <li class="d-flex justify-content-between mb-4">
                        <img
                          src="https://mdbootstrap.com/img/Photos/Avatars/avatar-6.jpg"
                          alt="avatar"
                          class="rounded-circle d-flex align-self-start me-3 shadow-1-strong"
                          width="60"
                        />
                        <div class="card mask-custom">
                          <div
                            class="card-header d-flex justify-content-between p-3"
                            style="border-bottom: 1px solid rgba(255, 255, 255, 0.3);"
                          >
                            <p class="fw-bold mb-0">Brad Pitt</p>
                            <p class="text-light small mb-0">
                              <i class="far fa-clock"></i> 10 mins ago
                            </p>
                          </div>
                          <div class="card-body">
                            <p class="mb-0">
                              Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
                              eiusmod tempor incididunt ut labore et dolore magna aliqua.
                            </p>
                          </div>
                        </div>
                      </li>
                      <li class="mb-3">
                        <div class="form-outline form-white">
                          <textarea class="form-control" id="textAreaExample" rows="4"></textarea>
                          <label class="form-label" for="textAreaExample">Message</label>
                        </div>
                      </li>
                      <button type="button" class="btn btn-light btn-lg btn-rounded float-end">
                        Send
                      </button>
                    </ul>
                  </div>
                </div>
              </div>
            </section>
          
        
    
        
            
            .gradient-custom {
              /* fallback for old browsers */
              background: #fccb90;
            
              /* Chrome 10-25, Safari 5.1-6 */
              background: -webkit-linear-gradient(to bottom right, rgba(252, 203, 144, 1), rgba(213, 126, 235, 1));
            
              /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */
              background: linear-gradient(to bottom right, rgba(252, 203, 144, 1), rgba(213, 126, 235, 1))
            }
            
            .mask-custom {
              background: rgba(24, 24, 16, .2);
              border-radius: 2em;
              backdrop-filter: blur(15px);
              border: 2px solid rgba(255, 255, 255, 0.05);
              background-clip: padding-box;
              box-shadow: 10px 10px 10px rgba(46, 54, 68, 0.03);
            }
          
        
    

If you want to support our friends from Tailwind Elements you can also check out the Tailwind textarea documentation.