Web Awesome (ViUR)

Font Awesome
Try SSR Server-side rendering (SSR) generates component HTML on the server before the page loads, improving SEO and initial load time. Use the switch to see Web Awesome components render with and without SSR.
Search this website ⌘KCtrl+K Light Dark System Docs Select Color Scheme Default Awesome Shoelace Active Brutalist Glossy Matter Mellow Playful Premium Tailspin Docs Select Theme View Project on GitHub Star Project on GitHub
Start Components Docs Help
Web Awesome Font Awesome Build Awesome
Search this site… /
Try SSR Server-side rendering (SSR) generates component HTML on the server before the page loads, improving SEO and initial load time. Use the switch to see Web Awesome components render with and without SSR.
Light Dark System Docs Select Color Scheme Default Awesome Shoelace Active Brutalist Glossy Matter Mellow Playful Premium Tailspin Docs Select Theme

Getting Started

  • Installation
  • Usage
  • Forms
  • Localization
  • Frameworks
  • Using with AI
  • Figma Design Kit ProThis requires access to Web Awesome Pro
  • Server Rendering

Resources

  • Accessibility
  • Browser Support
  • Contributing
  • Patterns ProPatterns require access to Web Awesome Pro
  • Migrating from Shoelace
  • Visual Tests
  • Changelog
  • Help & Support

Theming & Utilities

  • Overview
  • Built-in Themes
  • Color Palettes
  • Design Tokens
  • Customizing & Theming
  • CSS Utilities

ViUR Components

  • Alert
  • Combobox
  • Pagination
  • Table Wrapper

Actions

  • Button
  • Button Group
  • Copy Button
  • Dropdown
    • Dropdown Item

Forms

  • Checkbox
  • Checkbox Group
  • Color Picker
  • Input
  • Known Date
  • Number Input
  • Radio Group
    • Radio
  • Rating
  • Select
    • Option
  • Slider
  • Switch
  • Textarea
  • Time Input
  • Data Grid Planned A Web Awesome Kickstarter stretch goal!

Layout

  • Accordion
    • Accordion Item
  • Card
  • Details
  • Dialog
  • Divider
  • Drawer
  • Page
  • Scroller
  • Split Panel

Navigation

  • Breadcrumb
    • Breadcrumb Item
  • Tab Group
    • Tab
    • Tab Panel
  • Tree
    • Tree Item

Feedback

  • Badge
  • Callout
  • Progress Bar
  • Progress Ring
  • Skeleton
  • Spinner
  • Tag
  • Tooltip

Media

  • Animated Image
  • Avatar
  • Carousel
    • Carousel Item
  • Comparison
  • Icon
  • Markdown
  • QR Code
  • Zoomable Frame

Data Viz

  • Advanced Usage

Helpers

  • Animation
  • Format Bytes
  • Format Date
  • Format Number
  • Include
  • Intersection Observer
  • Mutation Observer
  • Popover
  • Popup
  • Random Content
  • Relative Time
  • Resize Observer

Random Content

  • Examples
  • Providing Content
  • Setting the Number of Items
  • Changing the Mode
  • Animating New Content
  • Autoplay
  • Styling the Container
  • Reacting to Changes
  • Server-Side Rendering
  • Using a Framework
  • Importing
  • Slots
  • Attributes & Properties
  • Methods
  • Events
  • CSS Custom Properties
On This Page...
  • Examples
  • Providing Content
  • Setting the Number of Items
  • Changing the Mode
  • Animating New Content
  • Autoplay
  • Styling the Container
  • Reacting to Changes
  • Server-Side Rendering
  • Using a Framework
  • Importing
  • Slots
  • Attributes & Properties
  • Methods
  • Events
  • CSS Custom Properties

Random Content

