Styling with the :default selector

Github Page


Definitions

The :default pseudo-class applies to the one or more UI elements that are the default among a set of similar elements. The :default pseudo-class must match any element in one of the following categories:

Sources:


Example 1 - button type="submit"

The first <button type="submit"> is the default element, and should have red text.

Example

CSS code
.example1 button:default {
  color: red;
}

Example 2 - input type="submit"

The first <input type="submit"> is the default element, and should have red text.

Example

CSS code
.example2 input:default {
  color: red;
}

Example 3 - input type="image"

The first <input type="image"> is the default element, and should have a red border.

Example

CSS code
.example3 input:default {
  border: 2px solid red;
}

Example 4 - radio - checked - default element should be red text

The first <input type="radio"> element that has a checked attribute is the default element, and should be colored red.

Example



CSS code
.example4 input:default + label {
  color: red;
}

Example 5 - checkbox - checked - default element should be red text

The first <input type="checkbox"> element that has a checked attribute is the default element, and should be colored red.

Example



CSS code
.example5 input:default + label {
  color: red;
}

Example 6 - option - selected - default element should be red text

The first <option> element that has a selected attribute is the default element, and should be colored red.

Currently not supported in most modern browsers.

Example

CSS code
.example6 option:default {
  color: red;
}

Github Page