We are independent & ad-supported. We may earn a commission for purchases made through our links.
Advertiser Disclosure
Our website is an independent, advertising-supported platform. We provide our content free of charge to our readers, and to keep it that way, we rely on revenue generated through advertisements and affiliate partnerships. This means that when you click on certain links on our site and make a purchase, we may earn a commission. Learn more.
How We Make Money
We sustain our operations through affiliate commissions and advertising. If you click on an affiliate link and make a purchase, we may receive a commission from the merchant at no additional cost to you. We also display advertisements on our website, which help generate revenue to support our work and keep our content free for readers. Our editorial team operates independently of our advertising and affiliate partnerships to ensure that our content remains unbiased and focused on providing you with the best information and recommendations based on thorough research and honest evaluations. To remain transparent, we’ve provided a list of our current affiliate partners here.
Software

Our Promise to you

Founded in 2002, our company has been a trusted resource for readers seeking informative and engaging content. Our dedication to quality remains unwavering—and will never change. We follow a strict editorial policy, ensuring that our content is authored by highly qualified professionals and edited by subject matter experts. This guarantees that everything we publish is objective, accurate, and trustworthy.

Over the years, we've refined our approach to cover a wide range of topics, providing readers with reliable and practical advice to enhance their knowledge and skills. That's why millions of readers turn to us each year. Join us in celebrating the joy of learning, guided by standards you can trust.

What Is an HTML Listbox?

By Eugene P.
Updated: May 17, 2024
References

In the HyperText Markup Language (HTML), a listbox is a type of interactive graphical user interface (GUI) component. It appears on a website as a box within the page that contains a vertical set of text options that can be selected by the user. The purpose of using an HTML listbox is to present a user with a number of options from which they can select, and then to react to the selection. There are many options available to customize a listbox, especially through the use of cascading style sheets (CSS). There is a visual and functional difference between an HTML listbox and another GUI element known as a combobox, even though they are defined in much the same way.

In a document, an HTML listbox is defined using the select tag. This tag starts the listbox and can be used to define several options. One of the most important properties of the select tag is the name of the listbox, which gives other parts of the HTML document the ability to directly access the values of the listbox. Another important option that can be set is the multiple property, which can allow a user to select multiple items from the list simultaneously instead of just one at a time.

Between the opening and closing select tags, the actual elements to be contained in an HTML listbox are defined using the option tag. The option tag encloses the actual text that will be displayed in the HTML listbox. Like the select tag, it also has some important properties. A valuable property of the option tag is the ability to define a return value for a selected option that is sent to a querying script instead of the text that the user sees. This means a user can see the word "red", but the HTML listbox can return the hexadecimal value of red instead of the actual word.

Aside from options, an HTML listbox can contain another visual element known as an optgroup. An optgroup is a heading that is used to visually separate the different options inside a listbox. When a user looks at a listbox that contains optgroup tags, he or she will see a bold heading in the box, under which the associated options will be slightly indented and not bold.

Even though a functional HTML listbox can be made and placed on a website, it will not actually do anything when a user selects an option unless supporting code is present to do so. This can be done with JavaScript® by accessing the listbox through the document object model (DOM), or it can be performed with other scripts or applets. As an interactive element, a listbox generates user events such as mouseover, which can be captured within the browser.

WiseGeek is dedicated to providing accurate and trustworthy information. We carefully select reputable sources and employ a rigorous fact-checking process to maintain the highest standards. To learn more about our commitment to accuracy, read our editorial process.
Link to Sources
Discussion Comments
By anon1005104 — On Jun 23, 2021

A dropdown or combobox is NOT and will never be the same as a listbox.

HTML has no listbox control.

Share
https://www.wisegeek.net/what-is-an-html-listbox.htm
WiseGeek, in your inbox

Our latest articles, guides, and more, delivered daily.

WiseGeek, in your inbox

Our latest articles, guides, and more, delivered daily.