Controlling the width of SELECT lists
= Index DOT Html by Brian Wilson =

Main Index | Element Index | Element Tree | HTML Support History
The Issue | Possible Solutions | Recommendation

The Issue
The default width of a SELECT form control is usually dependent on the width of the widest OPTION item in the list; the width of the SELECT list will basically be not much greater (but no less) than this width.

The HTML standards don't allow for a way to control this width. CSS, on the other hand, would be perfect for controlling this, but historical support for CSS on form controls is rather weak.

Solution 1: Using   to pad OPTION element content
Support Key: [IE1|M2A1|N1|O2.1|S1]
This solution can work rather well - non-breaking spaces are treated as displayable content, so these can be used to add crude right and left "padding" widths to the SELECT control. The one downside of this method is that it is difficult to achieve a precise width for the control.

Solution 2: Using a WIDTH attribute on the SELECT control
Support Key: [IE|M|N4-4.x|O|S]
This proprietary attribute was added in Netscape 4.x, and has been retired in Netscape 6.x, but this attribute takes as a value a positive integer representing a pixel width for the control. The disadvantage here is that only Netscape 4.x supports it.

Solution 3: CSS on the SELECT control
Support Key: [IE4|M|N6B1|O5|S1]
This is by far the best solution, using the 'width' CSS property - and it has the widest support.


Since Netscape 4 has only the proprietary attribute that will give the desired effect, it will not hurt anything to combine the use of CSS and the WIDTH attribute.

<select name="foo" width="300" style="width: 300px">
    <option>one </option>
    <option>two </option>
    <option>three </option>

Boring Copyright Stuff...