Caret-color - CSS Property

caret-color

Summary of characteristics of the caret-color property

Quick description
Chooses the color of the text marker (flashing cursor).
Status
Standard
Predefined values
auto | currentcolor | transparent
Percentages
Not applicable.
Initial value
auto
Inherited by default
Yes.
Computed value: during an animation, the caret-color property gradually changes from one value to another.
Single: single value (no order).
W3C Module
CSS Basic User Interface Module
 🡇  
 🡅  
Document status: WD (Working Draft)

Document status: REC (Recommendation)

Syntax diagram of caret-color.

caret-color - Syntax DiagramSyntax diagram of the caret-color CSS property. Defines the color of the text marker. auto auto currentcolor currentcolor transparent transparent color-name color-name #xxxxxx #xxxxxx color colorcaret-color:;caret-color:;
Syntax diagram of the caret-color property.
The links in the diagram provide more details about the values.
Download the diagram in SVG.

In the diagram, the bold terms are the predefined words of CSS, the other terms are described below:

Description of the caret-color property.

Sets the color of the insertion caret. This is the blinking cursor that appears when you click in a text field. The cursor that follows the mouse is not affected by this property.

Mouse pointer.
Insertion caret and mouse pointer
Insertion caret (blinking).

The color of the insertion caret is of course more visible when it is block-shaped, rather than just a simple blinking vertical line. To change the shape of the caret, see the caret-shape property.

The insert caret doesn't show up when text is selected, and the selection color isn't the same as the caret.

Also see the following properties regarding the setup of the insert caret and the mouse pointer (cursor):

This property determines whether the default blinking of the text cursor should be maintained.
Sets the shape of the text caret.
Short-hand property grouping all properties related to the text marker.
Sets the shape of the mouse cursor.

Values for caret-color.

    In all the examples that follow, the shape of the insertion caret has also been changed with caret-shape, to better show the color. But not all browsers recognize the caret-shape property yet. On Firefox  , for example, the color change might be hard to notice.

  • caret-color: auto;

    Default value. The browser determines the insertion caret color. Most of the time this value is equivalent to currentColor, unless the cursor shape is block, in which case the insertion caret takes an intermediate color.

  • caret-color: currentColor;

    The insertion caret is shown in the same color as the text.

  • caret-color: transparent;

    The insertion caret is invisible.

  • caret-color: #00AA00;

    The color of the insertion caret is set by its hexadecimal code, in 3, 6, or 8 digits. Check the page on Colors for more details.

  • caret-color: lavender;

    The color of the insertion caret is defined by its name. See Color chart.

  • caret-color: hsl(h, s, l);

    The color of the insertion caret is set by one of the many functions reserved for this purpose: hsl(), rgb(), etc. Check out the page on Colors for the full list of these functions.

  • caret-color: initial; (auto) caret-color: inherit; caret-color: revert; caret-color: revert-layer; caret-color: revert-rule; caret-color: unset;

    Common values ​​are presented on these pages: initial, inherit, revert, revert-layer, revert-rule, unset.

Animation of the caret-color property.

Like all properties that take a color as a value, caret-color can be animated gradually, from one color to another. Be sure to click in the input area below to make the insertion caret appear. The fact that it blinks makes it hard to notice the animation, but it’s definitely there.

Access the caret-color property via a program

Change the insertion caret color in Javascript.

Two code examples for changing the value of caret-color are given below. The first uses kebab-case notation for the property name (a dash to separate the words), and the second is written in camel-case style (a capital letter to separate the words).

Javascript
let el = document.getElementById('id'); el.style['caret-color'] = 'red'; // or let el = document.getElementById('id'); el.style.caretColor = 'red';

Read the insertion caret color in JavaScript.

The code given below is the mirror of the previous one: it retrieves the value of caret-color when it has been initialized via the style attribute of the element. Values assigned through a CSS selector are not taken into account by this code. For that, refer to the following example.

Javascript
let el = document.getElementById('id'); let value = el.style['caret-color']; // or let el = document.getElementById('id'); let value = el.style.caretColor;

Read the computed value of caret-color in Javascript.

The computed value is the one that comes from resolving conflicts between the value(s) assigned to the element via CSS selectors and any inherited values. If there aren't any, the computed value is the property's initial value. Most of the time, there’s no conflict, and the computed value is just the value assigned to the property for the element.

