Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set the background color of <option> in a <select> element?

How do you set the background color of an item in an HTML list?

like image 966
mike Avatar asked Aug 30 '25 15:08

mike


2 Answers

select.list1 option.option2
{
    background-color: #007700;
}
<select class="list1">
  <option value="1">Option 1</option>
  <option value="2" class="option2">Option 2</option>
</select>

I assume you mean the <select> input element?

Support for that is pretty new, but FF 3.6, Chrome and IE 8 render this all right:

<select name="select">
  <option value="1" style="background-color: blue">Test</option>
  <option value="2" style="background-color: green">Test</option>
</select>
like image 38
Pekka Avatar answered Sep 03 '25 02:09

Pekka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!