Visibility Utilities visible/invisible
Control the visibility of elements without affecting their layout space using visibility utilities.
Quick Reference
visible
Make element visible
visibility: visible
invisible
Hide element but preserve space
visibility: hidden
Interactive Examples
Visible vs Invisible
All Elements Visible
Middle Element Invisible
✓ Invisible elements preserve their layout space
✓ Other elements don't move to fill the space
✓ Element is not visible but still affects layout
<div class="invisible">Hidden but space preserved</div>
Visibility vs Display Comparison
Using invisible (space preserved)
Using hidden (space collapsed)
invisible: Element hidden, space preserved
hidden: Element removed from layout flow
Interactive Visibility Toggle
✓ Notice how the layout doesn't shift when toggling
✓ Space is always preserved for the middle element
Responsive Visibility
✓ Resize window to see responsive behavior
✓ Space is preserved at all breakpoints
<div class="invisible md:visible">Responsive visibility</div>
Common Use Cases
🎯 Loading States
Hide content while preserving layout during loading.
<div class="invisible">Loading...</div>
📱 Responsive Design
Show/hide elements at different breakpoints.
<div class="invisible md:visible">
🎨 Animation Preparation
Hide elements before animating them in.
<div class="invisible animate-fade-in">
🔧 Form Validation
Show/hide error messages without layout shift.
<span class="invisible text-red-500">
📊 Data Visualization
Toggle chart elements without affecting layout.
<g class="invisible">Chart layer</g>
🎮 Interactive Elements
Hide/show UI elements in games or apps.
<div class="invisible hover:visible">
Visibility vs Other Hiding Methods
Method Comparison
Method | Space | Events | Screen Reader |
---|---|---|---|
invisible | ✓ Preserved | ✗ No events | ✗ Hidden |
hidden | ✗ Collapsed | ✗ No events | ✗ Hidden |
opacity-0 | ✓ Preserved | ✓ Events work | ✓ Accessible |
sr-only | ✗ Collapsed | ~ Limited | ✓ Accessible |
When to Use Each Method
invisible
When you need to hide content but preserve layout space. Good for loading states and preventing layout shifts.
hidden
When you want to completely remove content from layout. Good for responsive design and conditional content.
opacity-0
When you need invisible content that can still receive events. Good for animations and interactive overlays.
sr-only
When content should only be available to screen readers. Good for accessibility labels and descriptions.
Best Practices
✅ Do
- • Use
invisible
to prevent layout shifts - • Combine with responsive utilities for adaptive design
- • Use for loading states and skeleton screens
- • Consider accessibility when hiding content
- • Test with screen readers when appropriate
- • Use for form validation messages
❌ Don't
- • Use
invisible
whenhidden
is more appropriate - • Hide important content without providing alternatives
- • Use for content that should be completely removed
- • Forget about keyboard navigation implications
- • Use when opacity or other methods would be better
- • Hide content that affects user understanding