<select>: The HTML Select element - HTML: HyperText Markup Language | MDN (2025)

The <select> HTML element represents a control that provides a menu of options.

Try it

The above example shows typical <select> usage. It is given an id attribute to enable it to be associated with a <label> for accessibility purposes, as well as a name attribute to represent the name of the associated data point submitted to the server. Each menu option is defined by an <option> element nested inside the <select>.

Each <option> element should have a value attribute containing the data value to submit to the server when that option is selected. If no value attribute is included, the value defaults to the text contained inside the element. You can include a selected attribute on an <option> element to make it selected by default when the page first loads.

A <select> element is represented in JavaScript by an HTMLSelectElement object, and this object has a value property which contains the value of the selected <option>.

The <select> element has some unique attributes you can use to control it, such as multiple to specify whether multiple options can be selected, and size to specify how many options should be shown at once. It also accepts most of the general form input attributes such as required, disabled, autofocus, etc.

You can further nest <option> elements inside <optgroup> elements to create separate groups of options inside the dropdown. You can also include <hr> elements to create separators that add visual breaks between options.

For further examples, see The native form widgets: Drop-down content.

Attributes

This element includes the global attributes.

autocomplete

A string providing a hint for a user agent's autocomplete feature. See The HTML autocomplete attribute for a complete list of values and details on how to use autocomplete.

autofocus

This Boolean attribute lets you specify that a form control should have input focus when the page loads. Only one form element in a document can have the autofocus attribute.

disabled

This Boolean attribute indicates that the user cannot interact with the control. If this attribute is not specified, the control inherits its setting from the containing element, for example <fieldset>; if there is no containing element with the disabled attribute set, then the control is enabled.

form

The <form> element to associate the <select> with (its form owner). The value of this attribute must be the id of a <form> in the same document. (If this attribute is not set, the <select> is associated with its ancestor <form> element, if any.)

This attribute lets you associate <select> elements to <form>s anywhere in the document, not just inside a <form>. It can also override an ancestor <form> element.

multiple

This Boolean attribute indicates that multiple options can be selected in the list. If it is not specified, then only one option can be selected at a time. When multiple is specified, most browsers will show a scrolling list box instead of a single line dropdown.

name

This attribute is used to specify the name of the control.

required

A Boolean attribute indicating that an option with a non-empty string value must be selected.

size

If the control is presented as a scrolling list box (e.g. when multiple is specified), this attribute represents the number of rows in the list that should be visible at one time. Browsers are not required to present a select element as a scrolled list box. The default value is 0.

Note: According to the HTML specification, the default value for size should be 1; however, in practice, this has been found to break some websites, and no other browser currently does that, so Mozilla has opted to continue to return 0 for the time being with Firefox.

Usage notes

Selecting multiple options

On a desktop computer, there are a number of ways to select multiple options in a <select> element with a multiple attribute:

Mouse users can hold the Ctrl, Command, or Shift keys (depending on what makes sense for your operating system) and then click multiple options to select/deselect them.

Warning: The mechanism for selecting multiple non-contiguous items via the keyboard described below currently only seems to work in Firefox.

On macOS, the Ctrl + Up and Ctrl + Down shortcuts conflict with the OS default shortcuts for Mission Control and Application windows, so you'll have to turn these off before it will work.

Keyboard users can select multiple contiguous items by:

  • Focusing on the <select> element (e.g. using Tab ).
  • Selecting an item at the top or bottom of the range they want to select using the Up and Down cursor keys to go up and down the options.
  • Holding down the Shift key and then using the Up and Down cursor keys to increase or decrease the range of items selected.

Keyboard users can select multiple non-contiguous items by:

  • Focusing on the <select> element (e.g. using Tab ).
  • Holding down the Ctrl key then using the Up and Down cursor keys to change the "focused" select option, i.e. the one that will be selected if you choose to do so. The "focused" select option is highlighted with a dotted outline, in the same way as a keyboard-focused link.
  • Pressing Space to select/deselect "focused" select options.

Styling with CSS

The <select> element is notoriously difficult to style productively with CSS. You can affect certain aspects like any element — for example, manipulating the box model, the displayed font, etc., and you can use the appearance property to remove the default system appearance.

