
- HTML Tutorial
- HTML - Home
- HTML - Overview
- HTML - Basic Tags
- HTML - Elements
- HTML - Attributes
- HTML - Formatting
- HTML - Phrase Tags
- HTML - Meta Tags
- HTML - Comments
- HTML - Images
- HTML - Tables
- HTML - Lists
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML - Frames
- HTML - Iframes
- HTML - Blocks
- HTML - Backgrounds
- HTML - Colors
- HTML - Fonts
- HTML - Forms
- HTML - Embed Multimedia
- HTML - Marquees
- HTML - Header
- HTML - Style Sheet
- HTML - Javascript
- HTML - Layouts
- HTML References
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Entities
- HTML - Fonts Ref
- HTML - Events Ref
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
How to add images in select list in HTML?
To add images in the select list, set the img text for the image in the <a> tag, which is enclosed in a div −
<div class="dropText"> <a href="#"> <img src="https://www.tutorialspoint.com/cg/images/cg_python.png" width="20" height="20"> Python </a> <! --- All other select items comes here !--> </div>
In the above div dropText, all the other select items is placed with the individual images. The dropText div is styled as. This also sets the background color of the select items i.e. skyblue −
.dropText { display: none; position: absolute; background-color: skyblue; min-width: 120px; z-index: 1; }
The below styles the text of the select list items −
.dropText a { color: black; padding: 12px 25px; text-decoration: none; display: block; }
On hover any select item, which color should be visible is shown using the below style. We have set the blue color −
.dropText a:hover { background-color: blue; color: white; }
The below sets the hover color of the select i.e. dropbtn with the yellow color −
.dropdown:hover .dropbtn { background-color: yellow; }
However, here’s the select button HTML −
<button class="dropbtn"> Select any one language </button>
On load, the select button is styled orange color. The cursor is also set to pointer −
.dropbtn { background-color: orange; padding: 10px; font-size: 20px; cursor: pointer; }
Example
Let us now see the complete example to add images in select list −
<!DOCTYPE html> <html> <head> <title>Select a Language</title> <style> .dropbtn { background-color: orange; padding: 10px; font-size: 20px; cursor: pointer; } .dropdown { position: relative; display: inline-block; } .dropText { display: none; position: absolute; background-color: skyblue; min-width: 120px; z-index: 1; } .dropText a { color: black; padding: 12px 25px; text-decoration: none; display: block; } .dropText a:hover { background-color: blue; color: white; } .dropdown:hover .dropText { display: block; } .dropdown:hover .dropbtn { background-color: yellow; } </style> </head> <body> <h1>Programming Language</h1> <div class="dropdown"> <button class="dropbtn"> Select any one language </button> <div class="dropText"> <a href="#"> <img src="https://www.tutorialspoint.com/cg/images/cg_python.png" width="20" height="20"> Python</a> <a href="#"><img src="https://www.tutorialspoint.com/cg/images/cg_java.png" width="20" height="20">Java</a> <a href="#"><img src="https://www.tutorialspoint.com/cg/images/cg_c++.png" width="20" height="20">C+</a> <a href="#"> </div> </div> </body> </html>
Output

Now, keep the mouse cursor on the dropdown and select a value −

- Related Articles
- How to add a list item in HTML?
- How to add an unordered list in HTML?
- How to list images in Docker?
- How to display Base64 images in HTML?
- How to embed base64 images in HTML?
- HTML DOM Select add() Method
- How do we add a menu list in HTML?
- Add HTML Content to Bootstrap List Group
- How to use select list in selenium?
- How to add visual effects to images with CSS?
- How to show images with a click in JavaScript using HTML?
- How to add background music in HTML?
- How to add a layer in HTML?
- How to add a paragraph in HTML?
- How to add preformatted text in HTML?
