CSSScript.com

show-when Web Component Demos

Download Back To CSSScript.Com

A Web Component that shows or hides content based on URL params, hash, media queries, CSS support, or network state.

CSS Feature Support

has-support

This item starts hidden and appears when the browser supports container query names.

Viewport Orientation

has-media

Resize the window or rotate a device to switch between the two matching media queries.

Print and Motion Preferences

media variants

One element appears for print output. The second uses hide-when to disappear when reduced motion is preferred.

URL Parameter: Show

has-param

This example is visible by default before registration, then follows the edit query parameter.

The edit parameter is active.

URL Parameter: Hide

hide-when

This inverse example hides when the readonly query parameter is present.

The page is not in readonly mode.

Hash Change

has-hash

Hash matching updates immediately when the address bar fragment changes.

The current hash is #edit. The current hash is #read.

Network Status

has-network

Browser online and offline events toggle these two states.

The browser reports an online connection. The browser reports an offline connection.

Language Match

has-lang

This expanded demo checks the browser language list exposed by navigator.languages.

Dynamic Element Creation

created with JavaScript

The button appends a hidden show-when element and lets the component reveal it after the support check passes.

No dynamic elements have been created yet.