It is bad to put <span /> tags inside <option /> tags, only for string manipulation not styling?

Rubens Mariuzzo picture Rubens Mariuzzo · Apr 15, 2011 · Viewed 64.7k times · Source

I would like to make groups of the text content of an <option /> tag. Say I have the following: <option>8:00 (1 hour)</option>, the time pattern 8:00 can be modified, then the text in parenthesis (1 hour) can also be modified.

I was thinking of doing something like

<option>
  <span>8:00</span>
  <span> (1 hour)</span>
</option>

It is bad to put <span /> tags inside <option /> tags, only for string manipulation not styling?

Answer

Quentin picture Quentin · Apr 15, 2011

From the HTML 4.01 spec:

<!ELEMENT OPTION - O (#PCDATA)         -- selectable choice -->

From the HTML 5 draft spec:

Content model: Text.

(Even the HTML 3.2 and HTML 2 specs say: <!ELEMENT OPTION - O (#PCDATA)*>)

An option element cannot have any child elements. So yes, it is bad.