Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to control cursor/caret size with CSS

Tags:

html

css

I'm trying to control the caret size in a html textarea. The size seems to default to the line height, is there a way to manually control it?

like image 650
cmwright Avatar asked May 22 '11 21:05

cmwright


People also ask

How do you change caret size in CSS?

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.

How do you style a caret in CSS?

The caret-color 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 <input> or those with the contenteditable attribute.

How do I increase cursor size in CSS?

You can't increase the size of the default cursor using CSS or jQuery. But you can replace the cursor with the custom image of any size using pure CSS by cursor : Url() property.


2 Answers

There isn't any way to change how the caret looks in a textarea. If you want to do that, you'll have to use something other than a textarea, such as a div or a canvas element and control everything with JavaScript.

like image 199
rid Avatar answered Sep 19 '22 00:09

rid


Worth noting that some fonts the default size and position of the cursor just looks weird. If this is a high priority for you, it might be worth at least considering switching to a different font. Here is an example of one Google font that looks super weird and two that don't:

example of Cutive Google Font with odd caret positioning

example of Abel Google Font caret

example of Roboto Condensed Google Font caret

You might also have luck generating your webfont files with different settings. The font squirrel webfont generator in Expert Mode has settings for vertical metrics and x-height matching that may help with this issue. Most paid webfonts from different foundries also have similar export settings now. Definitely a time consuming task to tweak settings, export repeatedly, install the new files and check your work, but can often be worth it.

like image 22
squarecandy Avatar answered Sep 19 '22 00:09

squarecandy