EN
CSS - style textarea HTML element
0
points
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>