28

I want to add some kind of space (padding, margin or whatever) between select options in HTML using CSS. I am currently using Chrome and I've already tried using something like this:

 select option {
     padding: 10px
 }

However it didn’t work. I’ve already read that this is possible to do but it does not work in IE.

Anyway, I’d like to have this to work in other browsers even if it doesn't work in IE.

JSFiddle example

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
Correia JPV
  • 610
  • 3
  • 10
  • 25

4 Answers4

17

Styling to select option is very much limited as to maintain a coherence and consistency among all the application in the operating system thus the browser are ought to restrict the style of some basic elements like in your case option tag.

The restriction depends browser to browser, like padding and even margin of option tag works in the Mozilla Firefox while it doesn't work with Chrome.

If it is very much necessary in you website to style the option tag then I suggest you to use some jQuery plugin (you can also make a drop down of your own, its simple).

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
sumitb.mdi
  • 1,010
  • 14
  • 17
  • 1
    By talking about your own dropdown, It is the reason why we don't flash. There is a word "semantic". – atilkan Mar 08 '15 at 16:08
  • 3
    Remember when you use your own control you won't get browser autofill and other accessibility features - such as for addresses. For example even 6 years on from this question they haven't figured out how to get angular material design controls to work with autofill in chrome :-( – Simon_Weaver May 06 '19 at 19:04
12

The appearance of option tags is determined by the browser in my experience and often for good reason - think about how differently the appearance is on iOS v chrome and the benefits of this.

You can exert some control of the select element however, by using the browser prefixed appearance attribute.

For example:

select {
    padding: 2px 10px;
    border: 1px solid #979997;

    -webkit-appearance: none;
    -moz-appearance: none;
    -ms-appearance: none;
    -o-appearance: none;
    appearance: none;

    -webkit-border-radius: 4px;
    -moz-border-radius: 4px;
    -ms-border-radius: 4px;
    -o-border-radius: 4px;
    border-radius: 4px;
}

However when clicked, they appear as they normally do in whatever browser you're using.

If you want finer control, your best bet I think is @sumitb.mdi's suggestion of a jquery plugin or build something similar yourself from scratch.

Joshua
  • 6,320
  • 6
  • 45
  • 62
0

<select></select> tag:- Changed have select css properties but not changed it's option values property if you want to change it's option property so add jQuery plugin otherwise create own dropdown(custom drop down).

Ashish Bhangade
  • 107
  • 1
  • 2
  • 8
0

I try all solutions but didn't work

The following code works for me.

<select>
<option value="1">Item 1 one</option>
<option value="" style="font-size:5pt;" disabled>&nbsp;</option>

<option value="2">Item 2 tow</option>
<option value="" style="font-size:5pt;" disabled>&nbsp;</option>

<option value="3">Item 3 three</option>
<option value="" style="font-size:5pt;" disabled>&nbsp;</option>

<option value="4">Item 4 four</option>
<option value="" style="font-size:5pt;" disabled>&nbsp;</option>

<option value="5">Item 5 five</option>
<option value="" style="font-size:5pt;" disabled>&nbsp;</option>

</select>
Xab Ion
  • 1,105
  • 1
  • 11
  • 20
  • While this achieves similar to what is asked, this also semantically changes the content of the page which might not be intended. – tuesday Jan 15 '23 at 17:45