W3docs

CSS :enabled Pseudo Class

Use the :enabled CSS pseudo-class for selecting and styling the enabled elements. Read about the pseudo-class & practice with examples.

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

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

Enabled elements accept clicks, text input, or focus.

Version

HTML Living Standard

HTML5

Selectors Level 4

Syntax

CSS :enabled syntax example

:enabled {
  css declarations;
}

Example of the :enabled selector:

CSS :enabled code example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      input {
        border: 1px solid #ccc;
        margin-bottom: 10px;
        padding: 2px 5px;
      }
      input[type=text]:enabled {
        background: #eee;
      }
      input[type=text]:disabled {
        background: #ccc;
      }
    </style>
  </head>
  <body>
    <h2>:enabled 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">Country:</label>
      <input type="text" disabled="disabled" value="10 High Street" id="country" />
    </form>
  </body>
</html>

Example of the :enabled selector with the <option> tag:

CSS :enabled another code example

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <style>
      option:enabled {
        background: #666;
      }
    </style>
  </head>
  <body>
    <h2>:enabled 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>

Practice

Practice

What does the ':enabled' pseudo-class in CSS do?