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. {%isodate%} (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 neccessary style to a countdown number. |
<div uk-countdown="date: {%isodate%}">
<span class="uk-countdown-days uk-countdown-number"></span>
<span class="uk-countdown-hours uk-countdown-number"></span>
<span class="uk-countdown-minutes uk-countdown-number"></span>
<span class="uk-countdown-seconds uk-countdown-number"></span>
</div>
<div
class="uk-grid-small uk-margin uk-child-width-auto"
uk-grid
uk-countdown="date: 2024-08-12T07:22:24+00:00"
>
<div>
<div class="uk-countdown-days uk-countdown-number"></div>
</div>
<div>
<div class="uk-countdown-hours uk-countdown-number"></div>
</div>
<div>
<div class="uk-countdown-minutes uk-countdown-number"></div>
</div>
<div>
<div class="uk-countdown-seconds uk-countdown-number"></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-days uk-countdown-number"></span>
<span class="uk-countdown-separator">:</span>
<span class="uk-countdown-hours uk-countdown-number"></span>
<span class="uk-countdown-separator">:</span>
<span class="uk-countdown-minutes uk-countdown-number"></span>
<span class="uk-countdown-separator">:</span>
<span class="uk-countdown-seconds uk-countdown-number"></span>
</div>
<div
class="uk-grid-small uk-margin uk-child-width-auto"
uk-grid
uk-countdown="date: 2024-08-12T07:22:24+00:00"
>
<div>
<div class="uk-countdown-days uk-countdown-number"></div>
</div>
<div class="uk-countdown-separator">:</div>
<div>
<div class="uk-countdown-hours uk-countdown-number"></div>
</div>
<div class="uk-countdown-separator">:</div>
<div>
<div class="uk-countdown-minutes uk-countdown-number"></div>
</div>
<div class="uk-countdown-separator">:</div>
<div>
<div class="uk-countdown-seconds uk-countdown-number"></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: 2024-08-12T07:22:24+00:00"
>
<div>
<div class="uk-countdown-days uk-countdown-number"></div>
<div class="uk-visible@s uk-countdown-label uk-margin-small uk-text-center">
Days
</div>
</div>
<div class="uk-countdown-separator">:</div>
<div>
<div class="uk-countdown-hours uk-countdown-number"></div>
<div class="uk-visible@s uk-countdown-label uk-margin-small uk-text-center">
Hours
</div>
</div>
<div class="uk-countdown-separator">:</div>
<div>
<div class="uk-countdown-minutes uk-countdown-number"></div>
<div class="uk-visible@s uk-countdown-label uk-margin-small uk-text-center">
Minutes
</div>
</div>
<div class="uk-countdown-separator">:</div>
<div>
<div class="uk-countdown-seconds uk-countdown-number"></div>
<div class="uk-visible@s uk-countdown-label uk-margin-small uk-text-center">
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.On your tailwind.config.js file, add the
Countdown component within the ui() plugin.
import ui from "franken-ui";
ui({
components: {
countdown: {
hooks: {},
media: true
}
}
}),
Note If you are developing theme from scratch, you can use all these hooks. If you’re using the shadcn/ui theme, some hooks might not work as they were already in use or removed. Learn more about using hooks.
| Hook Name | Affected Classes |
|---|---|
hook-countdown | .uk-countdown |
hook-item | .uk-countdown-number, .uk-countdown-separator |
hook-number | .uk-countdown-number |
hook-separator | .uk-countdown-separator |
hook-label | .uk-countdown-label |
hook-misc | * |