Table of Contents
Basic Multi-Select Dropdown
Set Size to Show Multiple Rows
Styling and Usability Tips
Submitting Selected Values
Home Web Front-end HTML Tutorial How to create a multi-select dropdown in html?

How to create a multi-select dropdown in html?

Sep 21, 2025 am 03:39 AM
html 多选下拉框

Use the select element to add multiple attributes to create a multi-select drop-down box. The user presses the Ctrl or Shift key to select multiple options, displays multiple lines through the size attribute, and submits the selected value in conjunction with the name attribute array format.

How to create a multi-select dropdown in html?

To create a multi-select dropdown in HTML, use the select element with the multiple attribute. This allows users to select more than one option from the list.

Basic Multi-Select Dropdown

Add the multiple attribute to the select tag. Users can select multiple options by holding down the Ctrl (or Cmd on Mac) key while clicking, or by using Shift to select a range.

Example:

Set Size to Show Multiple Rows

By default, the dropdown may show only one row. Use the size attribute to display several options at once, making it easier to see and select multiple items.

Example:

Styling and Usability Tips

The default appearance can be improved with CSS. You can also add a label to make it accessible.

  • Wrap the select in a label or use the for and id attributes
  • Set a helpful instruction like "Hold Ctrl to select multiple"
  • Use CSS to adjust width, height, or font

Submitting Selected Values

When used in a form, multiple selected values ​​are sent as separate entries with the same name. On the server side (eg, PHP, Python), you'll receive them as an array or list.

In PHP, access them like:

$selectedFruits = $_POST['fruits']; // returns an array

Basically, just add multiple to your select element and make sure the name ends with [] if required by your backend (eg, name="fruits[]" in PHP).

The above is the detailed content of How to create a multi-select dropdown in html?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

ArtGPT

ArtGPT

AI image generator for creative art from text prompts.

Stock Market GPT

Stock Market GPT

AI powered investment research for smarter decisions

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to import bookmarks from other browsers by UC browser_How to import bookmark data by UC browser How to import bookmarks from other browsers by UC browser_How to import bookmark data by UC browser Sep 24, 2025 am 10:36 AM

You can migrate bookmarks from other browsers through the UC browser import function: first select "Import Bookmarks" and authorize reading data; 2. Support manual import from HTML files. You must first export the bookmarks to HTML in the source browser and select file import; 3. You can also transfer through cloud service, enable cloud synchronization and pull the bookmark data in the UC browser to complete the migration.

What is the difference between object and embed tags in html? What is the difference between object and embed tags in html? Sep 23, 2025 am 01:54 AM

Theobjecttagispreferredforembeddingexternalcontentduetoitsversatility,fallbacksupport,andstandardscompliance,whileembedissimplerbutlacksfallbackandparameteroptions,makingitsuitableonlyforbasicusecases.

How to make a full-screen background image with HTML How to make a full-screen background image with HTML Sep 23, 2025 am 05:43 AM

Setting up a full-screen background image using CSS can be achieved by directly styling the body or using a full-screen container. 1. Set background-size to cover and cooperate with background-position:center to ensure that the image is covered and centered; 2. Optionally fix the background or use containers to control the layout more flexibly; 3. Use high resolution to optimize the picture and add fallback colors to improve the experience.

What is semantic HTML What is semantic HTML Sep 25, 2025 am 02:37 AM

SemanticHTMLusesmeaningfultagslikearticle,section,nav,andmaintoclearlydefinecontentstructureforbothdevelopersandbrowsers.Theseelementsimproveaccessibilitybyenablingscreenreaderstointerpretpagelayouteffectively,enhanceSEOthroughbettercontentorganizati

What is the head tag in html? What is the head tag in html? Sep 24, 2025 am 06:47 AM

Theheadtagcontainsmetadataandresourcesessentialforbrowserandsearchengineprocessing,includingtitle,characterset,description,stylesheets,scripts,andviewportsettings,asshownintheexamplewithproperHTMLstructure.

How to force a link to download a file in html? How to force a link to download a file in html? Sep 22, 2025 am 02:34 AM

Use the download attribute to force the browser to download files instead of opening them. For example, downloading PDFs, which support custom file names and homologous files. Cross-domain requires the server to cooperate with CORS and Content-Disposition headers.

How to auto-play a video in HTML How to auto-play a video in HTML Sep 25, 2025 am 05:04 AM

To achieve automatic video playback, the video must be muted. Use the autoplay and muted properties to ensure that HTML videos are automatically played in modern browsers. If you want to play loops, you can add loop attributes. If you remove controls, the control bar will not be displayed.

How to create a simple image gallery in HTML How to create a simple image gallery in HTML Sep 25, 2025 am 01:20 AM

Create an HTML structure, use div containers and img tags to add images; 2. Set flex or grid layout with CSS, adjust spacing and styles; 3. Implement responsive design through media queries; 4. Optionally add image containers with text to display the title.

See all articles