<wa-random-content>
Experimental Helpers Since 3.9

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>
  <wa-random-content id="rc-overview">
    <wa-callout variant="brand">
      <wa-icon slot="icon" name="paperclip-vertical"></wa-icon>
      <strong>It looks like you're writing a letter!</strong><br />
      Want a hand with the formatting?
    </wa-callout>
    <wa-callout variant="brand">
      <wa-icon slot="icon" name="paperclip-vertical"></wa-icon>
      <strong>It looks like you're building a web app!</strong><br />
      I can recommend a few components.
    </wa-callout>
    <wa-callout variant="brand">
      <wa-icon slot="icon" name="paperclip-vertical"></wa-icon>
      <strong>It looks like you're stuck.</strong><br />
      Have you tried turning it off and on again?
    </wa-callout>
    <wa-callout variant="brand">
      <wa-icon slot="icon" name="paperclip-vertical"></wa-icon>
      <strong>It looks like you're shipping on a Friday.</strong><br />
      Bold move. I respect it.
    </wa-callout>
  </wa-random-content>

  <wa-divider></wa-divider>

  <wa-button appearance="filled" onclick="document.getElementById('rc-overview').randomize()">Shuffle</wa-button>
</div>

Examples

Link to This Section

Providing Content

Link to This Section

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 components Even rich cards with their own content.
Shuffle
<div>
  <div class="wa-cluster wa-align-items-center" style="min-height: 5rem">
    <wa-random-content id="rc-providing">
      <p>Plain text works fine.</p>
      <wa-badge variant="brand">So do components</wa-badge>
      <wa-card>Even rich cards with their own content.</wa-card>
    </wa-random-content>
  </div>

  <wa-divider></wa-divider>

  <wa-button appearance="filled" onclick="document.getElementById('rc-providing').randomize()">Shuffle</wa-button>
</div>

Setting the Number of Items

Link to This Section

Set items to show more than one child at a time. The value is clamped to the number of available children.

New Sale Low stock Popular Last chance
1 2 3 4 Shuffle
<div class="rc-items-demo">
  <wa-random-content id="rc-items" items="2">
    <wa-badge variant="brand">New</wa-badge>
    <wa-badge variant="success">Sale</wa-badge>
    <wa-badge variant="warning">Low stock</wa-badge>
    <wa-badge variant="neutral">Popular</wa-badge>
    <wa-badge variant="danger">Last chance</wa-badge>
  </wa-random-content>

  <wa-divider></wa-divider>

  <div class="wa-cluster" style="align-items: flex-end">
    <wa-select id="rc-items-count" label="Items" value="2" style="width: 8rem">
      <wa-option value="1">1</wa-option>
      <wa-option value="2">2</wa-option>
      <wa-option value="3">3</wa-option>
      <wa-option value="4">4</wa-option>
    </wa-select>
    <wa-button appearance="filled" onclick="document.getElementById('rc-items').randomize()">Shuffle</wa-button>
  </div>
</div>

<script>
  document.getElementById('rc-items-count').addEventListener('change', event => {
    document.getElementById('rc-items').items = Number(event.target.value);
  });
</script>

Changing the Mode

Link to This Section

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
unique default 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). Stepping through content in order.
A B C D
unique random sequence Shuffle
Recent picks:
<div class="rc-modes-demo">
  <wa-random-content id="rc-modes" mode="unique">
    <wa-tag variant="brand">A</wa-tag>
    <wa-tag variant="success">B</wa-tag>
    <wa-tag variant="warning">C</wa-tag>
    <wa-tag variant="danger">D</wa-tag>
  </wa-random-content>

  <wa-divider></wa-divider>

  <div class="wa-cluster" style="align-items: flex-end">
    <wa-select id="rc-modes-mode" label="Mode" value="unique" style="width: 10rem">
      <wa-option value="unique">unique</wa-option>
      <wa-option value="random">random</wa-option>
      <wa-option value="sequence">sequence</wa-option>
    </wa-select>
    <wa-button appearance="filled" onclick="document.getElementById('rc-modes').randomize()">Shuffle</wa-button>
  </div>

  <small style="display: block; margin-block-start: var(--wa-space-s)">
    Recent picks: <span id="rc-modes-history"></span>
  </small>
