HTML countdown timer you can copy and paste
An HTML countdown timer is a small block of HTML for the numbers, CSS for the look and a few lines of JavaScript that work out the time left. Set your deadline, watch the preview run the real code, and copy it. No library, no outside files.
Live preview
The code
Set a date to see the code.
How a timer in HTML works
A timer in HTML is three small parts working together. The HTML holds a box for each unit, days, hours, minutes and seconds. The CSS lays them out and colors them. The JavaScript reads the deadline, subtracts the current time, and writes the difference into the boxes. Then it waits until the next whole second and does it again, until the difference reaches zero.
- The deadline is stored on the outer box as
data-end, a Unix time in seconds. - The script works out the seconds left with
Date.now()and rounds up, so the last second shows as 01 rather than 00. - It splits that into days, hours, minutes and seconds and pads each to two digits.
- It schedules the next update for the start of the next second, so the display never drifts behind the clock.
- At zero it hides the numbers, shows your end line, and stops.
The code, part by part
Every class name in the code starts with ect- and a few random letters, so two
timers on the same page, or a timer on a page with its own stylesheet, never collide. The
style block only styles those classes. The script is wrapped in a function that runs once,
finds its own box by that class, and leaves no global variables behind.
It uses the system font of each visitor's device, so it loads no font file. The digits use tabular figures, which keeps every number the same width and stops the timer jiggling as it counts. The whole thing is a few kilobytes, and the size of yours is shown under the code.
Accessible without extra work
A timer that announces itself every second makes a page unusable with a screen reader. This one hides the ticking digits from assistive technology and keeps a separate polite live region that says the time left in words, such as "2 days, 4 hours, 15 minutes left", and changes it only when the minute changes.
A visitor who has asked their device to reduce motion does not get the ticking seconds. The CSS hides the seconds box, and the script updates once a minute instead of once a second. The four styles keep their text above the contrast the WCAG guidelines ask for.
Time zones, and changing the deadline by hand
The date and time you type are read in the time zone you pick, daylight saving included, and
stored as one instant. That is why the same code counts to the same moment for every visitor.
To move the deadline later, change the number in data-end. Come back here and
set the new date, or work it out in a browser console:
Date.parse("2027-01-01T00:00:00Z") / 1000 gives the number for midnight UTC on
1 January 2027.
Where to paste it
Anywhere a page accepts raw HTML. WordPress has a Custom HTML block, Squarespace a Code block, Webflow an Embed element and Shopify a Custom Liquid section, and a hand-written site takes it as it is. If the numbers stay at 00, the block you used removed the script: some text blocks and some hosted plans do that, and the builder's code or embed block is the one to use.
For a countdown without a website, the free online countdown timer makes the same countdown as a page of its own, with a link to share and a full screen view.
Why an HTML countdown timer cannot go in an email
Email clients do not run JavaScript. Gmail, Outlook, Apple Mail and the rest remove scripts from a message before showing it, and many remove style blocks too, so the code on this page would arrive as a row of zeros or nothing. The one thing that moves in an inbox is an animated image, which is why an email countdown is a GIF drawn by a server at the moment the email is opened.
The free email countdown timer generator makes that image and gives you the code for your email platform. A timer from the free generator works for 500 opens without an account, and for 1,000 once you sign in and claim it. The guide to countdown timers in email explains how the image behaves in each client, and two more free tools cover downloading a countdown GIF and checking a GIF before a send.
Questions about the HTML countdown timer
Does this countdown need jQuery or any library
No. It is plain JavaScript that every current browser runs, with no library, no font file and no request to this site or any other. Copy it, and it is yours.
How do I change the end date later
Change the number in data-end. It is the deadline as a Unix time in seconds, which is the same instant everywhere in the world. Make the timer again on this page and copy the new number, or work it out in a browser console with Date.parse("2027-01-01T00:00:00Z") / 1000.
Will the timer show the right time for visitors in other time zones
Yes. The deadline is stored as an instant rather than a local date, so a visitor in Sydney and a visitor in Los Angeles see the same number of hours left. The time zone you pick here is only used to turn the date and time you typed into that instant.
Why do the numbers stay at 00 after I paste it
The page is not running the script. Some site builders and some hosted blog plans strip script tags from a content block. Use the builder's own custom code or embed block instead of a text block, or check the plan's rules on scripts.
Can I use this HTML countdown timer in an email
No. Email clients remove JavaScript from every message, so the numbers would never change and most clients would show nothing at all. An email countdown is an animated image drawn when the email is opened. The free email countdown timer generator on this site makes one.
What does it show when the countdown ends
The numbers are hidden and the line you set is shown in their place, "The countdown has ended" by default. The script then stops, so nothing keeps running on the page.