Changing the text cursor with CSS caret-color
The blinking marker that shows where typed text will appear is the insertion caret. CSS lets you change its colour independently from the text with caret-color:
input {
caret-color: blue;
}
textarea {
caret-color: green;
}
The property also works on editable elements:
<h1 contenteditable="true">
This is an editable heading.
</h1>
h1[contenteditable] {
caret-color: blue;
}
This is most useful when the default caret has poor contrast against a custom input background. Keep it visible; matching it to the background rather defeats the point.
Enjoyed reading this?
If you found this article helpful, consider supporting my writing. Every little bit helps keep this blog going.
Related articles
- Making Links Easy to Recognize
Make links recognisable with underlines, clear focus states, useful text, and behaviour that does not surprise the reader.
- When CSS Layout Order Stops Matching the HTML
Keep Grid and Flexbox layouts aligned with the HTML order so keyboard focus and screen reader reading do not jump around the page.
- Keyboard Focus Styles With :focus-visible
Keep a clear keyboard focus indicator while avoiding the same focus ring after every pointer interaction.