CSS Reference ยท Typography
The caret-color property
Reference for the CSS caret-color property: change the color of the blinking text insertion caret in inputs, textareas and editable elements, with a live demo.
The caret is the thin blinking line that shows where typed text will appear in an input, a textarea or any element with contenteditable. The caret-color property changes its color. By default the caret uses the same color as the text, which is usually fine, but on dark or branded designs a custom color can make it easier to see.
The property only changes the color. Its width and blink rate are chosen by the browser and the operating system.
input, textarea { caret-color: #e0245e; }
Try it
When a field has focus, its caret blinks in the chosen color. If you do not see it, click inside the field first, because a preview does not move focus automatically.
Syntax
caret-color: auto | <color>;
| Initial value | auto |
| Applies to | all elements |
| Inherited | yes |
| Animatable | yes, as a color (auto is not interpolated) |
| Computed value | auto, or the computed color |
Values
| Value | Description |
|---|---|
auto |
The browser chooses the color, usually currentcolor, the text color of the element. |
<color> |
Any CSS color: a name, hex value, rgb(), hsl(), oklch() and so on. |
Usage notes
- Where it appears. Only in places where the user can type:
<input>of text types,<textarea>and elements withcontenteditable. Setting it on other elements does nothing visible, but the value is inherited, so it can be set once onbodyor:root. - Never hide the caret.
caret-color: transparentmakes it invisible and leaves users unsure where they are typing. It is acceptable only for special editors that draw their own caret. - Contrast. The caret should stand out against the field background. A caret that matches the background color is invisible.
- Pair with
accent-color. For forms with a brand color, useaccent-colorfor checkboxes and radios andcaret-colorfor text fields. - Inheritance helps theming. Set it on a theme class and every field inside follows.
- Not for the selection. Selected text is styled with the
::selectionpseudo-element, not withcaret-color. - Newer caret features. There are also newer properties for the caret shape and animation; they are not widely available, so check a compatibility table before using them.
Browser support
Supported in all current browsers.
Related
accent-colorโ colors form controlscolorโ text coloruser-selectโ controls text selection- Lesson: Forms