HTML hidden Attribute

HTMLWeb DevelopmentFront End Technology

The HTML hidden attribute is used to communicate to the user that element with hidden attribute is no longer relevant to the document and should not be visible to the user.

Let us see an example of hidden attribute −


 Live Demo

<!DOCTYPE html>
<title>HTML hidden attribute</title>
   form {
      margin: 0 auto;
      text-align: center;
   * {
      padding: 2px;
   input[type="button"] {
      border-radius: 10px;
<input type="text" id="textSelect" placeholder="Your Authorization Level">
<select id="selection1" hidden>
<option>Add user</option>
<option>Delete user</option>
<option>Modify user</option>
<select id="selection2" hidden>
<option>Mail admin</option>
<option>Call admin</option>
<input type="button" value="go" onclick="displaySelection()">
<div id="divDisplay">Hello</div>
   var textSelect = document.getElementById("textSelect");
   var divDisplay = document.getElementById("divDisplay");
   var selection1 = document.getElementById("selection1");
   var selection2 = document.getElementById("selection2");
   function displaySelection() {
      if(textSelect.value === 'admin'){
         selection1.hidden = false;
         selection2.hidden = true;
         divDisplay.textContent = 'Welcome Admin';  
      } else if(textSelect.value === 'user'){
         selection2.hidden = false;
         selection1.hidden = true;
         divDisplay.textContent = 'Welcome User';
      } else{
         selection2.hidden = true;
         selection1.hidden = true;
         divDisplay.textContent = 'Your input does not match any authorization';

1) Clicking ‘Go’ button with user authorization level −

2) Clicking ‘Go’ button with admin authorization level −

3) Clicking ‘Go’ button with unauthorized level −

Published on 19-Sep-2019 12:29:51