Selects one or more child elements at random and displays them, hiding the rest.
Randomly picks and displays one or more of its slotted children, hiding the rest. Use it to rotate testimonials, surface featured content, show a tip of the day, or add variety to an otherwise static page.
It looks like you're writing a letter!
Want a hand with the formatting?
It looks like you're building a web app!
I can recommend a few components.
It looks like you're stuck.
Have you tried turning it off and on again?
It looks like you're shipping on a Friday.
Bold move. I respect it.
Shuffle
<div><cs-random-contentid="rc-overview"><cs-calloutvariant="brand"><cs-iconslot="icon"name="attach_file"></cs-icon><strong>It looks like you're writing a letter!</strong><br/>
Want a hand with the formatting?
</cs-callout><cs-calloutvariant="brand"><cs-iconslot="icon"name="attach_file"></cs-icon><strong>It looks like you're building a web app!</strong><br/>
I can recommend a few components.
</cs-callout><cs-calloutvariant="brand"><cs-iconslot="icon"name="attach_file"></cs-icon><strong>It looks like you're stuck.</strong><br/>
Have you tried turning it off and on again?
</cs-callout><cs-calloutvariant="brand"><cs-iconslot="icon"name="attach_file"></cs-icon><strong>It looks like you're shipping on a Friday.</strong><br/>
Bold move. I respect it.
</cs-callout></cs-random-content><cs-divider></cs-divider><cs-buttonappearance="filled"onclick="document.getElementById('rc-overview').randomize()">Shuffle</cs-button></div>
Examples
Providing Content
Slot virtually any HTML — text, badges, cards, images, or other components — as long as each item is a direct child. Nested elements and bare text nodes are ignored. The host renders display: contents, so it stays invisible to layout.
Plain text works fine.
So do componentsEven rich cards with their own content.
Shuffle
<div><divclass="cs-cluster cs-align-items-center"style="min-block-size:var(--cs-space-5xl)"><cs-random-contentid="rc-providing"><p>Plain text works fine.</p><cs-badgevariant="brand">So do components</cs-badge><cs-card>Even rich cards with their own content.</cs-card></cs-random-content></div><cs-divider></cs-divider><cs-buttonappearance="filled"onclick="document.getElementById('rc-providing').randomize()">Shuffle</cs-button></div>
Number of Items
Set items to show more than one child at a time. The value is clamped to the number of available children.
The mode attribute controls how the next selection is chosen. Switch modes and shuffle a few times to feel the difference — the recent picks are listed underneath.
Mode
Behavior
Best for
uniquedefault
Never repeats the previous selection.
Tip rotators and timed loops.
random
Picks at complete random, so the same item can appear twice in a row.
A one-time shuffle on load.
sequence
Steps through children in DOM order, wrapping at the end (advances by items).
Use the animation attribute to play an entrance transition when new content is shown.
Good morning!
Welcome back.
What are you building today?
nonefadefade-upfade-downfade-leftfade-rightNext
<divclass="rc-animation-demo"><cs-random-contentid="rc-animation"animation="fade-up"><p>Good morning!</p><p>Welcome back.</p><p>What are you building today?</p></cs-random-content><cs-divider></cs-divider><divclass="cs-cluster cs-align-items-end"><cs-selectid="rc-animation-select"label="Animation"value="fade-up"style="width: 10rem"><cs-optionvalue="none">none</cs-option><cs-optionvalue="fade">fade</cs-option><cs-optionvalue="fade-up">fade-up</cs-option><cs-optionvalue="fade-down">fade-down</cs-option><cs-optionvalue="fade-left">fade-left</cs-option><cs-optionvalue="fade-right">fade-right</cs-option></cs-select><cs-buttonappearance="filled"onclick="document.getElementById('rc-animation').randomize()">Next</cs-button></div></div><script>
document.getElementById('rc-animation-select').addEventListener('change',event=>{
document.getElementById('rc-animation').animation = event.target.value;});</script>
Directional animations (fade-up, fade-down, fade-left, fade-right) rely on CSS transform, which has no effect on display: inline elements. The component promotes inline children to inline-block while a directional animation plays, so they work inline without extra markup.
Tune the duration, easing, and travel distance with the --animation-duration, --animation-easing, and --animation-translate custom properties. Animations are skipped automatically when the user prefers reduced motion.
Autoplay
Add the autoplay attribute to rotate content on a timer, and set the cadence with autoplay-interval (milliseconds). It pauses while the pointer is over the component or focus is inside it, and resumes when the user moves away. It respects reduced motion, too: content still rotates, but the entrance animation is skipped. Each new item is announced to screen readers using its text, so give icon-only content an accessible label (for example <cs-icon label="…">).
Did you know?
Octopuses have three hearts.
Honey never spoils.
A group of flamingos is called a flamboyance.
Bananas are botanically berries.
Cheetahs meow rather than roar.
Pause
<divclass="rc-autoplay-demo"><dl><dt>Did you know?</dt><cs-random-contentid="rc-autoplay"mode="unique"animation="fade-up"autoplayautoplay-interval="3000"><dd><cs-iconname="pets"variant="fill"></cs-icon> Octopuses have three hearts.</dd><dd><cs-iconname="emoji_nature"></cs-icon> Honey never spoils.</dd><dd><cs-iconname="eco"></cs-icon> A group of flamingos is called a flamboyance.</dd><dd><cs-iconname="nutrition"></cs-icon> Bananas are botanically berries.</dd><dd><cs-iconname="pets"></cs-icon> Cheetahs meow rather than roar.</dd></cs-random-content></dl><cs-divider></cs-divider><cs-buttonid="rc-autoplay-toggle"appearance="filled">Pause</cs-button></div><style>.rc-autoplay-demo dl{margin: 0;}.rc-autoplay-demo dt{font-weight:var(--cs-font-weight-semibold);margin-block-end:var(--cs-space-2xs);}.rc-autoplay-demo dd{margin-inline-start: 0;}.rc-autoplay-demo dd cs-icon{margin-inline-end:var(--cs-space-2xs);color:var(--cs-color-brand-fill-loud);}</style><script>const rcAutoplay = document.getElementById('rc-autoplay');const rcAutoplayToggle = document.getElementById('rc-autoplay-toggle');
rcAutoplayToggle.addEventListener('click',()=>{
rcAutoplay.autoplay =!rcAutoplay.autoplay;
rcAutoplayToggle.textContent = rcAutoplay.autoplay ?'Pause':'Play';});</script>
If you turn on autoplay, give people a way to pause it.
The built-in hover and focus pausing doesn’t help someone using a keyboard when the rotating content isn’t focusable, so add a visible pause button like the one above.
Styling the Container
The host is display: contents by default, so it adds no box of its own. To lay several shown items out as a row or grid, give the host its own display — that overrides the transparent default. Here it shows three of six people at random in a flex row.
Because the host is transparent, the component also works inline within a sentence.
Have a
wonderfulfantasticmarveloussplendid
day!
Shuffle
<div><p>
Have a
<cs-random-contentid="rc-inline"><span>wonderful</span><span>fantastic</span><span>marvelous</span><span>splendid</span></cs-random-content>
day!
</p><cs-divider></cs-divider><cs-buttonappearance="filled"onclick="document.getElementById('rc-inline').randomize()">Shuffle</cs-button></div>
Unselected children are hidden with the hidden attribute, so you can target whatever is currently shown with :not([hidden]):
The component emits a cs-content-change event whenever the displayed selection changes — on first render, on randomize(), and on each autoplay tick. event.detail.items is the array of elements now shown.
Until the component upgrades on the client, every child is visible, which can flash on first paint. Add the cs-cloak class to hide content until Cornerstone is ready. Because the first selection is random, server- and client-rendered output can also differ; for a stable first paint, use mode="sequence", which always starts at the first child.
Using a Framework
The component selects from its slotted children by toggling the hidden attribute on them directly. Treat that content as static — if a framework owns and re-renders the children, its reconciliation can overwrite the hidden state. Render a fixed set of children, then drive the component imperatively: call randomize() through a ref and listen for cs-content-change.
API
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import
needed. To cherry-pick this component, use one of the following snippets.