<!DOCTYPE html>
<html lang="en">
<head>
<title>Visible vs. Hidden</title>
<meta name="viewport" content="initial-scale=1">
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<!-- no space reserved, hidden from aria-->
<div style="display: none;">
<h1>Heading</h1>
<a href="#link1">Link 1</a>
</div>
<!-- no space reservced, hidden from aria-->
<div hidden>
<h1>Heading</h1>
<a href="#link2">Link 2</a>
</div>
<!-- reserve the space, not hidden from aria-->
<div style="opacity: 0;">
<h1>Heading</h1>
<a href="#link3">Link 3</a><!-- can add tabindex="-1" to hide from tab focus -->
</div>
<!-- reserve the space, link is not reachable, similar to display:none; -->
<div style="visibility: hidden;">
<h1>Heading</h1>
<a href="#link4">Link 4</a>
</div>
<!-- content is still be renderered to the screen, and link is also reachable -->
<div class="visuallyhidden">
<h1>Heading</h1>
<a href="#link5">Link 5</a>
</div>
<!-- render to screen and hidden from aria-->
<div aria-hidden="true">
<h1>Heading</h1>
<a href="#link6">Link 6</a>
</div>
</body>
</html>
// Code goes here
/* Styles go here */
html, body {
font-family: Helvetica, sans-serif;
text-align: center;
}
.visuallyhidden {
border: 0;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
div {
color: #fff;
height: 100px;
float: left;
padding-bottom: 2%;
width: 200px;
}
div:before {
content: '';
display: block;
height: 35%;
}
div:nth-child(1) {
background-color: purple;
}
div:nth-child(2) {
background-color: red;
}
div:nth-child(3) {
background-color: blue;
}
div:nth-child(4) {
background-color: green;
}
div:nth-child(5) {
background-color: yellow;
color: #000;
}
div:nth-child(6) {
background-color: orange;
color: #000;
}
div:nth-child(5) a,
div:nth-child(6) a {
color: #000;
}
div h1 {
margin: 0;
}
div a {
color: #fff;
display: block;
font-size: 1em;
font-weight: bold;
padding: 0.5em;
}
div button, {
background-color: #000;
border: 0;
color: #fff;
font-size: 1em;
padding: 0.5em;
}
div button:focus {
background-color: #fff;
color: #000;
}