CSS propertyInteraction and more
caret-color
Sets the colour of the text cursor in input fields.
- Initial value
auto- Inherited
- Yes
- Animatable
- yes, as a colour
- Applies to
- all elements, the effect is visible in editable fields
- JavaScript
element.style.caretColor = "#a78bfa"
Example
#CSS
.code-editor {
caret-color: #facc15;
}Example HTML
<textarea spellcheck="false" style="width: 100%; height: 70px; padding: 8px; font-family: monospace; background: #0a0a0b; caret-color: #facc15; border-radius: 8px;">const lesson = "CSS"</textarea>Preview
Definition and usage
#The caret-color property changes the colour of the blinking bar that shows the typing position in <input> and <textarea> fields and in elements with contenteditable.
By default (auto) the caret usually has the text colour. A custom colour helps match fields to the page theme or highlight the active field.
The transparent value hides the caret, but do that only in exceptional cases, for example in fields that look like an on-screen keyboard.
Syntax
#Syntax
caret-color: auto | <color>;Values
#Values in practice
#auto
A caret in the text colour.
.demo { caret-color: auto; }#f43f5e
A red caret.
.demo { caret-color: #f43f5e; }#a78bfa
A purple caret matching the accent.
.demo { caret-color: #a78bfa; }Browser support
#Widely available
Works in all modern browsers, phones included. You can use it without worry.
- Chrome
- Edge
- Firefox
- Safari
Good practices
#- In code editors, a bright caret makes it easier to track where you are typing.
- Don’t hide the caret in ordinary fields, because the user won’t know where they are typing.
Related entries
#Spotted a mistake or missing an example? Write to us.