CSS caret-color Property

The caret-color property sets the color of the text insertion caret displayed in editable content.

The insertion caret is the blinking indicator that shows where the next character will appear when typing. It is commonly visible in text inputs, textareas, and elements with the contenteditable attribute.

By default, browsers choose an appropriate caret color, usually based on the text color. The caret-color property allows you to specify a different color without changing the surrounding text.

caret-color Syntax

Use caret-color with a CSS color value or the keyword auto.

selector {
  caret-color: #1769aa;
}

The general syntax is:

selector {
  caret-color: auto | <color>;
}

Automatic Color

input {
  caret-color: auto;
}

Named Color

input {
  caret-color: red;
}

Hexadecimal Color

input {
  caret-color: #1769aa;
}

RGB Color

textarea {
  caret-color: rgb(23 105 170);
}

Current Text Color

input {
  caret-color: currentColor;
}

Transparent Caret

input {
  caret-color: transparent;
}

CSS-Wide Keywords

input {
  caret-color: inherit;
}
input {
  caret-color: initial;
}
input {
  caret-color: unset;
}
input {
  caret-color: revert;
}
input {
  caret-color: revert-layer;
}

The property accepts standard CSS color values, including named colors, hexadecimal colors, RGB, HSL, and other supported color functions.

Property Values

The caret-color property accepts auto or a CSS color value.

Value Description
auto Allows the browser to choose the caret color. This is the initial value.
<color> Sets the caret to a specified CSS color.
currentColor Uses the element's current text color.
transparent Makes the insertion caret invisible.

Color Value Examples

Declaration Description
caret-color: red; Uses a named red color.
caret-color: #1769aa; Uses a hexadecimal blue color.
caret-color: rgb(0 128 0); Uses an RGB green color.
caret-color: hsl(280 70% 50%); Uses an HSL purple color.
caret-color: currentColor; Matches the current text color.
caret-color: transparent; Hides the visible caret.

CSS-Wide Keywords

Value Description
inherit Uses the computed value from the parent element.
initial Resets the property to auto.
unset Uses the inherited value because the property is inherited.
revert Reverts the property according to cascade origin rules.
revert-layer Reverts the property according to cascade layer rules.

Property Characteristics

Characteristic Value
Initial value auto
Inherited Yes
Applies to All elements, with a visible effect on elements displaying an insertion caret
Computed value auto or a computed color
Animation type By computed color type
Percentages Not applicable directly
Shorthand caret
Primary use Customizing the text insertion caret color

Although the property can be declared on any element, it is only visually relevant when a text insertion caret is displayed.

How It Works

The insertion caret becomes visible when a user focuses an editable control and places the text insertion point.

Step 1: Create a Text Input

<input type="text" class="custom-input" placeholder="Enter your name">

Step 2: Set the Caret Color

.custom-input {
  caret-color: #1769aa;
}

The insertion caret appears blue when the input has focus.

Step 3: Style the Input

.custom-input {
  padding: 10px;
  border: 1px solid #cccccc;
  color: #333333;
  background-color: #ffffff;
  caret-color: #1769aa;
}

The text remains dark gray while the caret uses the specified blue color.

Step 4: Add Focus Styling

.custom-input:focus-visible {
  outline: 2px solid #1769aa;
  outline-offset: 2px;
}

The focus outline identifies the active control, while the caret indicates where text will be inserted.

Step 5: Apply to Multiple Controls

input,
textarea {
  caret-color: #1769aa;
}

The same caret color is applied to text inputs and textareas that display an insertion caret.

Automatic Caret Color

The auto value allows the browser to choose an appropriate insertion caret color.

input {
  caret-color: auto;
}

Default Behavior

Browsers generally use the current text color for the caret, although the exact behavior may depend on the browser and operating system.

Dark Text

input {
  color: #222222;
  caret-color: auto;
}

Light Text

.dark-input {
  color: #eeeeee;
  background-color: #222222;
  caret-color: auto;
}

