Create a simple countdown timer.
To apply this component, add the uk-countdown
attribute to a container element and define a date when the countdown should expire. Just add date: YYYY-MM-DDThh:mm:ssTZD
option to the attribute, using the ISO 8601 format, e.g. 2024-11-29T09:55:16+00:00
(UTC time).
Add the following classes to child elements to apply the necessary functionality and styling.
Class | Description |
---|---|
.uk-countdown-days |
Add this class to indicate the days to be counted down. |
.uk-countdown-hours |
Add this class to indicate the hours to be counted down. |
.uk-countdown-minutes |
Add this class to indicate the minutes to be counted down. |
.uk-countdown-seconds |
Add this class to indicate the seconds to be counted down. |
.uk-countdown-number |
This class adds the necessary style to a countdown number. |
<div uk-countdown="date: {%isodate%}">
<span class="uk-countdown-number uk-countdown-days"></span>
<span class="uk-countdown-number uk-countdown-hours"></span>
<span class="uk-countdown-number uk-countdown-minutes"></span>
<span class="uk-countdown-number uk-countdown-seconds"></span>
</div>
<div class="uk-grid-small uk-child-width-auto uk-margin" uk-grid uk-countdown="date: {%isodate%}">
<div>
<div class="uk-countdown-number uk-countdown-days"></div>
</div>
<div>
<div class="uk-countdown-number uk-countdown-hours"></div>
</div>
<div>
<div class="uk-countdown-number uk-countdown-minutes"></div>
</div>
<div>
<div class="uk-countdown-number uk-countdown-seconds"></div>
</div>
</div>
To insert a separator between each number, use the .uk-countdown-separator
class.
<div uk-countdown="date: {%isodate%}">
<span class="uk-countdown-number uk-countdown-days"></span>
<span class="uk-countdown-separator">:</span>
<span class="uk-countdown-number uk-countdown-hours"></span>
<span class="uk-countdown-separator">:</span>
<span class="uk-countdown-number uk-countdown-minutes"></span>
<span class="uk-countdown-separator">:</span>
<span class="uk-countdown-number uk-countdown-seconds"></span>
</div>
<div class="uk-grid-small uk-child-width-auto uk-margin" uk-grid uk-countdown="date: {%isodate%}">
<div>
<div class="uk-countdown-number uk-countdown-days"></div>
</div>
<div class="uk-countdown-separator">:</div>
<div>
<div class="uk-countdown-number uk-countdown-hours"></div>
</div>
<div class="uk-countdown-separator">:</div>
<div>
<div class="uk-countdown-number uk-countdown-minutes"></div>
</div>
<div class="uk-countdown-separator">:</div>
<div>
<div class="uk-countdown-number uk-countdown-seconds"></div>
</div>
</div>
To add a label to each number, use the .uk-countdown-label
class.
<div class="uk-countdown-label">Days</div>
<div class="uk-countdown-label">Hours</div>
<div class="uk-countdown-label">Minutes</div>
<div class="uk-countdown-label">Seconds</div>
<div class="uk-grid-small uk-child-width-auto" uk-grid uk-countdown="date: {%isodate%}">
<div>
<div class="uk-countdown-number uk-countdown-days"></div>
<div class="uk-countdown-label uk-margin-small uk-text-center uk-visible@s">Days</div>
</div>
<div class="uk-countdown-separator">:</div>
<div>
<div class="uk-countdown-number uk-countdown-hours"></div>
<div class="uk-countdown-label uk-margin-small uk-text-center uk-visible@s">Hours</div>
</div>
<div class="uk-countdown-separator">:</div>
<div>
<div class="uk-countdown-number uk-countdown-minutes"></div>
<div class="uk-countdown-label uk-margin-small uk-text-center uk-visible@s">Minutes</div>
</div>
<div class="uk-countdown-separator">:</div>
<div>
<div class="uk-countdown-number uk-countdown-seconds"></div>
<div class="uk-countdown-label uk-margin-small uk-text-center uk-visible@s">Seconds</div>
</div>
</div>
Any of these options can be applied to the component attribute. Separate multiple options with a semicolon. For more information, take a look at the chapter on component configuration.
Option | Value | Default | Description |
---|---|---|---|
date |
String | false |
Any string parsable by Date.parse . See Reference. |
Learn more about JavaScript components.
UIkit.countdown(element, options);
The following methods are available for the component:
UIkit.countdown(element).start();
Starts the countdown.
UIkit.countdown(element).stop();
Stops the countdown.
The Countdown component automatically sets the appropriate WAI-ARIA roles, states and properties.
timer
role.