How to create: Full-page tab

Learn how to use CSS and JavaScript to create a full-page tab that covers the entire browser window (fullscreen tab).

Full-page tab

Click the link to display the "current" page:

Home

Home is where the heart is...

News

Some news on this fine day!

Contact

Get in touch, or drop by for a cup of coffee.

About

Who we are and what we do.

Try It Yourself

Create a single-page tab

Step 1 - Add HTML:

<button class="tablink" onclick="openPage('Home', this, 'red')">Home</button>
<button class="tablink" onclick="openPage('News', this, 'green')" id="defaultOpen">News</button>
<button class="tablink" onclick="openPage('Contact', this, 'blue')">Contact</button>
<button class="tablink" onclick="openPage('About', this, 'orange')">About</button>
<div id="Home" class="tabcontent">
  <h3>Home</h3>
  <p>Home is where the heart is..</p>
</div>
<div id="News" class="tabcontent">
  <h3>News</h3>
  <p>Some news this fine day!</p>
</div>
<div id="Contact" class="tabcontent">
  <h3>Contact</h3>
  <p>Get in touch, or swing by for a cup of coffee.</p>
</div>
<div id="About" class="tabcontent">
  <h3>About</h3>
  <p>Who we are and what we do.</p>
</div>

Create buttons to open specific tab content. All elements with class="tabcontent" of <div> Elements are initially hidden (by CSS and JS). When the user clicks a button, it opens the tab content that matches this button.

Step 2 - Add CSS:

Set the style for the link and tab content (full page):

/* Set the height of body and document to 100% to enable 'full page tabs'
body, html {
  height: 100%;
  margin: 0;
  font-family: Arial;
}
/* Set the style for the tab links */
.tablink {
  background-color: #555;
  color: white;
  float: left;
  border: none;
  outline: none;
  cursor: pointer;
  padding: 14px 16px;
  font-size: 17px;
  width: 25%;
}
.tablink:hover {
  background-color: #777;
}
/* Set the style for tab content (and add height: 100% to the entire page content) */
.tabcontent {
  color: white;
  display: none;
  padding: 100px 20px;
  height: 100%;
}
#Home {background-color: red;}
#News {background-color: green;}
#Contact {background-color: blue;}
#About {background-color: orange;}

Third step - Add JavaScript:

function openPage(pageName, elmnt, color) {
  // Default hide all elements with class="tabcontent"
  var i, tabcontent, tablinks;
  tabcontent = document.getElementsByClassName("tabcontent");
  for (i = 0; i < tabcontent.length; i++) {
    tabcontent[i].style.display = "none";
  }
  // Remove the background color from all tab links/buttons
  tablinks = document.getElementsByClassName("tablink");
  for (i = 0; i < tablinks.length; i++) {
    tablinks[i].style.backgroundColor = "";
  }
  // Display the specific tab content
  document.getElementById(pageName).style.display = "block";
  // Add a specific color to the button used to open the tab content
  elmnt.style.backgroundColor = color;
}
// Get the element with id="defaultOpen" and click it
document.getElementById("defaultOpen").click();

Try It Yourself

Related Pages

Tutorial:How to Create Tab