15

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?

H. Pauwelyn
  • 13,575
  • 26
  • 81
  • 144
enthusiastic
  • 1,702
  • 4
  • 19
  • 31

1 Answers1

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