A hidden attribute on an <input> tag hides the input element.
Although the input element is not visible, its position on the page is maintained.
A hidden attribute on an <input> element.
The text field is not visible.
A hidden input element:
<p>A hidden input element:</p>
<input type="text" hidden>
The hidden attribute hides the <input> element.
You can specify either 'hidden' (without value) or 'hidden="hidden"'. Both are valid.
A hidden <img> is not visible, but maintains its position on the page.
<input hidden>
<input hidden="hidden">
Value | Description |
---|---|
hidden | Use value 'hidden' or no value at all. |
Clicking the button toggles A hidden attribute on the <input> element.
<input id="myinput" type="text" placeholder="Enter your name...">
<br /><br />
<button onclick="toggle(this)">Hide input</button>
<script>
let toggle = button => {
let element = document.getElementById("myinput");
let hidden = element.getAttribute("hidden");
if (hidden) {
element.removeAttribute("hidden");
button.innerText = "Hide input";
} else {
element.setAttribute("hidden", "hidden");
button.innerText = "Show input";
}
}
</script>
Initially, the <input> can be seen and has no hidden attribute.
Clicking the button calls JavaScript which toggles the hidden attribute from the <input> element.
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 |