W3.CSS Visibility
Show and Hide
W3.CSS makes it easy to show and hide content.
Hide an element, reveal extra details with a button, or choose what appears at different screen sizes.
Hide an Element
Use w3-hide to hide an element.
The class sets display:none, so the hidden element takes up no space in the layout.
Panel 2 is hidden below, so Panel 3 follows Panel 1.
Panel 1
Panel 2
Panel 3
Example
<div class="w3-panel w3-light-grey">
<p>Panel 1</p>
</div>
<div class="w3-panel w3-pale-blue w3-hide">
<p>Panel 2</p>
</div>
<div class="w3-panel w3-light-grey">
<p>Panel 3</p>
</div>
Try it Yourself »
Try removing w3-hide from Panel 2 and run the example again.
Show an Element
Use w3-show to display an element as a block.
A block starts on a new line and normally fills the available width of its parent.
In this example, w3-show makes the second panel visible even though it also has w3-hide.
This panel is hidden.
This panel is visible.
Example
<div class="w3-panel w3-pale-blue w3-hide">
<p>This panel is hidden.</p>
</div>
<div class="w3-panel w3-pale-blue w3-hide w3-show">
<p>This panel is visible.</p>
</div>
Try it Yourself »
w3-show-block
The w3-show-block class is another name for w3-show.
Both classes set display:block and produce the same result.
Show an Inline Block
Use w3-show-inline-block when the element should appear within a line of text.
An inline block normally uses only the width its content needs and can sit beside other content.
The label below is revealed beside the word Status.
Status: Saved
Example
<p>Status:
<span class="w3-tag w3-teal w3-hide w3-show-inline-block">Saved</span>
</p>
Try it Yourself »
Try changing w3-show-inline-block to w3-show to see the label become a block.
Toggle Visibility
Use a button and a little JavaScript to show or hide extra content.
Click the button to reveal the details panel, then click it again to hide the panel.
More Details
This panel is now visible.
This paragraph moves down when the panel appears.
Example
<button class="w3-button w3-teal" onclick="toggleVisibilityDemo(this)">Show or hide details</button>
<div id="visibilityDemo" class="w3-panel w3-pale-blue w3-hide">
<h3>More Details</h3>
<p>This panel is now visible.</p>
</div>
<p>This paragraph moves down when the panel appears.</p>
<script>
function toggleVisibilityDemo(button) {
const panel = document.getElementById("visibilityDemo");
const isVisible = panel.classList.toggle("w3-show");
button.setAttribute("aria-expanded", isVisible);
}
</script>
Try it Yourself »
The panel starts with w3-hide.
The classList.toggle() method adds w3-show if it is missing and removes it if it is present.
The button's aria-expanded value is updated so assistive technology can announce whether the panel is expanded.
Responsive Visibility
Use the responsive hide classes to hide content at different screen widths.
These classes respond to viewport changes automatically, without JavaScript.
| Class | Hidden When the Viewport Width Is |
|---|---|
| w3-hide-small | 600px or less |
| w3-hide-medium | 601px to 992px |
| w3-hide-large | 993px or more |
The breakpoints use the browser viewport width.
In Tryit, this is the width of the result area.
Resize the window or result area to see which panel disappears.
Example
<div class="w3-panel w3-pale-blue w3-hide-small"> <p>Hidden on small screens: 600px or less.</p> </div> <div class="w3-panel w3-pale-green w3-hide-medium"> <p>Hidden on medium screens: 601px to 992px.</p> </div> <div class="w3-panel w3-pale-yellow w3-hide-large"> <p>Hidden on large screens: 993px or more.</p> </div>Try it Yourself »
Show Content in One Screen Range
Combine two responsive hide classes to show content only in the remaining screen-width range.
For example, w3-hide-medium w3-hide-large hides an element on medium and large screens, so it appears only on small screens.
Only one of these panels is visible in each range.
Example
<div class="w3-panel w3-pale-blue w3-hide-medium w3-hide-large"> <p>Shown only on small screens.</p> </div> <div class="w3-panel w3-pale-green w3-hide-small w3-hide-large"> <p>Shown only on medium screens.</p> </div> <div class="w3-panel w3-pale-yellow w3-hide-small w3-hide-medium"> <p>Shown only on large screens.</p> </div>Try it Yourself »
Visibility Classes
| Class | Description |
|---|---|
| w3-hide | Hides an element and removes its layout space. |
| w3-show | Displays an element as a block. |
| w3-show-block | Same as w3-show. |
| w3-show-inline-block | Displays an element as an inline block. |
| w3-hide-small | Hides an element on screens 600px wide or smaller. |
| w3-hide-medium | Hides an element on screens from 601px to 992px wide. |
| w3-hide-large | Hides an element on screens 993px wide or larger. |