Skip to content

Timed Content

<quiet-timed-content> stable since 1.0

Timed content shows certain content based on the current date and time.

It's national Cat Day! 😸

This will show before National Cat Day (October 29)

This will show after National Cat Day (October 29)

<quiet-timed-content id="timed__overview">
  <p>It's national Cat Day! 😸</p>

  <p slot="before">This will show <em>before</em> National Cat Day (October 29)</p>
  <p slot="after">This will show <em>after</em> National Cat Day (October 29)</p>
</quiet-timed-content>

<script>
  // Obtain a reference
  const timedContent = document.getElementById('timed__overview');

  // Calculate dates for this year's National Cat Day
  const currentYear = new Date().getFullYear();
  const catDayStart = new Date(currentYear, 9, 29).setHours(0, 0, 0, 0); // October = 9
  const catDayEnd = new Date(currentYear, 9, 29).setHours(23, 59, 59, 999);

  // Set the start and end dates
  timedContent.startDate = new Date(catDayStart);
  timedContent.endDate = new Date(catDayEnd);
</script>

<style>
  #timed__overview p {
    margin-block-end: 0;
  }
</style>

If you pass a string to the start-date or end-date attributes, always use the ISO 8601 format . Otherwise, ambiguous dates such as 01/02/2000 can be parsed as January 2 or February 1 depending on the client's locale.

Examples Jump to heading

Providing dates Jump to heading

The most common use case is showing content during a specific period of time. Use the start-date and end-date attributes to tell the component when to show the content.

<quiet-timed-content 
  start-date="2025-12-01T00:00:00.000Z" 
  end-date="2025-12-31T23:59:59.999Z"
>
  <p>Holiday Sale! All catnip toys are 50% off!</p>
</quiet-timed-content>

You can also pass a Date object to the startDate and endDate properties.

<quiet-timed-content>
  <p>Holiday Sale! All catnip toys are 50% off!</p>
</quiet-timed-content>

<script>
  const timedContent = document.querySelector('quiet-timed-content');

  timedContent.startDate = new Date('2025-12-01T00:00:00.000Z');
  timedContent.endDate = new Date('2025-12-31T23:59:59.999Z');
</script>

If you specify a date without a timezone, e.g. 2025-12-01, it will be interpreted in the user's local timezone. To ensure consistent behavior across timezones, include explicit timezone information in your dates, e.g. 2025-12-01T00:00:00Z for UTC, or be aware that users in different timezones may see content transitions at different times.

Before and after slots Jump to heading

Use the before and after slots to show different content outside of the specified date range. The before slot shows when the current date is before the start date, and the after slot shows when the current date is after the end date.

<quiet-timed-content 
  start-date="2025-08-15" 
  end-date="2025-08-17"
>
  <div>
    <h3>Sale</h3>
    <p>25% off all premium cat food!</p>
  </div>
  
  <div slot="before">
    <h3>Sale Coming Soon</h3>
    <p>Cat food sale begins August 15th!</p>
  </div>
  
  <div slot="after">
    <h3>Sale Ended</h3>
    <p>Thanks for treating your cats during our promotion!</p>
  </div>
</quiet-timed-content>

Start date only Jump to heading

When only the start-date is provided, content will show from that date forward. This is useful for feature launches or permanent changes that take effect on a specific date.

<quiet-timed-content start-date="2025-06-15">
  <p>New feature is now available!</p>
  
  <div slot="before">
    <p>New feature coming June 15th!</p>
  </div>
</quiet-timed-content>

End date only Jump to heading

When only the end-date is provided, content will show up until that date. This is useful for limited-time offers or deprecation notices.

<quiet-timed-content end-date="2025-03-31">
  <p>The legacy API is available until March 31</p>
  
  <div slot="after">
    <p>The legacy API has been discontinued</p>
  </div>
</quiet-timed-content>

Enabling live updates Jump to heading

By default, the component will render the content based on the time the page was first loaded. To update the component dynamically as time passes, add the live attribute. For performance, live updates only occur every 60 seconds.

<quiet-timed-content 
 start-date="2025-05-31T14:30:00.000Z" 
 end-date="2025-05-31T14:35:00.000Z"
 live
>
  <p>Flash sale happening now! âš¡</p>
  <p slot="before">Flash sale starts at 2:30 PM UTC</p>
  <p slot="after">Flash sale ended at 2:35 PM UTC</p>
</quiet-timed-content>

API Jump to heading

Importing Jump to heading

The autoloader is the recommended way to import components but, if you prefer to do it manually, the following code snippets will be helpful.

CDN npm

To manually import <quiet-timed-content> from the CDN, use the following code.

import 'https://cdn.jsdelivr.net/npm/@quietui/quiet-browser@1.0.0/dist/components/timed-content/timed-content.js';

To manually import <quiet-timed-content> from npm, use the following code.

import '@quietui/quiet/dist/components/timed-content/timed-content.js';

Slots Jump to heading

Timed Content supports the following slots. Learn more about using slots

Name Description
(default) The default slot.
before Optional content that shows before the specified date/time.
after Optional content that shows after the specified date/time.

Properties Jump to heading

Timed Content has the following properties that can be set with corresponding attributes. In many cases, the attribute's name is the same as the property's name. If an attribute is different, it will be displayed after the property. Learn more about attributes and properties

Property / Attribute Description Reflects Type Default
startDate
start-date
The date to start showing the content. string
Date
''
endDate
end-date
The date to stop showing the content. string
Date
''
live When set, the content will update as the time changes. boolean false
Search this website Toggle dark mode Get the code on GitHub Follow @quietui.org on Bluesky Follow @quiet_ui on X

    No results found