๐ What Is caret-color?
The caret-color property controls the color of thetext cursor (caret) inside editable elements like<input>, <textarea>, and contenteditable elements.
The caret is the blinking vertical bar that appears when you type. With caret-color, you can match the cursor to your brand or theme.
Note
โ Supports all modern browsers
โ Accepts any CSS color value
๐ฆ Syntax
caret-color syntax
caret-color: auto | <color>;| Value | Description |
|---|---|
| auto | Default caret color (usually text color). |
| <color> | Any CSS color: hex, rgb, hsl, color(), named colors, etc. |
๐ 1. Basic Example
Simple caret color
input {
caret-color: #ff5722; /* Orange caret */
}The caret becomes orange inside input fields.
๐ 2. Use Caret Color on Textareas
Textarea styling
textarea {
caret-color: dodgerblue;
}A bright blue caret improves visibility on light backgrounds.
๐ 3. Match Caret to Dark Mode
Dark mode caret
input {
caret-color: #00e5ff;
}
@media (prefers-color-scheme: dark) {
input {
caret-color: #80ffff; /* Brighter caret for dark backgrounds */
}
}Ensures the caret stays visible in both light and dark UI themes.
๐ 4. Use CSS Variables With Caret Color
CSS variable caret
:root {
--caret-theme: #9c27b0;
}
input[type="text"] {
caret-color: var(--caret-theme);
}Makes caret color themeable across large applications.
๐ 5. Custom Caret for Contenteditable Elements
contenteditable
[contenteditable="true"] {
caret-color: limegreen;
}Great for editors, note-taking apps, or chat interfaces.
๐ 6. Invisible Caret (Special Use Case)
Transparent caret
.no-caret {
caret-color: transparent;
}Used for special UI effects, pseudo-inputs, or read-only editing modes.
๐งช Real-World Examples
1๏ธโฃ Modern Login Form
Login form caret
.login input {
caret-color: #4caf50; /* Green caret */
}2๏ธโฃ Code Editor (contenteditable)
Editor caret
.editor {
caret-color: #ff4081; /* Pink caret */
}Stylish caret for coding interfaces.
3๏ธโฃ Chat App Input
Chat input
.chat-input {
caret-color: #2196f3;
}โ ๏ธ Common Mistakes
- โ Setting caret-color on elements that are not editable
- โ Choosing colors with low contrast โ caret becomes invisible
- โ Forgetting theme-specific caret colors (light vs dark mode)
Note
๐ฅ Summary
The caret-color property gives you precise control over the color of the blinking cursor inside text inputs, text areas, and editable elements. It enhances readability, accessibility, and brand consistency.
Learn more โMDN Docs ๐