
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - <select> Tag
Introduction to <select> Tag
The HTML <select> tag is used to create dropdown lists in online forms, allowing users to choose one or more options from a list. The <select> tag, contains <option> tags.
For identification and form submission, attributes like name and id are required. JavaScript enhances functionality while CSS applies styling. Testing on different devices ensures a consistent user experience.
Syntax
Following is the syntax of <select> tag −
<select> .... </select>
Attributes
The HTML select tag supports Global and Event attributes of HTML along with some specific attributes listed bellow.
Attribute | Value | Description |
---|---|---|
disabled | disabled | Disables the input control. The button will not accept user changes, cannot receive focus, and will be skipped when tabbing. |
autofocus | autofocus | Specifies that the drop-down list should automatically receive focus when the page loads. |
form | form_id | Specifies one or more forms. |
multiple | multiple | When set, it allows multiple items to be selected simultaneously. |
name | name | Assigns a name to the input control. |
required | required | Before submitting the form, the user must select a value; otherwise, it will not be proceed. |
size | number | Specifies the number of visible items in the drop-down list. |
Example: Creating Dropdown
In the following program, we use the HTML <select> tag to create a dropdown list. The HTML code includes options for HTML, CSS, and JavaScript, along with a submit button.
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> </head> <body> <!--create a select tag--> <p>Simple select element</p> <select> <option value="">--Chose your option--</option> <option value="">HTML</option> <option value="">CSS</option> <option value="">JavaScript</option> </select> <button>Submit</button> </body> </html>
Example: Form Selection
Here is another example of the HTML <select> tag. We create a "select" element using the select tag that defines the list options within the "form" element. The HTML code includes a form with text, email, and number inputs, a language dropdown, and a submit button.
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> </head> <body> <!--create a form--> <h3>HTML "select" element example</h3> <form> Name: <input type="text"> <br> Email: <input type="email"> <br> Mobile: <input type="number"> <br> Language: <select> <option value="">--Choose language--</option> <option value="">Hindi</option> <option value="">English</option> </select> <button>Submit</button> </form> </body> </html>
Example: Disable Select Element
In this program, we use the HTML <select> tag to define a list of options. The "disabled" attribute is used to disable the "select" element. The HTML code creates a disabled dropdown list with options for India, United States, Australia, and Germany.
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> </head> <body> <!--create a select tag--> <p>HTML 'select' element with 'disabled' attribute</p> <label for="">Choose your country:-</label> <select disabled> <option value="">India</option> <option value="">United state</option> <option value="">Australia</option> <option value="">Germany</option> </select> </body> </html>
Example: Styling Select Elements
In this example, we use the HTML <select> tag to define a list of options. CSS is applied to style the select element. The HTML code creates a styled dropdown list with options for HTML, JavaScript, Java, Python, and C++, labeled as follows.
<!DOCTYPE html> <html lang="en"> <head> <title>Document</title> <style> select { width: 200px; height: 30px; border: 2px solid blue; border-radius: 10px; padding: 5px; } select option { color: green; } </style> </head> <body> <!--create a select tag--> <p>HTML 'select' element with CSS</p> <label for="">Choose your favorite computer language:-</label> <select> <option value="">HTML</option> <option value="">JavaScript</option> <option value="">Java</option> <option value="">Python</option> <option value="">C++</option> </select> </body> </html>
Supported Browsers
Tag | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
select | Yes | Yes | Yes | Yes | Yes |