CSS caret-color property specifies the color of the cursor, which is the visible marker, also known as the text input cursor. It is used with input elements such as input forms, text boxes, textarea etc. which use the cursor and are editable.
Syntax
caret-color: auto | color | transparent | initial | inherit;
Property Values
Value | Description |
---|---|
auto | The browser uses the currentColor for the caret. Default. |
color | The color of the caret can be specified in different formats (color names, hex, rgb etc.). |
transparent | The caret is not visible. |
initial | It sets the property to its default value. |
inherit | It inherits the property from the parent element. |
Examples of CSS Caret Color Property
The following examples explain the caret-color property with different values.
Caret Color Property with Auto Value
To let the browser decide the color of the cursor, which uses the current text color, we use the auto value. The current text color will be applied to the cursor. This is shown in the following example.
Example
<!DOCTYPE html><html><head><style>div { display: grid; gap: 20px; width: 60%; }
.inp { border: 2px solid black; font-size: 16px; padding: 5px; caret-color: auto; }
.text { color: blue; }
</style></head><body><h2>.textarea { color: red; }
</h2><div><label>CSS caret-color property
caret-color: auto (color of the text will be applied to caret) </label><input type="text" value="Default cursor color." class=" inp text" /><textarea rows="10" class=" inp textarea">Default caret color. </textarea></div></body></html></pre>
Caret Color Property with Color Values
To give a color of our choice to the cursor, we can specify the color in different format (color names, hex values, rgb values, hsl values etc.). The specified color will be applied to the cursor. This is shown in the following example.
Example
<!DOCTYPE html><html><head><style>div { display: grid; gap: 20px; width: 60%; }
.inp { border: 2px solid black; font-size: 20px; padding: 5px; }
.text1 { caret-color: orange; }
.text2 { caret-color: #ff4d94; }
.text3 { caret-color: rgb(0, 204, 204); }
</style></head><body><h2>.textarea { caret-color: hsl(120, 100%, 50%); }
</h2><div><label>CSS caret-color property
caret-color: color values (specified color will be applied to caret.) </label><input type="text" value="Green caret color." class=" inp text1" /><input type="text" value="Pink cursor color." class=" inp text2" /><input type="text" value="Blue cursor color." class=" inp text3" /><textarea rows="10" class=" inp textarea">green cursor color. </textarea></div></body></html></pre>
Caret Color Property with Transparent Value
To make the cursor transparent such that it is not visible, we use the transparent value. This is shown in the following example.
Example
<!DOCTYPE html><html><head><style>div { display: grid; gap: 20px; width: 60%; }
</style></head><body><h2>.inp { border: 2px solid black; font-size: 16px; padding: 5px; caret-color: transparent; }
</h2><div><label>CSS caret-color property
caret-color: transparent (cursor color will not be visible) </label><input type="text" value="transparent caret." class="inp" /><textarea rows="10" class=" inp">transparent caret. </textarea></div></body></html></pre>
Leave a Reply