Bird
Raised Fist0
CSSmarkup~20 mins

Visibility property in CSS - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

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
Challenge - 5 Problems
🎖️
Visibility Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
What happens when visibility is set to hidden?
Consider a block element styled with visibility: hidden;. What will you see in the browser?
CSS
<style>div { width: 100px; height: 100px; background: red; visibility: hidden; }</style><div></div>
AThe element is invisible but still takes up space on the page.
BThe element disappears and the space it occupied collapses.
CThe element becomes transparent but can still be clicked.
DThe element is removed from the DOM.
Attempts:
2 left
💡 Hint
Think about whether the element's space remains reserved or not.
📝 Syntax
intermediate
2:00remaining
Which CSS rule correctly hides an element but keeps its space?
Select the CSS rule that hides an element visually but preserves its space in the layout.
Adisplay: none;
Bvisibility: hidden;
Copacity: 0;
Dposition: absolute; left: -9999px;
Attempts:
2 left
💡 Hint
Remember, some properties remove the element from the layout flow.
rendering
advanced
2:00remaining
What is the visual result of this CSS snippet?
Given the following HTML and CSS, what will you see in the browser?
CSS
<style>p { visibility: collapse; border: 1px solid black; }</style><p>Hello</p>
AThe paragraph is invisible but space remains.
BThe paragraph is visible with a border.
CThe paragraph is hidden and its space collapses like display:none.
DThe paragraph text is visible but border is hidden.
Attempts:
2 left
💡 Hint
Consider how visibility: collapse; behaves on block elements.
selector
advanced
2:00remaining
Which CSS selector targets only visible elements?
You want to style only elements that are visible (not hidden by visibility). Which selector works best?
A:is(:not([style*='visibility: hidden']))
B:visible
C:not([hidden])
D:where(:not([style*='visibility: hidden']))
Attempts:
2 left
💡 Hint
CSS does not have a native :visible selector, but you can use negation with :where for specificity.
accessibility
expert
2:00remaining
How does visibility: hidden; affect screen readers?
If an element has visibility: hidden;, what is the expected behavior for screen readers?
AScreen readers read the element only if it has ARIA roles.
BScreen readers read the element but do not allow interaction.
CScreen readers still read the element content aloud.
DScreen readers ignore the element completely as if it is not in the DOM.
Attempts:
2 left
💡 Hint
Think about how hidden content should be treated for accessibility.

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

  1. Step 1: Understand the visibility property

    The visibility property controls whether an element is visible or hidden but does not affect layout space.
  2. Step 2: Analyze the effect of hidden

    When set to hidden, the element is not shown but still occupies space on the page.
  3. Final Answer:

    It hides the element but keeps its space reserved on the page. -> Option B
  4. 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

  1. Step 1: Recall correct CSS property syntax

    CSS properties use a colon : between property and value, ending with a semicolon.
  2. Step 2: Match syntax to visibility property

    The correct syntax is visibility: hidden; to hide but keep space.
  3. Final Answer:

    visibility: hidden; -> Option A
  4. Quick Check:

    Property: value; is correct CSS syntax [OK]
Hint: Use colon, not equals, for CSS properties [OK]
Common Mistakes:
  • Using equals sign instead of colon
  • Swapping property and value order
  • Using non-existent CSS properties
3. Consider this HTML and CSS:
<div style="visibility: hidden; background: red; width: 100px; height: 100px;">Box</div>

What will you see on the webpage?
medium
A. A transparent box with the text 'Box' visible.
B. A red box with the text 'Box' visible.
C. No space or box visible at all.
D. No red box or text, but space is reserved where the box would be.

Solution

  1. Step 1: Analyze the visibility property effect

    The style visibility: hidden; hides the element but keeps its space on the page.
  2. Step 2: Understand the visual output

    The red box and text are hidden, so nothing is visible, but the space of 100x100 pixels remains empty.
  3. Final Answer:

    No red box or text, but space is reserved where the box would be. -> Option D
  4. Quick Check:

    visibility: hidden hides content but keeps space [OK]
Hint: Hidden means invisible but space stays [OK]
Common Mistakes:
  • Expecting the box to be visible
  • Confusing with display:none which removes space
  • Thinking text remains visible
4. You wrote this CSS but the element still shows on the page:
.hidden-box { visibility = hidden; }

What is the error?
medium
A. The syntax uses '=' instead of ':'.
B. The property name should be 'visible' not 'visibility'.
C. The class selector should start with '#', not '.'.
D. The value 'hidden' is invalid for visibility.

Solution

  1. Step 1: Check CSS property syntax

    CSS uses a colon : to assign values, not an equals sign =.
  2. Step 2: Identify the syntax error

    The code uses visibility = hidden; which is invalid syntax and ignored by browsers.
  3. Final Answer:

    The syntax uses '=' instead of ':'. -> Option A
  4. Quick Check:

    Use colon for CSS property assignment [OK]
Hint: CSS uses colon, not equals, for properties [OK]
Common Mistakes:
  • Using '=' instead of ':' in CSS
  • Confusing class selector '.' with id selector '#'
  • Assuming 'hidden' is invalid value
5. You want to hide a button but keep the page layout stable so other elements don't move. Which CSS property and value should you use?
hard
A. display: none;
B. position: absolute; left: -9999px;
C. visibility: hidden;
D. opacity: 0;

Solution

  1. Step 1: Understand layout impact of hiding methods

    display: none; removes element and space, opacity: 0; hides visually but keeps clickable, position: absolute; left: -9999px; moves element off screen.
  2. Step 2: Choose method that hides but keeps space

    visibility: hidden; hides element but keeps its space, keeping layout stable.
  3. Final Answer:

    visibility: hidden; -> Option C
  4. Quick Check:

    visibility: hidden hides but keeps space [OK]
Hint: Use visibility hidden to keep space but hide element [OK]
Common Mistakes:
  • Using display:none which removes space
  • Using opacity:0 but element remains interactive
  • Moving element off screen breaks accessibility