Block Content Warning
A block-level content warning that overlays the entire content area. This page uses shared default wording; see Shared Labels to reuse a template across warnings.
Single Warning Type
Wrap the content and set type to name the
warning. Tab to its button, then press Enter or Space to
reveal it. Without JavaScript, authored
hidden keeps this content hidden.
Code
<content-warning type="violence" hidden>
<p>This content contains graphic violence.</p>
<p>The scene describes a battle and its aftermath.</p>
</content-warning>
Live example
This content contains graphic violence.
The scene describes a battle and its aftermath.
Multiple Warning Types
Use space-separated types for multiple warning categories.
Code
<content-warning type="violence spoilers nsfw" hidden>
<p>Contains violence, spoilers, and mature content.</p>
<p>The protagonist dies in the final battle, sacrificing themselves to save their friends.</p>
</content-warning>
Live example
Contains violence, spoilers, and mature content.
The protagonist dies in the final battle, sacrificing themselves to save their friends.
Inline Content Warning
An inline content warning that works within text flow.
Inline Usage
Add inline to place the button within a
sentence. This example omits hidden, so
“episode 5” remains visible without JavaScript. Add
hidden if that fallback would expose
content you need to conceal.
Code
<p>
The character dies in
<content-warning type="spoilers" inline>
episode 5
</content-warning>.
</p>
Live example
The character dies in
Multiple Inline Warnings
You can have multiple inline warnings in one sentence.
Code
<p>
<content-warning type="spoilers" inline>Jon</content-warning>
meets <content-warning type="spoilers" inline>Daenerys</content-warning>
in season 7.
</p>
Live example
Content Hiding Modes
The component offers two modes for hiding content, each with different trade-offs.
Default Mode (Dark Overlay)
After render, the component applies
hidden and inert to its
content wrapper. inert prevents interaction
and excludes the content from the accessibility tree.
Block content keeps its layout beneath a dark,
translucent overlay because the wrapper’s CSS overrides
native hidden display. Authored
hidden hides the whole element before
upgrade; Reader Mode behavior still varies across tools.
Code
<content-warning type="sensitive content" hidden>
<p>The overlay covers this content until you reveal it.</p>
</content-warning>
Live example
The overlay covers this content until you reveal it.
Blur Mode (Visual Only)
Content is visually obscured with CSS blur but remains
in the DOM. The wrapper uses
aria-hidden="true" to exclude it from the
accessibility tree, not inert. Avoid
focusable descendants in blur examples. Bare text nodes
aren’t blurred; inline warnings hide their wrapper
instead.
Not guaranteed to be hidden from Reader
Mode.
Code
<content-warning type="spoilers" blur hidden>
<p>This content is blurred visually and may be extracted by Reader Mode.</p>
</content-warning>
Live example
This content is blurred visually and may be extracted by Reader Mode.
Custom Blur Amount
Adjust the blur intensity using the
--content-warning-blur-amount CSS custom
property.
Code
<style>
.light-blur {
--content-warning-blur-amount: 5px;
}
.heavy-blur {
--content-warning-blur-amount: 20px;
}
</style>
<content-warning type="spoilers" blur class="light-blur" hidden>
<p>Lightly blurred content (5px blur)</p>
<p>Text is more readable through the blur.</p>
</content-warning>
<br><br>
<content-warning type="spoilers" blur class="heavy-blur" hidden>
<p>Heavily blurred content (20px blur)</p>
<p>Text is much harder to read through the blur.</p>
</content-warning>
Live example
Lightly blurred content (5px blur)
Text is more readable through the blur.
Heavily blurred content (20px blur)
Text is much harder to read through the blur.
Comparison
Compare the dark overlay with visual blur. Both block warnings keep the paragraphs’ layout before reveal; blur lets their shapes show around the button.
Code
<content-warning type="test" hidden>
<p>Content covered by the overlay.</p>
</content-warning>
<content-warning type="test" blur hidden>
<p>Visually blurred content.</p>
</content-warning>
Live example
Default (Overlay)
Content covered by the overlay.
Blur Mode
Visually blurred content.
Custom Styling
Customize the appearance using CSS Shadow Parts.
Custom Colors
Set both button colors to keep the label on an opaque backplate. The overlay can have a separate background; keep the focus outline visible.
Code
<style>
.custom-warning::part(overlay) {
background: rgba(139, 0, 0, 0.95);
}
.custom-warning::part(button) {
color: #fff;
border: 3px solid #ff6b6b;
padding: 2rem;
background: #260000;
border-radius: 0.5rem;
}
</style>
<content-warning type="horror" class="custom-warning" hidden>
<p>This is scary content with custom styling!</p>
<p>The dark red background and red border make it stand out.</p>
</content-warning>
Live example
This is scary content with custom styling!
The dark red background and red border make it stand out.
Styled Button Text
Style the button text and appearance.
Code
<style>
.styled-parts::part(button) {
text-transform: uppercase;
letter-spacing: 0.15em;
font-weight: 900;
background: #333;
color: #fff;
border-radius: 0.5rem;
}
</style>
<content-warning type="mature" class="styled-parts" hidden>
<p>This content is for mature audiences.</p>
</content-warning>
Live example
This content is for mature audiences.
Event Handling
Listen for the revealed event to track user interactions.
Tracking Reveals
Activate the warning to update the status below it. The
event fires once per reveal and supplies the authored
type.
Code
<content-warning type="spoilers" id="tracked" hidden>
<p>This is the secret content that was revealed!</p>
</content-warning>
<p id="status">Status: Hidden</p>
<script>
document.getElementById('tracked')
.addEventListener('content-warning:revealed', (e) => {
document.getElementById('status').textContent =
`Status: Revealed (${e.detail.type})`;
});
</script>
Live example
This is the secret content that was revealed!
Status: Hidden
Labels and Translations
Write a complete button label with
reveal-label. Its {type} token
inserts the warning type wherever your sentence needs it.
The visible text also names the button. Translate
type too, and set lang on
translated content. See the
label reference
for shared defaults, precedence, and recovery.
Use Your Application’s Vocabulary
Write the whole phrase to fit a review workflow, including its punctuation. This changes the label, not the reveal behavior.
Code
<content-warning
type="plot details"
reveal-label="Review note: {type}. Show details"
hidden>
<p>The review discusses the ending.</p>
</content-warning>
Live example
The review discusses the ending.
Spanish Translation
The warning and image alternative inherit Spanish from their containing element. This photo is a placeholder, not a graphic image.
Code
<content-warning
type="violencia gore"
reveal-label="Advertencia: {type}. Mostrar contenido"
hidden
>
<img src="https://picsum.photos/600/400?random=5"
alt="Fotografía de ejemplo" style="display: block; max-width: 100%">
</content-warning>
Live example
French Translation
The warning inherits French from its containing element. Style the complete label while the button keeps an opaque background.
Code
<style>
.french-warning::part(button) {
background: #111;
color: #fff;
}
.french-warning::part(label) {
font-weight: bold;
color: #ffeb3b;
}
</style>
<content-warning
type="contenu sensible"
reveal-label="Afficher le contenu : {type}"
class="french-warning"
hidden
>
<p>Ce contenu pourrait être considéré comme sensible par certains utilisateurs. Veuillez faire preuve de discrétion.</p>
</content-warning>
Live example
Ce contenu pourrait être considéré comme sensible par certains utilisateurs. Veuillez faire preuve de discrétion.
A Shorter Label
Leave extra instructions out of your template when a short label says enough.
Code
<content-warning
type="graphic content"
reveal-label="Reveal {type}"
hidden
>
<p>This warning uses a short reveal label.</p>
</content-warning>
Live example
This warning uses a short reveal label.
API Reference
For complete documentation of attributes, events, CSS custom properties, and browser support, see the README.