Languages
[Edit]
EN

CSS - style textarea HTML element

0 points
Created by:
elmer
646

In this article, we would like to show you how to style textarea HTML elements using CSS.

Quick solution:

textarea {
    background: yellow;
}

 

Practical example

In this example, we present how to use CSS type selector to style all textarea elements on the web page.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    textarea {
        background: #ffe973;
        border: 2px solid red;
    }

  </style>
</head>
<body>
  <textarea>Textarea 1 ...</textarea>
  <br>
  <textarea>Textarea 2 ...</textarea>
</body>
</html>

Advanced example 

In this section, we present advanced styling for textarea elements, :focus pseudo-class and  ::placeholder pseudo-element.

// ONLINE-RUNNER:browser;

<!doctype html>
<html>
<head>
  <style>

    label.field {
        display: flex;
    }

    label.field + label.field {
        margin: 10px 0 0 0;
    }

    span.label {
        min-width: 80px;
        font: 13px/26px Arial;
        color: #5f6368;
    }

    textarea.input {
        padding: 3px 6px;
        outline: 0;
        border: 1px solid #e4e4e4;
        border-radius: 3px;
        background: #ffffff;
        flex: 1;
        min-height: 3rem;
        font: 13px Arial;
        color: #495057;
        resize: vertical;
    }

    /* scrollbar style solution is available here:              */
    /* https://dirask.com/posts/CSS-set-scrollbar-colors-j89R91 */

    textarea.input:focus {
        border-color: #80bdff;
    }

    textarea.input::placeholder {  /* placeholder legacy solution is available here:                       */
        color: #c0c0c0;            /* https://dirask.com/posts/CSS-change-input-s-placeholder-color-DdZoKj */
    }

  </style>
</head>
<body>
  <label class="field">
    <span class="label">About me:</span>
    <textarea class="input" name="user-about" placeholder="Describe yourself ..."></textarea>
  </label>
  <label class="field">
    <span class="label">My skills:</span>
    <textarea class="input" name="user-skills" placeholder="Describe your skills ..."></textarea>
  </label>
</body>
</html>

 

See also

  1. CSS - change textarea size

  2. CSS - disable textarea resize button

References

  1. Type selectors - CSS: Cascading Style Sheets | MDN
  2. <textarea>: The Textarea element - HTML: HyperText Markup Language | MDN
  3. :focus - CSS: Cascading Style Sheets | MDN
  4. ::placeholder - CSS: Cascading Style Sheets | MDN

Alternative titles

  1. CSS - style textarea HTML elements
  2. CSS - style all HTML textareas on web page
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join