</div>

<script>
  const rcModes = document.getElementById('rc-modes');
  const rcModesHistory = document.getElementById('rc-modes-history');

  document.getElementById('rc-modes-mode').addEventListener('change', event => {
    rcModes.mode = event.target.value;
  });

  rcModes.addEventListener('wa-content-change', event => {
    const labels = event.detail.items.map(item => item.textContent.trim()).join('');
    const picks = (rcModesHistory.textContent + ' ' + labels).trim().split(/\s+/).slice(-16);
    rcModesHistory.textContent = picks.join(' ');
  });
</script>

Animating New Content

Link to This Section

Use the animation attribute to play an entrance transition when new content is shown.

Good morning!

Welcome back.

What are you building today?

none fade fade-up fade-down fade-left fade-right Next
<div class="rc-animation-demo">
  <wa-random-content id="rc-animation" animation="fade-up">
    <p>Good morning!</p>
    <p>Welcome back.</p>
    <p>What are you building today?</p>
  </wa-random-content>

  <wa-divider></wa-divider>

  <div class="wa-cluster" style="align-items: flex-end">
    <wa-select id="rc-animation-select" label="Animation" value="fade-up" style="width: 10rem">
      <wa-option value="none">none</wa-option>
      <wa-option value="fade">fade</wa-option>
      <wa-option value="fade-up">fade-up</wa-option>
      <wa-option value="fade-down">fade-down</wa-option>
      <wa-option value="fade-left">fade-left</wa-option>
      <wa-option value="fade-right">fade-right</wa-option>
    </wa-select>
    <wa-button appearance="filled" onclick="document.getElementById('rc-animation').randomize()">Next</wa-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

Link to This Section

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 <wa-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
<div class="rc-autoplay-demo">
  <dl>
    <dt>Did you know?</dt>
    <wa-random-content id="rc-autoplay" mode="unique" animation="fade-up" autoplay autoplay-interval="3000">
      <dd><wa-icon name="octopus"></wa-icon> Octopuses have three hearts.</dd>
      <dd><wa-icon name="bee"></wa-icon> Honey never spoils.</dd>
      <dd><wa-icon name="feather"></wa-icon> A group of flamingos is called a flamboyance.</dd>
      <dd><wa-icon name="banana"></wa-icon> Bananas are botanically berries.</dd>
      <dd><wa-icon name="cat"></wa-icon> Cheetahs meow rather than roar.</dd>
    </wa-random-content>
  </dl>

  <wa-divider></wa-divider>

  <wa-button id="rc-autoplay-toggle" appearance="filled">Pause</wa-button>
</div>