In the case of caret-color, the color is returned in the form rgb(r,g,b), or, if the color's opacity is not total, in the form rgba(r,g,b,a).

Javascript
let el = document.getElementById('id'); let value = window.getComputedStyle(el).getPropertyValue('caret-color');

Read or change the value of the caret-color property with JQuery.

Some code examples are given below. JQuery syntax is generally shorter than Javascript syntax.

JQuery

// Read the value:
$('#id').prop('caret-color');
// Write the value:
$('#id').prop('caret-color', 'red');
$('#id').prop('{caret-color': 'red'});

Read the computed value of the property caret-color with JQuery.

JQuery
let value = $('#id').css('caret-color');

Other code examples.

Other examples of Javascript and JQuery code are given on the page Javascript and CSS.

Test it yourself.

The buttons below apply the entered value to the caret-color property and then display either the value as it was applied or the computed value. This second option lets you see how the value of caret-color is stored (serialized). You'll notice that colors are always returned in rgb(), rgba(), ou color() format, no matter how they were assigned.

Simulator.

The insertion caret is a very thin, blinking line. Some colors make it hard to see.

caret-color :
Test :

Browsers compatibility with caret-color.

The property caret-color is quite old. All browsers recognize it and handle it correctly, except Internet Explorer  , but that browser is no longer used.

Column 1
Support by browsers for the caret-color property to define the color of the text cursor that appears in editable areas.
Column 2
Browser support for the caret-shape property, which defines the shape of the text cursor (the blinking cursor that shows where the typed character will appear).
1
caret-color
property
2
caret-shape
property
Estimated overall support.
95%
66%

Browsers on computers :

Mobile browsers :

Outdated or marginal browsers :

Internet Explorer

UC Browser pour Androïd

Opéra Mobile

QQ Browser

Baidu Browser

Opéra

Chrome

Safari

Firefox

Safari sur IOS

Edge

Chrome pour Androïd

Samsung Internet

Androïd Brower

Firefox pour Androïd

KaiOS Browser

Opéra mini

Historic of the caret-color property.

  • CSS Basic User Interface Module Level 3

    This specification module groups the properties that interact with the user interface (UI): cursor, caret-color, etc. It also defines the outline properties outline....

    Regarding caret-color The ability to choose the color of the text cursor is added, with the caret-color property.
    WD
    August 02, 2002
    Working Draft.
    CR
    July 07, 2015
    Candidate Recommendation.
    PR
    December 14, 2017
    Proposed for recommendation.
    REC
    June 21, 2018
    Recommendation .
  • CSS Basic User Interface Module Level 4

    This level 4 of the specification builds on the definitions already established in level 3. It also includes some additions: text marker management is more detailed, several properties concern the mouse pointer, etc.

    Regarding caret-color No modification to the caret-color property.
    The shorthand property caret is added.
    WD
    September 22, 2015
    Working Draft.
    CR
    PR
    REC

See also, regarding the user interface.

The possibilities for customizing or styling the user interface (UI) are described in the specification CSS Basic User Interface Module of the W3C.

Properties:

accent-color
Defines the colour of active or checked items.
appearance
Langue française
Remove the formatting applied by the operating system. Only applies to form controls.
caret
Short-hand property grouping all properties related to the text marker.
caret-animation
This property determines whether the default blinking of the text cursor should be maintained.
Caret-color
Chooses the color of the text marker (flashing cursor).
caret-shape
Sets the shape of the text caret.
cursor
Sets the shape of the mouse cursor.
ime-mode
Langue française
Defines the accessibility of an input box.
interactivity
Langue française
Allows rendering an element and its descendants inert.
interest-delay
Langue française
Shorthand property equivalent to interest-delay-start and interest-delay-end.
interest-delay-end
Langue française
Defines the time between the moment when the mouse leaves the element and the moment when the tooltip disappears.
interest-delay-start
Langue française
Defines the time between when the mouse arrives on the element and when the tooltip appears.
outline
Langue française
Summary of contour characteristics.
outline-color
Langue française
Sets the color of the outline.
outline-offset
Langue française
Sets the spacing between the outline and the element.
outline-style
Langue française
Defines the type of stroke of the contours (single, double, dashed...).
outline-width
Langue française
Sets the weight of the strokes for the outline.
resize
Langue française
Allows or prevents the element from being sized by the user.
user-select
Langue française
Defines whether the content of an element is user-selectable or not.