The dropdown list in HTML is an important element for form building purposes or for showing the selection list from which the user can select one or multiple values. This kind of selection list in HTML is known as the Dropdown list. It is created using
Syntax of Dropdown List in HTML
Let’s see how the Dropdown list is going to be created:
Syntax:
<select> <option value="">option1</option> <option value="">option2</option> <option value="">option3</option> <option value="">option3</option> </select>
Example:
<select name="color"> <option value="red">Red</option> <option value="purple">Purple </option> </select>
As shown in the above syntax , is a tag used to create Dropdown list.
Setting background color or color to the hover by using code:
.dropdown a:hover{ Background-color: color_name; }
Position for the dropdown list is defined into two values: position: a relative who is used to display the content of the list exactly right below the select list button. With the help of position: absolute;
Min-width is one of the properties used to give a specific width to the Drop Down list. We can set it as long as our drop-down button by setting the width to 100%. The above syntax is defined for single attribute selection; now, we will see how multiple options are going to be selected from the item list.
Syntax:
<select multiple> <option value="">option1</option> <option value="">option2</option> </select>
Example:
<select name="subject" multiple> <option value="math">Math</option> <option value="english">English</option> <option value="science">Science</option> <option value="biology">Biology</option> </select>
How does the Dropdown List work in HTML?
After studying the syntax now, we will see how exactly the Dropdown list is going to work in HTML. There are some attributes that are used in the
- Name: This attribute is helpful to assign a name to the control, which is going to send to the server to be identified and take the required value.
- Multiple: If the attribute is set to “multiple” then, the user can select multiple values from the selection list.
- Size: The size attribute is used to define a specific sized scrolling box around the Dropdown list. It is also helpful for displaying several visible options from the list.
- Value: This attribute will show an option in the selection list is selected.
- Selected attributes enable at the very starting points of page loads to show already selected list item from the list.
- Label: Label attributes works as another approach to labeling options value.
- Disabled: If we want to show a drop-down list with a disable option, it is possible to use a disabled attribute in the HTML select list.
- onChange: Whenever the user is going to select anyone the option from the dropdown list, then the event is triggered on item selection.
- onFocus: Whenever the user hovers the mouse on the selection list to select an option from the list, it triggers an event to select the item.
- Form: This attribute is used to define one or multiple forms that are related to the select field.
- disabled: We should keep our drop-down list disable from the user with the help of this attribute.
- required: Whenever filling some form, we want to show that this field is necessary to select any value from its list before actual sending form, so in this case, we define that the user is required to select any one value from the list.
Examples of HTML Code
The following examples will show how exactly the Dropdown list is going to be used:
Example #1
Code:
<title>DropDown List</title> <h4 id="Seven-Wonders-of-the-world">Seven Wonders of the world</h4>
The above example contains different options like disabled, selected, required, etc., which is shown in the output screen.
Output:
Example #2
Code:
Multiple options can be selected here .Please press ctrl key and select multiple options at a time.
<script> function multipleFunc() { document.getElementById("multiselectdd").multiple = true; } </script>As shown in the below screenshot, select multiple options from the dropdown list, press the given button and select multiple options by pressing on CTRL.
Output:
Example #3
Code:
<style> .dropdownbtn { background-color: black; color: white; padding: 12px; font-size: 12px; } .dropdowndemo{ position:fixed; display: block; } .dropdownlist-content { display: none; position: absolute; background-color: greenyellow; min-width: 120px; z-index: 1; } .dropdownlist-content a { color: darkblue; padding: 14px 18px; display: block; } .dropdownlist-content a:hover {background-color: lightcyan;} .dropdowndemo:hover .dropdownlist-content {display: block;} .dropdowndemo:hover .dropdownbtn {background-color: blue;} </style> <h2 id="Hover-Dropdown-Demo">Hover Dropdown Demo</h2> <div class="dropdowndemo"> <button class="dropdownbtn">HTML forms Element</button> <div class="dropdownlist-content"> <a href="#">Links</a> <a href="#">Dropdown list</a> <a href="#">Input Field</a> <a href="#">Button</a> <a href="#">Radio Buttons</a> </div> </div>
The dropdown list will be open on the hover effect.
出力:
結論
ドロップダウン リストは、選択リストからオプションを選択するために使用されると結論付けることができます。一度に 1 つまたは複数のオプションを選択するために使用されます。ユーザーはリストからオプションを選択できるため、より使いやすくなります。上記の属性は、ドロップダウン リストでさまざまな選択操作を行うために select タグとともに使用されます。
おすすめ記事
これは HTML でのドロップダウン リストのガイドです。ここでは、HTML でのドロップダウン リストの動作と、そのコード実装の例について説明します。詳細については、他の関連記事も参照してください –
- HTML スタイル属性
- HTML のトップ 10 の利点
- HTML フレーム
- HTML レイアウト
The above is the detailed content of Dropdown List in HTML. For more information, please follow other related articles on the PHP Chinese website!

HTMLtagsdefinethestructureofawebpage,whileattributesaddfunctionalityanddetails.1)Tagslike,,andoutlinethecontent'splacement.2)Attributessuchassrc,class,andstyleenhancetagsbyspecifyingimagesources,styling,andmore,improvingfunctionalityandappearance.

The future of HTML will develop in a more semantic, functional and modular direction. 1) Semanticization will make the tag describe the content more clearly, improving SEO and barrier-free access. 2) Functionalization will introduce new elements and attributes to meet user needs. 3) Modularity will support component development and improve code reusability.

HTMLattributesarecrucialinwebdevelopmentforcontrollingbehavior,appearance,andfunctionality.Theyenhanceinteractivity,accessibility,andSEO.Forexample,thesrcattributeintagsimpactsSEO,whileonclickintagsaddsinteractivity.Touseattributeseffectively:1)Usese

The alt attribute is an important part of the tag in HTML and is used to provide alternative text for images. 1. When the image cannot be loaded, the text in the alt attribute will be displayed to improve the user experience. 2. Screen readers use the alt attribute to help visually impaired users understand the content of the picture. 3. Search engines index text in the alt attribute to improve the SEO ranking of web pages.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML is used to build web page structure; 2. CSS is used to beautify the appearance of web pages; 3. JavaScript is used to achieve dynamic interaction. Through tags, styles and scripts, these three together build the core functions of modern web pages.

Setting the lang attributes of a tag is a key step in optimizing web accessibility and SEO. 1) Set the lang attribute in the tag, such as. 2) In multilingual content, set lang attributes for different language parts, such as. 3) Use language codes that comply with ISO639-1 standards, such as "en", "fr", "zh", etc. Correctly setting the lang attribute can improve the accessibility of web pages and search engine rankings.

HTMLattributesareessentialforenhancingwebelements'functionalityandappearance.Theyaddinformationtodefinebehavior,appearance,andinteraction,makingwebsitesinteractive,responsive,andvisuallyappealing.Attributeslikesrc,href,class,type,anddisabledtransform

TocreatealistinHTML,useforunorderedlistsandfororderedlists:1)Forunorderedlists,wrapitemsinanduseforeachitem,renderingasabulletedlist.2)Fororderedlists,useandfornumberedlists,customizablewiththetypeattributefordifferentnumberingstyles.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