Restore Automatic Color

.custom-input {
  caret-color: #1769aa;
}
.default-input {
  caret-color: auto;
}

The second rule explicitly restores automatic caret color selection for the default-input class.

When to Use auto

Use auto when you want the browser to manage caret color or when overriding an earlier custom declaration.

Because auto is the initial value, it normally does not need to be declared.

Custom Caret Colors

The caret-color property accepts CSS color values, allowing the insertion caret to match a website's design.

Named Color

input {
  caret-color: blue;
}

Hexadecimal Color

input {
  caret-color: #1769aa;
}

RGB Color

input {
  caret-color: rgb(23 105 170);
}

HSL Color

input {
  caret-color: hsl(205 76% 38%);
}

Color with Transparency

input {
  caret-color: rgb(23 105 170 / 80%);
}

CSS Custom Property

:root {
  --input-caret-color: #1769aa;
}
input,
textarea {
  caret-color: var(--input-caret-color);
}

Different Colors for Different Fields

.name-input {
  caret-color: #1769aa;
}
.email-input {
  caret-color: #008855;
}
.message-input {
  caret-color: #9933cc;
}

Custom caret colors can help maintain a consistent visual style, but the selected color should remain easy to distinguish from the control's background.

Using currentColor

The currentColor keyword makes the insertion caret use the element's computed text color.

input {
  color: #1769aa;
  caret-color: currentColor;
}

Match the Text Color

textarea {
  color: #333333;
  caret-color: currentColor;
}

Dark Theme

.dark-input {
  color: #eeeeee;
  background-color: #222222;
  caret-color: currentColor;
}

Change Text and Caret Together

.custom-input {
  color: #1769aa;
  caret-color: currentColor;
}
.custom-input:focus {
  color: #008855;
}

When the text color changes to green, the caret also uses that color.

currentColor vs. auto

The currentColor keyword explicitly uses the text color. The auto value allows the browser to determine the caret color, which generally produces a similar result.

Use currentColor when you specifically want the caret to follow the element's text color.

Transparent Caret

The transparent value makes the text insertion caret invisible.

input {
  caret-color: transparent;
}

Text Editing Still Works

Making the caret transparent does not prevent users from typing or editing text. It only hides the visible insertion indicator.

Transparent Caret in a Textarea

textarea {
  caret-color: transparent;
}

Restore Caret Visibility

input {
  caret-color: transparent;
}
input:focus {
  caret-color: #1769aa;
}

This example restores a visible caret when the input receives focus.

Accessibility Warning

An invisible insertion caret can make text editing difficult because users cannot easily determine where new text will appear.

Avoid caret-color: transparent in ordinary form controls unless an accessible alternative insertion indicator is provided.

Form Controls

The caret-color property is commonly used with form controls that accept text input.

Text Input

input[type="text"] {
  caret-color: #1769aa;
}

Email Input

input[type="email"] {
  caret-color: #1769aa;
}

Search Input

input[type="search"] {
  caret-color: #008855;
}

Password Input

input[type="password"] {
  caret-color: #1769aa;
}

Textarea

textarea {
  caret-color: #9933cc;
}

All Text Inputs and Textareas

input,
textarea {
  caret-color: #1769aa;
}

Target a Specific Form

.contact-form input,
.contact-form textarea {
  caret-color: #1769aa;
}

The property does not create an insertion caret in controls that do not support text editing, such as buttons, checkboxes, or radio buttons.

Editable Content

Elements using the HTML contenteditable attribute can display a text insertion caret.

Editable HTML Element

<div class="editable-box" contenteditable="true">
  Click here and edit this text.
</div>

Custom Caret Color

.editable-box {
  padding: 12px;
  border: 1px solid #cccccc;
  caret-color: #1769aa;
}

Dark-Themed Editor

<div class="code-editor" contenteditable="true" spellcheck="false">
  Edit this sample text.
