How can I remove the caret from a <input type="text">
element only using CSS and not JavaScript?
Asked
Active
Viewed 7.3k times
39

Davide Cannizzo
- 2,826
- 1
- 29
- 31
-
1What are you referring for? Can you attach an image? – Rafa Romero May 07 '14 at 10:51
-
3You mean the insertion point cursor (caret)? Why would you want to remove it? – Lee Taylor May 07 '14 at 10:52
-
If anyone still looking for an answer. caret-color:"transparent",cursor:"default and if you are using react, onKeyDown={(e) => { e.preventDefault(0 }} will disable the edit – anusha chokka Mar 27 '22 at 21:33
2 Answers
43
Of course you can do it just with CSS
.
Add this code to your CSS file:
border: none;
color: transparent;
text-shadow: 0 0 0 gray;
text-align: center;
&:focus {
outline: none;
}

Rafa Romero
- 2,667
- 5
- 25
- 51
-
8
-
2All I had found were awful hacks done with javascript and two input fields. Thanks so much for this solution! So simple :) – forgivenson Jun 03 '16 at 16:46
-
2
-
7
-
-
1it can be done with using caret-color property. https://stackoverflow.com/a/48389261/5749192 – Gabriel Brito Jul 11 '20 at 03:51
8
I can only say you that you can achieve this by applying the color through css :
<input type="text" style="color: transparent;text-shadow: 0 0 0 red;" />
Otherwise there is no way to style the text cursor with CSS.

Rakesh Shetty
- 4,548
- 7
- 40
- 79