How to hide the blinking cursor in an input text?
Eliminate the blinking cursor in a text field by setting caret-color: transparent
using CSS for the <input>
. Use ::placeholder
to style the placeholder text separately.
Just apply this class to your <input>
:
Doing so maintains the placeholder visibility while creating an invisible text cursor during user input.
The Step-by-Step Guide
There are multiple ways and combinations to make the cursor blink its last blink. Let's dive deeper into them:
Synchronizing cursor color with your input background
If the completely invisible cursor is too much for you, have the cursor match the background color of your input field:
"Read-Only Field" - Not the best disguise
While setting an input field as readonly
does prevent users from modifying the input value, it fails to get rid of our not-so-little blinking culprit. Here’s a better disguise:
Clickable, yet cursor-less inputs
What if you require your input fields to be interactively non-editable like dropdown menus? Let's introduce a small tweak with JavaScript:
Apply the necessary class to your <input>
, and voila!
Removing focus using jQuery
If you want to remove the cursor after an input field has gained focus, use the trusty old blur() method from jQuery:
Keep the words, lose the cursor
Styling a subtle text shadow helps maintain text visibility even with our cursor MIA. Here's how:
Tweaking your inputs for visual perfection
Tweaking the margin and padding of your input boxes can drastically enhance their appearance while keeping that cursor hidden, like so:
Functional but cursor-less
You can make inputs functional but without a cursor, without using the disabled
attribute:
Styling inside the parent div
A selectable input field paired with a styled parent div can be a great combination to manipulate the cursor's visibility:
Visualization
See your cursor's journey in hiding:
Applying CSS
for hiding the cursor:
Was this article helpful?