Use CSS revert to Restore display
This educational demo shows why display: block is not always the right way to reveal hidden elements, and how display: revert restores the browser's natural display behavior.
1. Hide every list item after the third
The requirement starts with a small rule: show only the first three options by default.
Code:#setupList li:nth-child(n+4) {
display: none;
}
Result:
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
Options 4 and 5 exist in the HTML, but the CSS rule hides them.
2. Revealing list items with display: block removes markers
A common first attempt is to set the hidden list items to block. The items appear, but they are no longer rendered as list items.
#blockList li:nth-child(n+4) {
display: none;
}
const showBlockItems = () => {
document.querySelectorAll('#blockList li:nth-child(n+4)').forEach((li) => {
li.style.display = 'block';
});
};
Result:
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
3. Revealing list items with display: revert restores markers
The default computed display value of an <li> is list-item, not block. revert asks the browser to return to its built-in behavior.
#revertList li:nth-child(n+4) {
display: none;
}
const showRevertItems = () => {
document.querySelectorAll('#revertList li:nth-child(n+4)').forEach((li) => {
li.style.display = 'revert';
});
};
Result:
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
4. Compare different display values on list items
Try each value. list-item and revert keep bullet markers because the elements render as list items.
#compareList li:nth-child(n+4) {
display: none;
}
displayChoice.addEventListener('change', () => {
document.querySelectorAll('#compareList li:nth-child(n+4)').forEach((li) => {
li.style.display = displayChoice.value;
});
});
Result:
- Option 1
- Option 2
- Option 3
- Option 4
- Option 5
5. Use all: revert to restore native controls
The all property applies a keyword to every CSS property. Here, the second button and second progress bar return to the browser's native styling.
.pretty-button {
padding: 12px 18px;
border: 0;
border-radius: 8px;
background: linear-gradient(135deg, #2563eb, #0f766e);
color: white;
font-weight: 800;
}
.plain-button,
.native-progress {
all: revert;
}
Result:
Styled controls
Reverted controls
6. Show mixed elements with display: revert
For tabs, accordions, and shared components, revert lets each tag return to its own default display value.
.toggle-demo [data-panel] {
display: none;
}
togglePanelsButton.addEventListener('click', () => {
document.querySelectorAll('.toggle-demo [data-panel]').forEach((panel) => {
panel.style.display = panel.style.display === 'revert' ? 'none' : 'revert';
});
});
Result:
Paragraph panel: I return as a block paragraph.
| Tag | Default display |
|---|---|
| <table> | table |
7. Compare global CSS keywords
The other global keywords are useful too, but they do different things. This example applies each keyword to the target box's color.
keywordChoice.addEventListener('change', () => {
keywordTarget.style.color = keywordChoice.value;
keywordStatus.textContent = 'color: ' + keywordChoice.value;
});
Result:
| Keyword value | Practicality | Compatibility | Overall rating |
|---|---|---|---|
inherit |
A | A+ | A+ |
initial |
B- | B+ | B |
unset |
B- | B- | B- |
revert |
B | C | B- |