Search code examples
csstextbox

Disable a textbox using CSS


How to disable a textbox in CSS? Currently we are having a textbox in our view which can be enabled/disabled depending on a property in the model. We are having asp.net MVC view; depending on the value of the Model property we need to either render a textbox or readonly textbox. we were thinking of doing this by applying CSS to the view control. Has someone done this earlier?


Solution

  • CSS cannot disable the textbox, you can however turn off display or visibility.

    display: none;
    visibility: hidden;
    

    Or you can also set the HTMLattribute:

    disabled="disabled"