However, these properties don't produce a consistent result across browsers, and it is hard to do things like line different types of form element up with one another in a column. The <select> element's internal structure is complex, and hard to control. If you want to get full control, you should consider using a library with good facilities for styling form widgets, or try rolling your own dropdown menu using non-semantic elements, JavaScript, and WAI-ARIA to provide semantics.

For more useful information on styling <select>, see:

  • Styling HTML forms
  • Advanced styling for HTML forms
  • The field-sizing property, which controls how <select> elements are sized in relation to their contained options.

Accessibility

The <hr> within a <select> should be considered purely decorative, as they are currently not exposed within the accessibility tree and therefore not exposed to assistive technologies.

Examples

Basic select

The following example creates a very simple dropdown menu, the second option of which is selected by default.

html

<!-- The second value will be selected initially --><select name="choice"> <option value="first">First Value</option> <option value="second" selected>Second Value</option> <option value="third">Third Value</option></select>

Result

Select with grouping options

The following example creates a dropdown menu with grouping using <optgroup> and <hr> to make it easier for the user to understand the content in the dropdown.

html

<label for="hr-select">Your favorite food</label> <br /><select name="foods" id="hr-select"> <option value="">Choose a food</option> <hr /> <optgroup label="Fruit"> <option value="apple">Apples</option> <option value="banana">Bananas</option> <option value="cherry">Cherries</option> <option value="damson">Damsons</option> </optgroup> <hr /> <optgroup label="Vegetables"> <option value="artichoke">Artichokes</option> <option value="broccoli">Broccoli</option> <option value="cabbage">Cabbages</option> </optgroup> <hr /> <optgroup label="Meat"> <option value="beef">Beef</option> <option value="chicken">Chicken</option> <option value="pork">Pork</option> </optgroup> <hr /> <optgroup label="Fish"> <option value="cod">Cod</option> <option value="haddock">Haddock</option> <option value="salmon">Salmon</option> <option value="turbot">Turbot</option> </optgroup></select>

Result

Advanced select with multiple features

The follow example is more complex, showing off more features you can use on a <select> element:

html

<label> Please choose one or more pets: <select name="pets" multiple size="4"> <optgroup label="4-legged pets"> <option value="dog">Dog</option> <option value="cat">Cat</option> <option value="hamster" disabled>Hamster</option> </optgroup> <optgroup label="Flying pets"> <option value="parrot">Parrot</option> <option value="macaw">Macaw</option> <option value="albatross">Albatross</option> </optgroup> </select></label>

Result

You'll see that:

  • Multiple options are selectable because we've included the multiple attribute.
  • The size attribute causes only 4 lines to display at a time; you can scroll to view all the options.
  • We've included <optgroup> elements to divide the options up into different groups. This is a purely visual grouping, its visualization generally consists of the group name being bolded, and the options being indented.
  • The "Hamster" option includes a disabled attribute and therefore can't be selected at all.

Technical summary

Content categories Flow content, phrasing content, interactive content, listed, labelable, resettable, and submittable form-associated element
Permitted content Zero or more <option>, <optgroup> or <hr> elements.
Tag omission None, both the starting and ending tag are mandatory.
Permitted parents Any element that accepts phrasing content.
Implicit ARIA role combobox with no multiple attribute and no size attribute greater than 1, otherwise listbox
Permitted ARIA roles menu with no multiple attribute and no size attribute greater than 1, otherwise no role permitted
DOM interface HTMLSelectElement

Specifications

Specification
HTML Standard
# the-select-element

Browser compatibility

BCD tables only load in the browser

See also

  • Events fired by <select>: change, input
  • The <option> element
  • The <optgroup> element
<select>: The HTML Select element - HTML: HyperText Markup Language | MDN (2025)

FAQs

How do I select an HTML element? ›

