Hiding & Showing: Display, Visibility, & Opacity
Master CSS visibility techniques for better web accessibility
CSS Visibility Methods Overview
Display: None
Completely removes elements from document flow. Not accessible to screen readers but useful for complete removal.
Visibility: Hidden
Hides elements visually but maintains space in layout. Screen reader accessible and preserves document flow.
Opacity: 0
Makes elements transparent while keeping them interactive. Best for transitions and maintains full accessibility.
Project Setup Steps
Close All Files
Close all open files in your code editor to avoid confusion with multiple projects
Open Project Folder
Navigate to Desktop > Class Files > Advanced HTML CSS Class and open the Hiding and Showing Elements folder
Launch Preview
Open index.html in your code editor and preview it in Chrome for DevTools access
Test the responsive behavior again by resizing your browser window. The Oil text should remain perfectly centered regardless of viewport size—this is the hallmark of robust, scalable CSS.
Display: None Analysis
Using visibility: hidden instead of display: none makes content accessible to screen readers while still hiding it visually. This follows web accessibility best practices for inclusive design.
Implementing Opacity Controls
Set Initial Transparency
Use opacity: 0 to make elements fully transparent while maintaining their position in document flow
Configure Hover State
Set opacity: 1 on hover to reveal the element with full opacity
Test Interaction
Verify that transparent elements remain interactive and accessible to screen readers
CSS Visibility Methods Comparison
| Feature | Display: None | Visibility: Hidden | Opacity: 0 |
|---|---|---|---|
| Document Flow | Removed | Maintained | Maintained |
| Screen Reader Access | No | Yes | Yes |
| User Interaction | No | No | Yes |
| CSS Transitions | No | No | Yes |
| Space Reserved | No | Yes | Yes |
Opacity is chosen as the best solution because it maintains accessibility, supports CSS transitions for smooth animations, and keeps elements interactive. This makes it ideal for modern web development practices.
Complete the Gallery
Copy the structure from Oil overlay and update the text content
Ensure consistent HTML structure across all image categories
Test hover effects work correctly on all four image overlays
Verify labels appear correctly and accessibility is maintained
Key Takeaways
