Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Using the CSS Visibility Property
📖 Scenario: You are creating a simple webpage with a message that can be hidden or shown using CSS. This is useful when you want to keep the space reserved but hide the content visually.
🎯 Goal: Build a webpage with a visible message inside a <div>. Then use the CSS visibility property to hide the message without removing its space.
📋 What You'll Learn
Create an HTML structure with a <div> containing the text 'Hello, world!'
Add a CSS rule to set the visibility property of the <div> to visible
Add a CSS rule to change the visibility property of the <div> to hidden
Ensure the hidden message still occupies space on the page
💡 Why This Matters
🌍 Real World
Web developers often need to hide elements without changing the page layout. The visibility property is useful for this.
💼 Career
Understanding CSS visibility helps in creating accessible and well-structured web pages that behave predictably.
Progress0 / 4 steps
1
Create the HTML structure with a message
Create an HTML file with a <div> element that contains the text Hello, world!. Use semantic HTML5 structure with <main> and include lang="en" in the <html> tag.
CSS
Hint
Remember to use semantic tags like <main> and set the language attribute on <html>.
2
Add CSS to make the message visible
Inside a <style> tag in the <head>, write a CSS rule that sets the visibility property of the <div> to visible.
CSS
Hint
Put your CSS inside a <style> tag in the <head>.
3
Change the visibility to hidden
Modify the CSS rule for the div to set the visibility property to hidden instead of visible.
CSS
Hint
Change the value of visibility from visible to hidden.
4
Confirm the hidden message still occupies space
Add a CSS rule to the main element that sets a visible border so you can see the space the hidden div occupies. Use border: 2px solid black;.
CSS
Hint
Adding a border to main helps you see the space the hidden div still takes.
Practice
(1/5)
1. What does the CSS property visibility: hidden; do to an element on a webpage?
easy
A. It makes the element transparent but still clickable.
B. It hides the element but keeps its space reserved on the page.
C. It removes the element completely from the page layout.
D. It changes the element's color to match the background.
Solution
Step 1: Understand the visibility property
The visibility property controls whether an element is visible or hidden but does not affect layout space.
Step 2: Analyze the effect of hidden
When set to hidden, the element is not shown but still occupies space on the page.
Final Answer:
It hides the element but keeps its space reserved on the page. -> Option B
Quick Check:
visibility: hidden hides but keeps space [OK]
Hint: Hidden keeps space, display none removes it [OK]
Common Mistakes:
Confusing visibility: hidden with display: none
Thinking hidden elements are clickable
Assuming hidden elements disappear completely
2. Which of the following is the correct CSS syntax to hide an element but keep its space using the visibility property?
easy
A. visibility: hidden;
B. visibility = hidden;
C. visible: hidden;
D. hide: visibility;
Solution
Step 1: Recall correct CSS property syntax
CSS properties use a colon : between property and value, ending with a semicolon.
Step 2: Match syntax to visibility property
The correct syntax is visibility: hidden; to hide but keep space.
Final Answer:
visibility: hidden; -> Option A
Quick Check:
Property: value; is correct CSS syntax [OK]
Hint: Use colon, not equals, for CSS properties [OK]