The id selector uses the id attribute of an HTML element to select a specific element. The id of an element is unique within a page, so the id selector is used to select one unique element! To select an element with a specific id, write a hash (#) character, followed by the id of the element.

What is the HTML HyperText Markup Language? ›

Hypertext Markup Language (HTML) is the standard markup language for documents designed to be displayed in a web browser. It defines the content and structure of web content. It is often assisted by technologies such as Cascading Style Sheets (CSS) and scripting languages such as JavaScript.

How to get selected HTML element in JavaScript? ›

6 Ways to select HTML Elements with Javascript
  1. Overview.
  2. getElementById.
  3. getElementsByClassName.
  4. getElementsByName.
  5. getElementsByTagName.
  6. querySelector.
  7. querySelectorAll.
  8. The Root of Our Search.
Jan 13, 2020

What does HTML stand for HyperText Markup Language quizlet? ›

HTML stands for HyperText Markup Language and is used to create the structure and content of a webpage. HyperText is text displayed on a computer or device that provides access to other text through links, also known as "hyperlinks." the second HTML tag used to end an HTML element.

How do you select select in HTML? ›

The <select> tag in HTML is a versatile tool for creating drop-down lists, allowing users to select from predefined options. By utilizing attributes such as autofocus, disabled, multiple, name, required, and size, you can enhance the functionality and usability of your drop-down lists.

How to select text in HTML? ›

The select() method is used to select the content of a text field.

What is an HTML example? ›

Let's see a simple example of HTML. <! DOCTYPE html> <html> <head> <title>programiz</title> </head> <body> <h1>HTML Tutorial</h1> <p>You'll learn about HTML.</ p> </body> </html>

What is an HTML short answer? ›

HTML stands for Hyper Text Markup Language. HTML is the standard markup language for creating Web pages. HTML describes the structure of a Web page. HTML consists of a series of elements.

What is markup in HTML with an example? ›

Markup is what HTML tags do to the text inside of them; they mark it as a specific type of text. For example, markup text could come in the form of boldface or italicized type to draw specific attention to a word or phrase.

What is the purpose of the label tag in HTML? ›

The <label> element is used to associate a text label with a form <input> field. The label is used to tell users the value that should be entered in the associated input field.

How to select HTML element using tag name in JavaScript? ›

The getElementsByTagName() method returns a collection of all elements with a specified tag name. The getElementsByTagName() method returns an HTMLCollection. The getElementsByTagName() property is read-only.

How to find all HTML elements in JavaScript? ›

To get all the HTML tags present in a website using JavaScript, you can use the getElementsByTagName() method in the global document object and then pass the asterisk symbol * as an argument to it. // Get all HTML tags const allHTMLTags = document.

What is HyperText Markup Language in HTML? ›

HTML (Hypertext Markup Language) is a text-based approach to describing how content contained within an HTML file is structured. This markup tells a web browser how to display text, images and other forms of multimedia on a webpage.

What is the HTML used to define? ›

HTML (HyperText Markup Language) is the most basic building block of the Web. It defines the meaning and structure of web content.

What is an online service that allows people with shared interests to communicate and interact? ›

Social networking services allow individuals and companies to make connections and interact with others. Users can share content, such as photos, videos, and blogs. As such, these sites can provide individuals with a way to stay connected with friends and families.

How do I get a specific element in HTML? ›

The getElementById() method returns an element with a specified value. The getElementById() method returns null if the element does not exist. The getElementById() method is one of the most common methods in the HTML DOM.

How do you click an element in HTML? ›

The HTMLElement. click() method simulates a mouse click on an element. When called on an element, the element's click event is fired (unless its disabled attribute is set).

How do you select element required in HTML? ›

The required attribute specifies that an item must be selected before submitting the form. As long as the option value is null or is an empty string, the form cannot be submitted. The required attribute is part of the built-in validation functionality in HTML.

How to make drop down HTML? ›

How to Make a Dropdown Menu in HTML
  1. Step 1: Add a <label> element to your HTML document. This will be the name of your dropdown menu.
  2. Step 2: Add a <select> element. ...
  3. Step 3: Create <option> elements and place them inside the <select> element. ...
  4. Step 4: Add a default value from the dropdown list, if desired.
Jun 3, 2024

Top Articles
Latest Posts
Recommended Articles
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 6414

Rating: 4.6 / 5 (56 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.