HTML chapters

Chapter 7 of 17

Visibility and native disclosure

Try this in our HTML Compiler →

The idea

HTML cannot run an if statement. The hidden attribute removes ordinary content from display, while details and summary create a native disclosure a reader can open. Boolean attributes are true when present: hidden="false" still hides an element. Dynamic decisions require JavaScript or server rendering.

Worked example

<details>
  <summary>What should I practise?</summary>
  <p>Write the document structure from memory.</p>
</details>

What to check

The browser supplies the open and closed interaction. Keyboard users can focus and activate the summary without a custom click handler.

Practice task

Add a second disclosure with a different question and answer. Do not put interactive controls inside the summary.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on