{countdown}
The time left until a moment, in words inside a time element - ticking every second in the browser when asked.
Syntax
{countdown '2026-12-31 00:00'}
{countdown $moment, units=3, past='We are live!', live}
{countdown $moment, now='2026-10-08 12:00', format='j M Y'}
Parameters
-
moment - The moment counted down to - a date in text, a Unix timestamp or a date object.
Options
-
units - How many units are shown, 1 to 4 (days, hours, minutes, seconds), default 2.
-
past -
The text once the moment has gone, default
ended. -
live - Bare option: a small script, once per page, counts down every second from the browser's clock.
-
now - Count from this moment instead of now.
-
format -
The PHP date format of the full moment in the
title, defaultl j F Y, H:i.
Description
{countdown '2026-12-31 00:00'} writes the time left until the moment in words - 84 days, 3 hours - inside a <time class="pad-countdown"> whose datetime is the moment and whose title is the moment in full. The words start at the largest unit that is not zero and take units of them, a zero unit among them left out: 5 minutes, 12 seconds, 1 day. Once the moment has gone, the text of past= stands there instead - ended when not given.
Now is padNow (), so padNowFreeze () holds a test still, and now= counts from a given moment - how the first example here stays the same on every request. format= is the PHP date format of the title.
With live the element gets role="timer" and the moment in milliseconds, and a small script - written once a page, carrying the request's nonce when $padCsp asks for one - counts down every second from the browser's clock, the same way the server counts. Without a script the server's words stay as they are. A moment that is no date and units outside 1 to 4 are strict errors.
Examples
Upcoming events
The two largest units by default, three or four when asked, and past= for an event that has started - all counted from a fixed now.
<ul>
<li>Jazz in the park: {countdown '2026-10-06 20:00', now='2026-10-08 12:00', past='Sold out'}</li>
<li>Pottery workshop: {countdown '2026-10-08 15:20', now='2026-10-08 12:00'}</li>
<li>City half marathon: {countdown '2026-10-12 09:30', now='2026-10-08 12:00', units=3}</li>
<li>New year: {countdown '2027-01-01 00:00', now='2026-10-08 11:59:30', units=4}</li>
</ul>
- Jazz in the park:
- Pottery workshop:
- City half marathon:
- New year:
A live launch counter
Three units, counting down every second in the browser - the server writes the same words first.
<p>Version 3.0 launches in {countdown '2026-12-01 10:00', units=3, live, past='We are live!'}</p>
See also
- {timeago} How long ago a moment was, in words, inside a time element that keeps the exact moment as its datetime and title.
- {calendar} Writes a month as a calendar table with its events, or hands over its weeks and days as rows for markup of your own.