Search code examples
htmlcsshtml-input

How to disable selection / highlighting of a HTML input element?


How to prevent user-selection / highlighting of an <input>?

This:

input { 
  user-select: none;
}
<input type="number" value="123" />

and the methods from How to disable text selection highlighting and CSS disable text selection and don't work on an input.

Note: if possible, I don't want to put the input on disabled mode.


Solution

  • This seems to work, as a first approximation:

    input { 
        pointer-events: none;
    }
    <input type="number" value="123" />