How to add CSS :selected pseudo-class similar to :checked, but for option elements?

Spread the love

Sometimes, we want to add CSS :selected pseudo-class similar to :checked, but for option elements.

In this article, we’ll look at how to add CSS :selected pseudo-class similar to :checked, but for option elements.

How to add CSS :selected pseudo-class similar to :checked, but for option elements?

To add CSS :selected pseudo-class similar to :checked, but for option elements, we use the :checked pseudoclass.

For instance, we write

<select>
  <option>A</option>
  <option>B</option>
  <option>C</option>
</select>

to add a select element.

Then we write

option:checked {
  color: red;
}

to selected the selected option element and make its text red.

Conclusion

To add CSS :selected pseudo-class similar to :checked, but for option elements, we use the :checked pseudoclass.

Leave a Reply

Your email address will not be published. Required fields are marked *