CSS :disabled Pseudo Class

The :disabled pseudo-class selects and styles elements that are disabled.

These elements are usually form elements, such as buttons (<button>), select menus (<select>), input types (<input>), and textareas (<textarea>).

Disabled elements do not accept clicks, text input, or focus.

Version

CSS3

Syntax

:disabled {
css declarations;
}

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style> 
      input{
      padding:2px 5px;
      margin-bottom:10px;
      border:1px solid #ccc;
      }
      input[type=text]:enabled {
      background: #eee;
      }
      input[type=text]:disabled {
      background: #ccc;
      }
    </style>
  </head>
  <body>
    <h2>:disabled selector example</h2>
    <form action="">
      <label for="name">First name:</label> 
      <input type="text" value="John" id="name"><br>
      <label for="lastname">Last name:</label> 
      <input type="text" value="Smith" id="lastname"><br>
      <label for="country"l>Country:</label> 
      <input type="text" disabled="disabled" value="10 High Street" id="conutry">
    </form>
  </body>
</html>

Another example with the :disabled selector:

Example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style> 
      option:disabled {
      background: #8ebf42;
      }
    </style>
  </head>
  <body>
    <h2>:disabled selector example</h2>
    <select>
      <option value="paris">Paris</option>
      <option value="london" disabled>London</option>
      <option value="moscow">Moscow</option>
      <option value="rome" disabled>Rome</option>
      <option value="berlin">Berlin</option>
    </select>
  </body>
</html>



Related articles