'Image won't display in select option (HTML)
for some reason my image won't display in my select option.
<select>
<option><img src="img/pic1.png" style="height:16px;width:16px;margin-left:4px">Option 1</option>
<option><img src="img/pic1.png" style="height:16px;width:16px;margin-left:4px">Option 2</option>
<option><img src="img/pic1.png" style="height:16px;width:16px;margin-left:4px">Option 3</option>
</select>
(Code simplified to understand problem, however, there are no special CSS arguments etc. for the options)
I already searched up other forums and questions on Stackoverflow, but why doesn't it work for me? What do I wrong?
Solution 1:[1]
The <option> element, and therefore the select, can only contain text, not images.
Solution 2:[2]
<option>’s specification does not permit the use of non-textual information in its definition. MDN’s page for <option> spells this out pretty clearly:
Permitted content
Text, possibly with escaped characters (like
é).
Suffice to say that <img> elements for not meet this standard.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ian Devlin |
| Solution 2 | esqew |