</div>
.code-editor {
  padding: 15px;
  color: #eeeeee;
  background-color: #222222;
  font-family: monospace;
  caret-color: #66ccff;
}

Apply to All Editable Elements

[contenteditable="true"] {
  caret-color: #1769aa;
}

Focus Styling

.editable-box:focus-visible {
  outline: 2px solid #1769aa;
  outline-offset: 2px;
}

The focus outline identifies the active editing area, while the insertion caret identifies the position where typed text will appear.

For custom editors, ensure that the caret remains visible against the editor's background.

Focus Styling

The caret is most noticeable when an editable element receives focus.

Caret Color on Focus

input:focus {
  caret-color: #1769aa;
}

Caret and Border Color

input {
  border: 1px solid #cccccc;
}
input:focus {
  border-color: #1769aa;
  caret-color: #1769aa;
}

Caret and Focus Outline

input:focus-visible {
  outline: 2px solid #1769aa;
  outline-offset: 2px;
  caret-color: #1769aa;
}

Different Caret Color on Focus

input {
  caret-color: #666666;
}
input:focus {
  caret-color: #008855;
}

Focus vs. Caret

The focus indicator shows which element is active. The insertion caret shows where text will be entered within that element.

Changing caret-color does not replace the need for a visible keyboard focus indicator.

Caret Animation

The caret-color property can be animated to change the insertion caret's color over time.

Color Animation

@keyframes caret-color-change {
  0% {
    caret-color: #1769aa;
  }
  50% {
    caret-color: #008855;
  }
  100% {
    caret-color: #1769aa;
  }
}
.animated-input {
  animation: caret-color-change 2s linear infinite;
}

Blinking with Transparency

@keyframes custom-caret-blink {
  50% {
    caret-color: transparent;
  }
}
.animated-input {
  caret-color: #1769aa;
  caret-animation: manual;
  animation: custom-caret-blink 1s step-end infinite;
}

The caret-animation: manual declaration disables the browser's automatic caret blinking in supporting browsers, allowing the custom animation to control visibility.

Reduced Motion

@media (prefers-reduced-motion: reduce) {
  .animated-input {
    animation: none;
  }
}

Browser Support Considerations

Although caret-color is widely supported, manual caret animation control is newer and has limited browser availability.

For ordinary form controls, the browser's default blinking behavior is generally preferable to a custom animation.

Accessibility

The insertion caret helps users identify where typed text will appear. Its color should remain visible against the background of the editable area.

Maintain Good Contrast

input {
  color: #222222;
  background-color: #ffffff;
  caret-color: #1769aa;
}

Dark Backgrounds

.dark-input {
  color: #eeeeee;
  background-color: #222222;
  caret-color: #66ccff;
}

Avoid Invisible Carets

input {
  caret-color: transparent;
}

This declaration hides the insertion caret and can make editing difficult. Avoid it unless a suitable alternative indicator is available.

Preserve Focus Indicators

input:focus-visible {
  outline: 2px solid #1769aa;
  outline-offset: 2px;
}

Consider Color Themes

input {
  color: #222222;
  background-color: #ffffff;
  caret-color: currentColor;
}
@media (prefers-color-scheme: dark) {
  input {
    color: #eeeeee;
    background-color: #222222;
  }
}

Using currentColor allows the caret to follow the text color when the color theme changes.

Avoid Distracting Effects

Custom caret colors should improve visibility without distracting users from the text they are entering.

Preserve native keyboard editing and selection behavior whenever possible.

Practical Uses

The caret-color property can help text inputs and editable areas match the visual design of a website.

Branded Text Input

.brand-input {
  caret-color: #1769aa;
}

Search Field

.search-input {
  caret-color: #008855;
}

Contact Form

.contact-form input,
.contact-form textarea {
  caret-color: #1769aa;
}

Dark-Themed Editor

.dark-editor {
  color: #eeeeee;
  background-color: #222222;
  caret-color: #66ccff;
}

Editable Content

