Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show just cursor (caret) but hide the letters in input

Tags:

css

Is there a css way to show a cursor in a transparent input? I keep googling and all that pops up is how to hide it!

<input class='transparent' />

.transparent{
 color:transparent;
 background:transparent;
}

To be absolutely clear the only thing I want to show up in the input is the cursor, nothing else - i.e. the text should be hidden but the cursor should still be visible.

like image 445
zazvorniki Avatar asked Jun 16 '16 15:06

zazvorniki


People also ask

How do you hide a caret in input field?

To hide blinking cursor in input text with CSS, we set the caret-color property. to set the caret-color to transparent to make the blinking cursor disappear from the input.

How do I hide the text cursor?

Approach: First, select the element where cursor element need to hide. Add CSS style cursor:none to the a class. Add the class name (class name of CSS style cursor:none) to the particular element where cursor element to be hide.

What is input caret?

A caret (sometimes called a "text cursor") is an indicator displayed on the screen to indicate where text input will be inserted. Most user interfaces represent the caret using a thin vertical line or a character-sized box that flashes, but this can vary. This point in the text is called the insertion point.


2 Answers

You could style the text not touching the caret using the text-fill-color feature of webkit.

 .transparent{
   background:transparent;
   color:black;   /* sets the color of both caret and text */
   -webkit-text-fill-color: transparent; /* sets just the text color */
 }
<input class='transparent' />

The feature isn't supported by all the browsers, but the recent versions of the most widely-used browsers do support it.

like image 199
nicael Avatar answered Dec 18 '22 13:12

nicael


I managed to solve this using the caret-color CSS property in input, text areas and content-editable divs: https://css-tricks.com/almanac/properties/c/caret-color/

input,
textarea,
[contenteditable] {
  caret-color: red;
}

Keep the color property as transparent for the text.

like image 42
P Fuster Avatar answered Dec 18 '22 13:12

P Fuster