I want to style the caret of a focused <input type='text'/>
. Specifically, the color and thickness.
If caps is ok in your context, one easy hack is to use the css attribute font-variant: small-caps; to get the caret larger than the text.
The caret-shape property in CSS changes the shape of the text cursor inside editable elements that indicates a user is typing. It's part of the CSS Basic User Interfaces Module Level 4, which is currently in Working Draft status. As I write, the caret is the little blinking bar that follows each character I type.
And the default color of this cursor for most of the browsers is black. But now you can change the cursor color to any color that you want. To change the cursor color in CSS we use the caret-color property and this property can be applied to the inputs and text areas both.
If you are using a webkit browser you can change the color of the caret by following the next CSS snippet. I'm not sure if It's possible to change the format with CSS.
input,
textarea {
font-size: 24px;
padding: 10px;
color: red;
text-shadow: 0px 0px 0px #000;
-webkit-text-fill-color: transparent;
}
input::-webkit-input-placeholder,
textarea::-webkit-input-placeholder {
color:
text-shadow: none;
-webkit-text-fill-color: initial;
}
Here is an example: http://jsfiddle.net/8k1k0awb/
'Caret' is the word you are looking for. I do believe though, that it is part of the browsers design, and not within the grasp of css.
However, here is an interesting write up on simulating a caret change using Javascript and CSS http://www.dynamicdrive.com/forums/showthread.php?t=17450 It seems a bit hacky to me, but probably the only way to accomplish the task. The main point of the article is:
We will have a plain textarea somewhere in the screen out of the view of the viewer and when the user clicks on our "fake terminal" we will focus into the textarea and when the user starts typing we will simply append the data typed into the textarea to our "terminal" and that's that.
HERE is a demo in action
There is a new css property caret-color
which applies to the caret of an input
or contenteditable
area. The support is growing but not 100%, and this only affects color, not width or other types of appearance.
input{
caret-color: rgb(0, 200, 0);
}
<input type="text"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With