css

caret-color CSS property

phongduong

Phong Duong

Posted on December 12, 2020

caret-color CSS property

Caret is a cursor in the input, textarea elements. It shows where the next typed character will be inserted. caret-color property sets the color of the caret. It can also be used for the elements with contenteditable attribute. The default value of this attribute is auto. It will take currentcolor and usually black.

input
Enter fullscreen mode Exit fullscreen mode
input {
    color: red;
}
Enter fullscreen mode Exit fullscreen mode

When you type the text in the input, the text color is red. caret-color will take the value of color property.

textarea(rows="5")
Enter fullscreen mode Exit fullscreen mode
textarea {
    caret-color: transparent;
}
Enter fullscreen mode Exit fullscreen mode

caret-color can take transparent value but it is hard to see where the cursor is especially when you are inserting in between the text.

p(contenteditable="true") Please click this text and edit it

Enter fullscreen mode Exit fullscreen mode
p[contenteditable="true"] {
    background: black;
    color: yellowgreen;
    caret-color: tomato;
}

Enter fullscreen mode Exit fullscreen mode

Although caret-color takes the value of color property by default, you can set a different value to ensure good visibility.

Here is the full example

💖 💪 🙅 🚩
phongduong
Phong Duong

Posted on December 12, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related