1

I have created a sample dropdown list (the code is below). I want to change the font color of the "Pick a Country" which is displaying in the select option: The default text color is black and I want to change it to red.

<select id="select-id">
<option value="" selected="">Pick a Country</option>
<option value="">India</option>
<option value="">Sri Lanka</option>
<option value="">Sweden</option>

LPK
  • 526
  • 2
  • 21

3 Answers3

4

I believe below solution gets what you want. Just few lines of CSS (explanation below snippet)

Warning

Styling <select> and <option> elements is not supported across all browsers, because they are rendered by OS, not browser. There are external libraries that create select-like elements composed from HTML elements that can be styled. Below solution is not 100% safe.

Snippet

#select-id {
  color: red;
}

#select-id option:not(:checked) {
  color: initial;
}
<select id="select-id">
  <option value="" selected="">Pick a Country</option>
  <option value="">India</option>
  <option value="">Sri Lanka</option>
  <option value="">Sweden</option>
</select>

Explanation

#select-id {
  color: red;
}

Makes select and all options have color: red.

#select-id option:not(:checked) {
  color: initial;
}

Makes not-selected options have initial color, which is black.

Community
  • 1
  • 1
Andrzej Ziółek
  • 2,241
  • 1
  • 13
  • 21
0

You can either style the first option or you can apply a class to it.

With first selector:

#select-id option:first-child {
  color: red;
}

With class selector:

 #select-id .placeholder {
   color: red;
 }
Furkan Poyraz
  • 672
  • 1
  • 4
  • 14
0

You can try this:

select option:first-child{
    color: red;
}
Pang
  • 9,564
  • 146
  • 81
  • 122