Dofactory.com
Dofactory.com

HTML <select> hidden Attribute

A hidden attribute on a <select> tag hides the dropdown.

Although the dropdown is not visible, its position on the page is maintained.

Example

#

A hidden attribute on a <select> element.
The dropdown control is not visible.

A hidden select element:

<p>A hidden select element:</p>

<select hidden>
  <option value="">-- Select city -- </option>
  <option value="paris">Paris</option>
  <option value="london">London</option>
  <option value="athens">Athens</option>
  <option value="madrid">Madrid</option>
</select>

Using hidden

The hidden attribute hides the <select> element.

You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid.

A hidden <select> element is not visible, but it maintains its position on the page.

Removing the hidden attribute makes it re-appear.


Syntax

<select hidden>
or
<select hidden="hidden">

Values

#

Value Description
hidden Use 'hidden' or hidden='hidden'. Both are valid.


More Examples

Clicking the button will toggle A hidden attribute on the <select> element.



<select id="myselect">
  <option value="">-- Select city -- </option>
  <option value="paris">Paris</option>
  <option value="london">London</option>
  <option value="athens">Athens</option>
  <option value="madrid">Madrid</option>
</select>

<br /><br />
<button onclick="toggle(this)">Hide Select</button>

<script>
  let toggle = button => {
     let element = document.getElementById("myselect");
     let hidden = element.getAttribute("hidden");
    
     if (hidden) {
        element.removeAttribute("hidden");
        button.innerText = "Hide Select";
     } else {
        element.setAttribute("hidden", "hidden");
        button.innerText = "Show Select";
     }
  }
</script>

Code explanation

Initially, the <select> is visible.

Clicking the button calls JavaScript that toggles the hidden attribute.

With the hidden attribute the dropdown is invisible.


Browser support

Here is when hidden support started for each browser:

Chrome
1.0 Sep 2008
Firefox
1.0 Sep 2002
IE/Edge
1.0 Aug 1995
Opera
1.0 Jan 2006
Safari
1.0 Jan 2003

You may also like

 Back to <select>

Author: Jack Poorte
Published: Jun 20 2021
Last Reviewed: Sep 30 2023


Quick question: what's your favorite/least favorite part of Dofactory?


Guides