dropdown menu in html
- User
dropdown menu in html
- Assistant
To create a dropdown menu in HTML, you can use the
<select>element combined with<option>elements for each item in the dropdown. Here's a simple example:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Dropdown Menu Example</title> </head> <body> <h2>Select a Fruit</h2> <select name="fruits" id="fruits-dropdown"> <option value="apple">Apple</option> <option value="banana">Banana</option> <option value="cherry">Cherry</option> <option value="date">Date</option> <option value="grape">Grape</option> </select> <script> // Accessing the dropdown menu in JavaScript (optional) const dropdown = document.getElementById('fruits-dropdown'); dropdown.addEventListener('change', function() { console.log('Selected fruit:', this.value); }); </script> </body> </html>