You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The **`caret-color`**[CSS](/en-US/docs/Web/CSS) property sets the color of the **insertion caret**, the visible marker where the next character typed will be inserted. This is sometimes referred to as the **text input cursor**. The caret appears in elements such as {{HTMLElement("input")}} or those with the [`contenteditable`](/en-US/docs/Web/HTML/Reference/Global_attributes/contenteditable) attribute. The caret is typically a thin vertical line that flashes to help make it more noticeable. By default, it is black, but its color can be altered with this property.
9
+
The **`caret-color`**[CSS](/en-US/docs/Web/CSS) property sets the color of the **insertion caret**, sometimes referred to as the **text input cursor**. This is the visible marker appearing at the insertion point where the next character typed will be added or where the next character deleted will be removed.
10
10
11
11
{{InteractiveExample("CSS Demo: caret-color")}}
12
12
@@ -37,8 +37,6 @@ caret-color: transparent;
37
37
}
38
38
```
39
39
40
-
Note that the insertion caret is only one type of caret. For example, many browsers have a "navigation caret," which acts similarly to an insertion caret but can be moved around in non-editable text. On the other hand, the mouse cursor image shown when hovering over text where the {{cssxref("cursor")}} property is `auto`, or when hovering over an element where the `cursor` property is `text` or `vertical-text`, though it sometimes looks like a caret, is not a caret (it's a cursor).
41
-
42
40
## Syntax
43
41
44
42
```css
@@ -64,14 +62,37 @@ caret-color: unset;
64
62
### Values
65
63
66
64
- `auto`
67
-
- : The user agent selects an appropriate color for the caret. This is generally {{cssxref("<color>","currentColor","#currentcolor_keyword")}}, but the user agent may choose a different color to ensure good visibility and contrast with the surrounding content, taking into account the value of `currentColor`, the background, shadows, and other factors.
68
-
69
-
> [!NOTE]
70
-
> While user agents may use `currentColor` (which is usually animatable) for the `auto` value, `auto` is not interpolated in transitions and animations.
65
+
- : Generally resolves to [`currentColor`](/en-US/docs/Web/CSS/color_value#currentcolor_keyword), the {{cssxref("color")}} of the text that will be modified.
71
66
72
67
- {{cssxref("<color>")}}
73
68
- : The color of the caret.
74
69
70
+
## Description
71
+
72
+
An insertion caret is a visible indicator of the spot within editable text — or within an element that accepts textinput — where content will be inserted (or deleted) by the user. The caret is typically a thin vertical line indicating where the addition or deletion of characters will occur. It generally blinks (flashes on and off), so it is more noticeable. The caret only appears when the editable element has focus. By default, this caret is the color of the text. The `caret-color` property can be used to set the color of this caret to something other than the `currentColor`, or to reset a colored caret back to its default.
73
+
74
+
The `auto` value sets the insertion caret to `currentColor`, which is the {{cssxref("color")}} of the text that is being added or deleted. User agents may choose a different color to ensure good visibility and contrast with the surrounding content, taking into account the {{cssxref("color")}}, {{cssxref("background-color")}}, shadows, and other factors. In practice, however, all browsers use the current color by default, and when `caret-color` is set to `auto`. You can set any valid `<color>` as the value.
75
+
76
+
### Understanding insertion carets
77
+
78
+
The insertion caret, and therefore this property, only applies to text or elements that can accept textinput. The caret appears in focused user interface elements where users can update content, such as {{HTMLElement("input")}} elements that accept freeform text, the {{HTMLElement("textarea")}} element, and elements with the [`contenteditable`](/en-US/docs/Web/HTML/Reference/Global_attributes/contenteditable) attribute set.
79
+
80
+
The caret may appear in `<input>` elements of type `password`, `text`, `search`, `tel`, and `email`. No caret exists with date, `color`, `hidden`, `radio`, or `checkbox` input types. Some browsers display a caret with the `number` input type. It is possible in some browsers to make a caret appear in elements that never have textcontent — for example, by setting [`appearance: none`](/en-US/docs/Web/CSS/appearance) and adding the `contenteditable` attribute. However, this is not recommended.
81
+
82
+
A caret may be displayed in an editable element or its descendants, provided the editability is not disabled, for example by setting a descendant element's `contentEditable` attribute to `false`. If an element is not editable or selectable, for example if {{cssxref("user-select")}} is set to `none`, the caret should not appear.
83
+
84
+
### Caret versus cursor
85
+
86
+
There are multiple types of carets. The insertion caret is the only type affected by the `caret-color` property.
87
+
88
+
Many browsers have a**navigation caret**, which acts similarly to an insertion caret but can be moved around in non-editabletext.
89
+
90
+
The mouse cursorimage shown for certain {{cssxref("cursor")}} property values (for example, `auto` or `text`) may resemble a caret, but it's not. It'sacursor.
91
+
92
+
### Animating from `auto`
93
+
94
+
Generally, when the `caret-color` is set to or defaults to `auto`, user agents use `currentColor`, which is animatable. However, `auto` is not an animatable value by default: when animating or transitioning the `caret-color` from `auto` to any color value, no interpolation happens. The animation is [discrete](/en-US/docs/Web/CSS/CSS_animated_properties#discrete); the color switches from or to the `currentColor` color at the midpoint of the {{cssxref("animation-duration")}} or {{cssxref("transition-duration")}}.
95
+
75
96
## Formal definition
76
97
77
98
{{cssinfo}}
@@ -104,7 +125,7 @@ input {
104
125
}
105
126
106
127
input.custom {
107
-
caret-color: red;
128
+
caret-color: orange;
108
129
}
109
130
110
131
p.custom {
@@ -126,7 +147,10 @@ p.custom {
126
147
127
148
## See also
128
149
129
-
- The {{HTMLElement("input")}} element
130
-
- The HTML [`contenteditable`](/en-US/docs/Web/HTML/Reference/Global_attributes/contenteditable) attribute, which can be used to make any element's text editable
131
-
- The {{cssxref("<color>")}} data type
132
-
- Other color-related properties: {{cssxref("color")}}, {{cssxref("background-color")}}, {{cssxref("border-color")}}, {{cssxref("outline-color")}}, {{cssxref("text-decoration-color")}}, {{cssxref("text-emphasis-color")}}, {{cssxref("text-shadow")}}, and {{cssxref("column-rule-color")}}
150
+
- {{cssxref("color")}}
151
+
- {{cssxref("text-emphasis")}}
152
+
- {{cssxref("cursor")}}
153
+
- {{cssxref("text-emphasis")}}
154
+
- CSS {{cssxref("<color>")}} data type
155
+
- {{HTMLElement("input")}} element
156
+
- HTML [`contenteditable`](/en-US/docs/Web/HTML/Reference/Global_attributes/contenteditable) attribute
Copy file name to clipboardExpand all lines: files/en-us/web/css/css_basic_user_interface/index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -95,7 +95,7 @@ Click "Play" in the example above to see or edit the code for the animation in t
95
95
- {{CSSxRef("resize")}}
96
96
- {{CSSxRef("user-select")}}
97
97
98
-
The CSS basic user interface module also defines the `caret`, `caret-shape`, `nav-down`, `nav-left`, `nav-right`, and `nav-up` properties. Currently, no browsers support these features.
98
+
The CSS basic user interface module also defines the `caret`, `caret-animation`, `caret-shape`, `nav-down`, `nav-left`, `nav-right`, and `nav-up` properties. Currently, no browsers support these features.
0 commit comments