<style>
  .rc-autoplay-demo dl {
    margin: 0;
  }
  .rc-autoplay-demo dt {
    font-weight: var(--wa-font-weight-semibold);
    margin-block-end: var(--wa-space-2xs);
  }
  .rc-autoplay-demo dd {
    margin-inline-start: 0;
  }
  .rc-autoplay-demo dd wa-icon {
    margin-inline-end: var(--wa-space-2xs);
    color: var(--wa-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

Link to This Section

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.

Shuffle
<div>
  <wa-random-content id="rc-layout" items="3" style="display: flex; gap: var(--wa-space-m); flex-wrap: wrap">
    <wa-avatar label="Jordan Hayes" initials="JH"></wa-avatar>
    <wa-avatar label="Mara Goldberg" initials="MG"></wa-avatar>
    <wa-avatar label="Beck Watts" initials="BW"></wa-avatar>
    <wa-avatar label="Avi Lin" initials="AL"></wa-avatar>
    <wa-avatar label="Rae Park" initials="RP"></wa-avatar>
    <wa-avatar label="Sam Cho" initials="SC"></wa-avatar>
  </wa-random-content>

  <wa-divider></wa-divider>

  <wa-button appearance="filled" onclick="document.getElementById('rc-layout').randomize()">Shuffle</wa-button>
</div>

Because the host is transparent, the component also works inline within a sentence.

Have a wonderful fantastic marvelous splendid day!

Shuffle
<div>
  <p>
    Have a
    <wa-random-content id="rc-inline">
      <span>wonderful</span>
      <span>fantastic</span>
      <span>marvelous</span>
      <span>splendid</span>
    </wa-random-content>
    day!
  </p>

  <wa-divider></wa-divider>

  <wa-button appearance="filled" onclick="document.getElementById('rc-inline').randomize()">Shuffle</wa-button>
</div>

Unselected children are hidden with the hidden attribute, so you can target whatever is currently shown with :not([hidden]):

wa-random-content > :not([hidden]) {
  outline: var(--wa-border-width-s) solid var(--wa-color-brand-fill-loud);
}

Reacting to Changes

Link to This Section

The component emits a wa-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.

const rc = document.querySelector('wa-random-content');

rc.addEventListener('wa-content-change', event => {
  console.log('Now showing:', event.detail.items);
});

Server-Side Rendering

Link to This Section

Until the component upgrades on the client, every child is visible, which can flash on first paint. Add the wa-cloak class to hide content until Web Awesome 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

Link to This Section

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 wa-content-change.

Importing

Link to This Section

If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.

CDN npm Self-Hosted React

Import this component directly from the CDN:

import 'https://ka-f.webawesome.com/webawesome@0.17.0/components/random-content/random-content.js';

After installing Web Awesome via npm, import this component:

import '@awesome.me/webawesome/dist/components/random-content/random-content.js';

If you're self-hosting Web Awesome, import this component from your server:

import './webawesome/dist/components/random-content/random-content.js';

To import this component for React 18 or below, use the following code:

import WaRandomContent from '@awesome.me/webawesome/dist/react/random-content/index.js';

Slots

Link to This Section

Learn more about using slots.

Name Description
(default) The pool of children to choose from. Only direct element children are eligible; unselected children are hidden with the hidden attribute.

Attributes & Properties

Link to This Section

Learn more about attributes and properties.

Name Description Reflects
animation
animation
Entrance animation for newly shown children.
Type 'none' | 'fade' | 'fade-up' | 'fade-down' | 'fade-left' | 'fade-right'
Default 'none'
autoplay
autoplay
Rotate the content automatically. Set the cadence with autoplay-interval.
Type boolean
Default false
autoplayInterval
autoplay-interval
Autoplay cadence in milliseconds.
Type number
Default 3000
items
items
Number of children to show simultaneously. Clamped to [1, childCount].
Type number
Default 1
mode
mode
Selection strategy: unique (default), random, or sequence.
Type 'random' | 'unique' | 'sequence'
Default 'unique'

Methods

Link to This Section

Learn more about methods.

Name Description Arguments
randomize() Selects a new set of children using the current mode. Returns the elements now shown.

Events

Link to This Section

Learn more about events.

Name Description
wa-content-change Emitted whenever the displayed selection changes, including on first render, on randomize(), and on each autoplay tick.

CSS Custom Properties

Link to This Section

Learn more about CSS custom properties.

Name Description
--animation-duration
Duration of the entrance animation. Default is 300ms.
--animation-easing
Easing function for the entrance animation. Default is ease.
--animation-translate
Translation distance for directional animations (fade-up, fade-down, fade-left, fade-right). Default is 0.5em.
Need a hand? Report a bug Ask for help
Go Make Something Awesome
Version 0.17.0 © Fonticons, Inc.
  • Terms
  • Privacy
  • Refunds
  • Core License
  • Pro License

Quick Links

  • Components
  • CSS Utilities
  • Theming
  • Using with AI
  • Changelog
  • Help & Support

Recent Searches

    D'oh! No results for “”

    Suggest on GitHub Ask on Discord
    Navigate Select
    Close Esc