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"
On this page

Example

#
CSS
.code-editor {
  caret-color: #facc15;
}
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

#
  • auto

    A caret in the text colour.
  • #f43f5e

    A red caret.
  • #a78bfa

    A purple caret matching the accent.

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.