How to create custom select dropdowns

Creating custom select dropdowns can enhance the user experience on your website. By utilizing HTML and CSS, you can craft visually appealing and functional dropdown menus that align with your design preferences.

<div class="custom-select"> <div class="select-selected">Select an option</div> <div class="select-items select-hide"> <div>Option 1</div> <div>Option 2</div> <div>Option 3</div> </div> </div> <style> .custom-select { position: relative; font-family: Arial; } .select-selected { background-color: #ddd; } .select-selected:hover, .select-selected:focus { background-color: #ccc; } .select-items div { padding: 10px; cursor: pointer; background-color: #f9f9f9; } .select-items div:hover { background-color: #e5e5e5; } </style> <script> const selected = document.querySelector('.select-selected'); const items = document.querySelector('.select-items'); selected.addEventListener('click', () => { items.classList.toggle('select-hide'); }); items.addEventListener('click', (e) => { if (e.target.tagName === 'DIV') { selected.textContent = e.target.textContent; items.classList.add('select-hide'); } }); </script>

custom select dropdown HTML dropdown CSS dropdown custom select box