[contenteditable="true"] {
  caret-color: #1769aa;
}

Match the Text Color

input {
  color: #333333;
  caret-color: currentColor;
}

CSS Custom Property

:root {
  --caret-accent: #1769aa;
}
input,
textarea {
  caret-color: var(--caret-accent);
}

Different Form Themes

.light-form {
  caret-color: #1769aa;
}
.dark-form {
  caret-color: #66ccff;
}

Choose a caret color that complements the design while remaining easy to see during text entry.

caret-color Example

The following example shows three editable controls with different insertion caret colors. Click inside each field to see the caret.

<div class="caret-color-demo">
  <label for="blue-caret">Blue Caret</label>
  <input type="text" id="blue-caret" class="blue-caret" placeholder="Click to type">
  <label for="green-caret">Green Caret</label>
  <input type="text" id="green-caret" class="green-caret" placeholder="Click to type">
  <label for="purple-caret">Purple Caret</label>
  <textarea id="purple-caret" class="purple-caret" rows="3" placeholder="Click to type"></textarea>
</div>
.caret-color-demo label {
  display: block;
  margin-bottom: 6px;
  font-weight: bold;
}
.caret-color-demo input,
.caret-color-demo textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  margin-bottom: 15px;
  padding: 10px;
  border: 1px solid #cccccc;
  border-radius: 4px;
  color: #333333;
  background-color: #ffffff;
}
.caret-color-demo .blue-caret {
  caret-color: #1769aa;
}
.caret-color-demo .green-caret {
  caret-color: #008855;
}
.caret-color-demo .purple-caret {
  caret-color: #9933cc;
}
.caret-color-demo input:focus-visible,
.caret-color-demo textarea:focus-visible {
  outline: 2px solid #1769aa;
  outline-offset: 2px;
}
Browser Result

Each control uses a different caret-color value while retaining the same text color and general form styling.

The insertion caret is visible when the control has focus. Its blinking behavior remains controlled by the browser.

Important Considerations

Keep the following points in mind when using caret-color:

  • Purpose: Controls the color of the text insertion caret.
  • Initial value: auto.
  • Inheritance: The property is inherited.
  • Editable content: The property is visually relevant to elements displaying an insertion caret.
  • Color values: Accepts standard CSS color values.
  • Automatic color: auto allows the browser to select the caret color.
  • Text color: currentColor makes the caret match the element's text color.
  • Transparency: transparent makes the caret invisible.
  • Accessibility: Choose a color that remains visible against the background.
  • Focus: The caret and focus outline serve different purposes.
  • Form controls: Commonly used with text inputs and textareas.
  • Editable elements: Can be used with contenteditable content.
  • Animation: The caret color can be animated using CSS.
  • Browser support: The property is widely supported in modern browsers.
  • Shorthand: Included in the newer caret shorthand.
  • Mouse pointer: Does not change the mouse cursor.
  • Text selection: Does not change the appearance of selected text.
  • Usability: Avoid hiding the insertion caret in ordinary editable controls.

Use caret-color to customize the insertion caret while preserving normal text editing behavior and a clearly visible focus indicator.

Browser Support

The caret-color property is widely supported in modern browsers, including Chrome, Edge, Firefox, and Safari.

It can be used in text inputs, textareas, and editable content without requiring the newer caret shorthand.

Basic Compatibility Example

input,
textarea {
  caret-color: #1769aa;
}

Fallback Behavior

Browsers that do not recognize caret-color ignore the declaration and continue using their default insertion caret color.

Feature Detection

@supports (caret-color: #1769aa) {
  .custom-input {
    caret-color: #1769aa;
  }
}

Feature detection is usually unnecessary for basic caret colors because support is widespread.

For current compatibility details, visit Can I Use? .

Specifications

The caret-color property is defined in CSS Basic User Interface Module Level 4.

CSS Basic User Interface Module Level 4

The specification defines how the insertion caret's color is selected and how custom color values are applied.