Sometimes you want to hide parts of a webpage or control if something is visible. This helps keep the page clean or show things only when needed.
Hidden and visibility control in Tailwind
hidden visible invisible
hidden completely hides an element and removes it from the page layout.
invisible hides the element but keeps its space on the page.
<div class="hidden">This text is hidden and takes no space.</div><div class="invisible">This text is invisible but space is reserved.</div><div class="visible">This text is visible.</div>This page shows three examples: a hidden paragraph that disappears completely, an invisible paragraph that keeps space but is not seen, and a visible paragraph. There's also a button that toggles a hidden message on and off.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1" /> <title>Hidden and Visibility Control</title> <script src="https://cdn.tailwindcss.com"></script> </head> <body class="p-6 font-sans"> <h1 class="text-2xl mb-4">Hidden and Visibility Control Example</h1> <div class="mb-2 bg-blue-100 p-3"> <p class="hidden">This paragraph is hidden and takes no space.</p> <p class="visible">This paragraph is visible and shows normally.</p> </div> <div class="mb-2 bg-green-100 p-3"> <p class="invisible">This paragraph is invisible but space is reserved.</p> <p>This paragraph is below the invisible one.</p> </div> <button id="toggleBtn" class="mt-4 px-4 py-2 bg-indigo-600 text-white rounded">Toggle Hidden Text</button> <p id="toggleText" class="hidden mt-2 bg-yellow-100 p-2">You toggled me visible!</p> <script> const btn = document.getElementById('toggleBtn'); const text = document.getElementById('toggleText'); btn.addEventListener('click', () => { text.classList.toggle('hidden'); }); </script> </body> </html>
Use hidden when you want to remove an element completely from view and layout.
Use invisible when you want to hide something but keep the space it occupies, so the page layout doesn't jump.
Toggle visibility with JavaScript by adding or removing the hidden class for interactive effects.
hidden hides and removes element space.
invisible hides but keeps space.
Use these classes to control what users see and keep your page tidy.