CSS caret Property
The caret property is a shorthand for controlling the color, shape, and animation of the text insertion caret in editable content.
The insertion caret is the blinking indicator that shows where typed text will appear in an input, textarea, or editable element. The shorthand combines caret-color, caret-shape, and caret-animation, although support for the newer caret features varies between browsers.
For broad compatibility, use caret-color when you only need to change the caret's color.
caret Syntax
The caret shorthand accepts caret color, shape, and animation values.
selector {
caret: red;
}
The general syntax is:
selector {
caret: <caret-color> || <caret-shape> || <caret-animation>;
}
The double vertical bars indicate that the components may appear in any order, with one or more components supplied.
Caret Color
input {
caret: #1769aa;
}
Caret Shape
input {
caret: block;
}
Caret Animation
input {
caret: manual;
}
Combined Values
input {
caret: #1769aa bar auto;
}
The combined examples use newer syntax that may not be recognized in all browsers.
CSS-Wide Keywords
input {
caret: inherit;
}
input {
caret: initial;
}
input {
caret: unset;
}
input {
caret: revert;
}
input {
caret: revert-layer;
}
CSS-wide keywords must be used by themselves rather than combined with individual caret values.
Property Values
The shorthand combines values from three caret-related properties.
| Component | Values | Description |
|---|---|---|
caret-color |
auto, CSS colors |
Controls the color of the insertion caret. |
caret-shape |
auto, bar, block, underscore |
Controls the visual shape of the insertion caret. |
caret-animation |
auto, manual |
Controls whether the browser provides its usual automatic caret blinking. |
Common Value Examples
| Declaration | Intended Result |
|---|---|
caret: auto; |
Uses automatic caret behavior for the applicable components. |
caret: red; |
Sets the caret color to red. |
caret: currentColor; |
Uses the element's current text color for the caret. |
caret: bar; |
Requests a vertical bar-shaped caret. |
caret: block; |
Requests a block-shaped caret. |
caret: underscore; |
Requests an underscore-shaped caret. |
caret: manual; |
Disables the browser's automatic caret blinking behavior where supported. |
Not all browsers support the complete shorthand or its individual components. Unsupported declarations may be ignored.
CSS-Wide Keywords
| Value | Description |
|---|---|
inherit |
Uses the corresponding computed caret values from the parent. |
initial |
Resets the caret subproperties to their initial values. |
unset |
Applies the inherited or initial behavior of each subproperty. |
revert |
Reverts the subproperties according to cascade origin rules. |
revert-layer |
Reverts the subproperties according to cascade layer rules. |
Property Characteristics
| Characteristic | Value |
|---|---|
| Property type | Shorthand |
| Subproperties | caret-color, caret-shape, caret-animation |
| Initial values | auto for each subproperty |
| Inheritance | Determined by the individual subproperties |
| Applies to | Elements that can display a text insertion caret |
| Animation | Determined by the individual subproperties |
| Primary use | Customizing the text insertion caret |
The shorthand does not control the mouse pointer or the text selection highlight.
How It Works
The insertion caret appears when an editable element receives focus and the user can enter or modify text.
Step 1: Create an Editable Element
<input type="text" placeholder="Enter your name">
Step 2: Set a Caret Color
input {
caret-color: #1769aa;
}
The caret uses the specified color in supporting browsers.
Step 3: Use the Shorthand
input {
caret: #1769aa;
}
Where the shorthand is supported, this sets the color component and resets omitted caret components to their initial values.
Step 4: Request a Caret Shape
input {
caret: #1769aa block;
}
This requests a blue block-shaped caret. The actual result depends on browser support.
Step 5: Control Caret Animation
input {
caret: #1769aa bar manual;
}
This requests a blue bar-shaped caret without the browser's automatic blinking.
The browser may continue using its default caret shape or blinking behavior when the newer features are unsupported.
Caret Color
The caret-color component controls the color of the text insertion caret.
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 {
color: #333333;
caret-color: currentColor;
}
Transparent Caret
input {
caret-color: transparent;
}
A transparent caret becomes invisible, which can make text editing confusing. Avoid hiding the insertion caret in ordinary form controls.
Color Through the Shorthand
input {
caret: #1769aa;
}
Compatibility Fallback
input {
caret-color: #1769aa;
caret: #1769aa;
}
The longhand provides a widely supported color declaration if the browser does not recognize the shorthand.
Caret Shape
The caret-shape component requests a particular appearance for the insertion caret.
Automatic Shape
input {
caret-shape: auto;
}
The browser chooses the caret shape.
Bar Shape
input {
caret-shape: bar;
}
Requests a vertical bar-shaped caret.
Block Shape
input {
caret-shape: block;
}
Requests a block-shaped caret, similar to those used in some terminal editors.
Underscore Shape
input {
caret-shape: underscore;
}
Requests an underscore-shaped caret.
Shape Through the Shorthand
input {
caret: #1769aa block;
}
Browser Limitations
The caret-shape property is not consistently supported across mainstream browsers. Unsupported shape values may have no visible effect.
Use the browser's default caret shape unless a specific appearance is essential and the target browsers support it.
Caret Animation
The caret-animation component controls whether the browser performs its usual automatic caret blinking.
Automatic Animation
input {
caret-animation: auto;
}
The browser controls the caret's normal blinking behavior.
Manual Animation Control
input {
caret-animation: manual;
}
The manual value disables the browser's automatic caret blinking so that the caret's appearance can be controlled through CSS animation where supported.
Animation Through the Shorthand
input {
caret: #1769aa bar manual;
}
Custom Blinking
@keyframes caret-blink {
50% {
caret-color: transparent;
}
}
.custom-input {
caret-color: #1769aa;
caret-animation: manual;
animation: caret-blink 1s step-end infinite;
}
This example demonstrates the intended custom blinking technique in browsers that support manual caret animation control.
Reduced Motion
@media (prefers-reduced-motion: reduce) {
.custom-input {
animation: none;
}
}
Respecting reduced-motion preferences is especially important when introducing custom caret effects.
The caret-animation property is a newer feature. Test its behavior before relying on it in production.
Shorthand Behavior
Like other CSS shorthands, caret can set multiple related properties in one declaration.
Separate Longhand Properties
input {
caret-color: #1769aa;
caret-shape: bar;
caret-animation: auto;
}
Equivalent Shorthand
input {
caret: #1769aa bar auto;
}
Order of Values
The shorthand components may appear in different orders when each value can be identified unambiguously.
input {
caret: block #1769aa manual;
}
Omitted Components
input {
caret: #1769aa;
}
Omitted components are reset to their initial values rather than retaining earlier declarations.
Resetting Earlier Values
input {
caret-shape: block;
caret: red;
}
In a browser that supports the full shorthand, the second declaration sets the color to red and resets the shape to auto.
Longhand Override
input {
caret: #1769aa bar auto;
caret-color: green;
}
The later longhand changes only the color component, provided both declarations are supported.
Use longhand properties when you need to modify one caret characteristic without resetting the others.
Form Controls
The insertion caret is commonly visible in text inputs and textareas.
Text Input
input[type="text"] {
caret-color: #1769aa;
}
Email Input
input[type="email"] {
caret-color: #1769aa;
}
Search Input
input[type="search"] {
caret-color: #1769aa;
}
Textarea
textarea {
caret-color: #1769aa;
}
Combined Form Controls
input,
textarea {
caret-color: #1769aa;
}
Focused Form Controls
input:focus,
textarea:focus {
caret-color: #1769aa;
}
Using the Shorthand
input,
textarea {
caret-color: #1769aa;
caret: #1769aa;
}
The longhand ensures that the caret color can still be customized in browsers without full shorthand support.
The property does not create an insertion caret in controls that do not support text editing, such as buttons or checkboxes.
Editable Content
The caret can also appear in elements made editable with the HTML contenteditable attribute.
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;
}
Caret Shorthand
.editable-box {
caret: #1769aa;
}
Editable Code Area
<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;
}
Focus Styling
.editable-box:focus-visible {
outline: 2px solid #1769aa;
outline-offset: 2px;
}
The focus outline identifies the active editable area, while the caret identifies the text insertion position.
These are separate visual indicators and should not be confused with one another.
Accessibility
The insertion caret is an important visual indicator for people entering or editing text.
Maintain Visible Contrast
input {
color: #222222;
background-color: #ffffff;
caret-color: #1769aa;
}
Choose a caret color that remains distinguishable from the field background.
Avoid Invisible Carets
input {
caret-color: transparent;
}
This declaration hides the insertion caret and can make keyboard editing difficult. Avoid it unless a carefully designed alternative insertion indicator is provided.
Preserve Focus Indicators
input:focus-visible {
outline: 2px solid #1769aa;
outline-offset: 2px;
}
A visible focus indicator helps keyboard users identify which control is active.
Respect Reduced Motion
@media (prefers-reduced-motion: reduce) {
.custom-input {
animation: none;
}
}
Avoid Distracting Animation
Custom caret animation should not make text entry harder to follow or create unnecessary visual distraction.
Use Native Editing Behavior
Whenever possible, preserve the browser's normal text editing, selection, keyboard navigation, and caret behavior.
Customize the caret only when the result improves usability and remains clear across supported browsers.
Practical Uses
Caret styling can help editable controls match a website's visual design.
Branded Text Input
.brand-input {
caret-color: #1769aa;
}
Dark-Themed Editor
.dark-editor {
color: #eeeeee;
background-color: #222222;
caret-color: #66ccff;
}
Search Field
.search-input {
caret-color: #008080;
}
Contact Form
.contact-form input,
.contact-form textarea {
caret-color: #1769aa;
}
Editable Text Area
[contenteditable="true"] {
caret-color: #1769aa;
}
Terminal-Style Caret
.terminal-input {
caret-color: #00cc66;
caret-shape: block;
}
The block shape is an enhancement for browsers that support caret-shape.
Custom Caret Animation
.custom-input {
caret-color: #1769aa;
caret-animation: manual;
}
Manual animation control is an advanced feature and should be tested in the intended browsers.
caret Example
The following example demonstrates caret colors in editable form controls. Click inside each field to see its insertion caret.
The shorthand is included as a progressive enhancement, with caret-color providing a compatible fallback.
<div class="caret-demo">
<label for="blue-caret">Blue Caret</label>
<input type="text" id="blue-caret" class="blue-caret" placeholder="Click to type">
<label for="red-caret">Red Caret</label>
<input type="text" id="red-caret" class="red-caret" placeholder="Click to type">
<label for="green-caret">Green Caret</label>
<textarea id="green-caret" class="green-caret" rows="3" placeholder="Click to type"></textarea>
</div>
.caret-demo label {
display: block;
margin-bottom: 6px;
font-weight: bold;
}
.caret-demo input,
.caret-demo textarea {
display: block;
width: 100%;
box-sizing: border-box;
margin-bottom: 15px;
padding: 10px;
border: 1px solid #cccccc;
border-radius: 4px;
}
.caret-demo .blue-caret {
caret-color: #1769aa;
caret: #1769aa;
}
.caret-demo .red-caret {
caret-color: #cc3333;
caret: #cc3333;
}
.caret-demo .green-caret {
caret-color: #008855;
caret: #008855;
}
.caret-demo input:focus-visible,
.caret-demo textarea:focus-visible {
outline: 2px solid #1769aa;
outline-offset: 2px;
}
Each field requests a different caret color. The color is visible when the field has focus and the insertion caret is displayed.
In browsers that do not support the caret shorthand, the caret-color declarations provide the intended colors.
Important Considerations
Keep the following points in mind when using caret:
- Property type:
caretis a shorthand property. - Subproperties: Combines
caret-color,caret-shape, andcaret-animation. - Initial values: Each subproperty initially uses
auto. - Editable content: The property is relevant to elements that display a text insertion caret.
- Color: The caret color can be customized using supported CSS color values.
- Shape: Bar, block, and underscore shapes are defined, but support varies.
- Animation: Manual caret animation control is a newer feature.
- Shorthand resets: Omitted components are reset to their initial values.
- Value order: Components may be supplied in different orders when unambiguous.
- Browser support: The complete shorthand is less widely supported than
caret-color. - Compatibility: Use
caret-coloras a fallback. - Accessibility: Maintain sufficient contrast between the caret and its background.
- Visibility: Avoid making the caret transparent in ordinary editable controls.
- Focus: The caret and focus outline serve different purposes.
- Reduced motion: Consider user preferences when introducing custom animation.
- Mouse pointer: The property does not control the mouse cursor.
- Selection: The property does not style selected text.
For dependable production styling, start with caret-color and use the shorthand or newer caret features only when their browser support meets your requirements.
Browser Support
The caret shorthand has limited availability compared with the widely supported caret-color property. Support for caret-shape and caret-animation also varies.
Browsers that do not recognize the shorthand may ignore the declaration and continue using their normal insertion caret.
Recommended Fallback
input,
textarea {
caret-color: #1769aa;
caret: #1769aa;
}
The longhand declaration provides a compatible caret color, while the shorthand can be used by browsers that support it.
Feature Detection
@supports (caret: #1769aa) {
.custom-input {
caret: #1769aa;
}
}
The @supports rule checks whether the browser recognizes the declaration. It does not guarantee that every caret shape or animation behavior is implemented.
For current compatibility information, visit Can I Use? and check the individual caret features.
Specifications
The caret shorthand and its related properties are defined in the CSS Basic User Interface Module Level 4 specification.
CSS Basic User Interface Module Level 4
The specification describes caret color, shape, animation behavior, and the shorthand used to combine these properties.
