I have a drop down list. I want to add images along with it. I tried adding img
tag inside tha option
tag... But still the images are not getting displayed.
How do I do it using option
tag?
Asked
Active
Viewed 5.3k times
15

H. Pauwelyn
- 13,575
- 26
- 81
- 144

enthusiastic
- 1,702
- 4
- 19
- 31
1 Answers
22
It's not possible, as <option>
only supports text.
You may have to roll your own drop-down control using complex HTML/CSS/JavaScript. How to do it may or may not be within the scope of your question.
Alternatively, you may use a non-repeating background-image
and apply some padding on the text to achieve a similar effect. But if each <option>
is to have a unique image, your code is going to be polluted with a style
attribute for every single <option>
. If you don't mind that, it's fine. Otherwise, roll your own somehow.

John Pavek
- 2,595
- 3
- 15
- 33

BoltClock
- 700,868
- 160
- 1,392
- 1,356
-
but `background-image` not work in all browsers.. – webdevanuj Jul 21 '16 at 08:02
-
deadlink deadlink – Ash Oct 02 '17 at 13:33
-
@Ash [Here](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/option) is a new link. – John Pavek Feb 21 '18 at 15:55