Countdown MDB Pro component

Countdown - Bootstrap 5 & Material Design 2.0 plugin

Dummy plugin creates placeholder content for accelerated building and testing your frontend templates.

Note: Read the API tab to find all available options and advanced customization


Countdown plugin creates countdown timer indicating time left to a given date.

Basic example

Create default Countdown by adding data-countdown to a container element with a Countdown expiration date value. Add countdown-unit class and an attribute data- with time unit to a child element to indicate which time units should be displayed inside Countdown.


          <div data-countdown="31 December 2021 23:59:59">
            <div class="countdown-unit countdown-days"></div>
            <div class="countdown-unit countdown-hours"></div>
            <div class="countdown-unit countdown-minutes"></div>
            <div class="countdown-unit countdown-seconds"></div>
          </div>
        

Interval

Create interval that will reset timer every time initial countdown ends.


          <div data-countdown="5 November 2020 12:35" data-countdown-interval="30">
            <div class="countdown-unit countdown-days"></div>
            <div class="countdown-unit countdown-hours"></div>
            <div class="countdown-unit countdown-minutes"></div>
            <div class="countdown-unit countdown-seconds"></div>
          </div>
        

Label

Create label for each time unit by adding data-countdown-label with a text of your choice.


          <div data-countdown="31 December 2021 23:59:59">
            <div class="countdown-unit countdown-days" data-countdown-label="days"></div>
            <div class="countdown-unit countdown-hours" data-countdown-label="hours"></div>
            <div class="countdown-unit countdown-minutes" data-countdown-label="minutes"></div>
            <div class="countdown-unit data-seconds" data-countdown-label="seconds"></div>
          </div>
        

Separator

Add data-countdown-separator to a container element to insert separator between each time unit.

Separator won't be visible for Countdown column position


          <div data-countdown="31 December 2021 23:59:59" data-countdown-separator=":">
            <div class="countdown-unit countdown-days"></div>
            <div class="countdown-unit countdown-hours"></div>
            <div class="countdown-unit countdown-minutes"></div>
            <div class="countdown-unit countdown-seconds"></div>
          </div>
        

Styling

Countdown position

Change default horizontal position of Countdown with data-countdown-position="vertical"


            <div data-countdown="31 December 2021 23:59:59" data-countdown-position="vertical">
              <div class="countdown-unit countdown-days"></div>
              <div class="countdown-unit countdown-hours"></div>
              <div class="countdown-unit countdown-minutes"></div>
              <div class="countdown-unit countdown-seconds"></div>
            </div>
          

Label position

Change default vertical position of Countdown label with data-countdown-label-position="horizontal"


            <div data-countdown="31 December 2021 23:59:59" data-countdown-label-position="horizontal">
              <div class="countdown-unit countdown-days" data-countdown-label="d"></div>
              <div class="countdown-unit countdown-hours" data-countdown-label="h"></div>
              <div class="countdown-unit countdown-seconds" data-countdown-label="m"></div>
              <div class="countdown-unit countdown-seconds" data-countdown-label="s"></div>
            </div>
          

Text size

Change default time unit text size (4rem) with data-countdown-text-size.


            <div data-countdown="31 December 2021 23:59:59" data-countdown-text-size="6rem">
              <div class="countdown-unit countdown-days" data-countdown-label="days"></div>
              <div class="countdown-unit countdown-hours" data-countdown-label="hours"></div>
              <div class="countdown-unit countdown-seconds" data-countdown-label="minutes"></div>
              <div class="countdown-unit countdown-seconds" data-countdown-label="seconds"></div>
            </div>
          

Custom classes

Add custom classes to time unit value and label with data-countdown-text-style and data-countdown-label-style


            <div data-countdown="31 December 2021 23:59:59" data-countdown-text-style="badge bg-primary"
              data-countdown-label-style="text-light bg-dark">
              <div class="countdown-unit countdown-days" data-countdown-label="days"></div>
              <div class="countdown-unit countdown-hours" data-countdown-label="hours"></div>
              <div class="countdown-unit countdown-seconds" data-countdown-label="minutes"></div>
              <div class="countdown-unit countdown-seconds" data-countdown-label="seconds"></div>
            </div>
          

Countdown - API


Usage

Create default Countdown by adding data-countdown to a container element with a Countdown expiration date value. Date value should be passed using proper Date format.
Add countdown-unit class to a child element to indicate unit styling and countdown-* class, where * indicating which time units should be displayed inside Countdown.

Via data attributes


        <div data-countdown="31 December 2021 23:59:59">
          <div class="countdown-unit countdown-days"></div>
          <div class="countdown-unit countdown-hours"></div>
          <div class="countdown-unit countdown-minutes"></div>
          <div class="countdown-unit countdown-seconds"></div>
        </div>
      

Via JavaScript


        <div id="countdown-element">
          <div class="countdown-unit countdown-days"></div>
          <div class="countdown-unit countdown-hours"></div>
          <div class="countdown-unit countdown-minutes"></div>
          <div class="countdown-unit countdown-seconds"></div>
        </div>
      

        const countdownExample = document.getElementById('countdown-element');
        new Countdown(countdownExample, {
        countdown: "31 December 2021 23:59:59",
        })
      

Via jQuery

Note: By default, MDB does not include jQuery and you have to add it to the project on your own.


        <div id="countdown-element">
          <div class="countdown-unit countdown-days"></div>
          <div class="countdown-unit countdown-hours"></div>
          <div class="countdown-unit countdown-minutes"></div>
          <div class="countdown-unit countdown-seconds"></div>
        </div>
      

        $('#countdown-element').countdown();
      

Options

Options can be passed via data attributes, JavaScript, or jQuery. For data attributes, append the option name to data-, as in data-. Each option can be passed with value or null.

Name Type Default Description
countdown String '' Initiates Countdown instance on element. Takes the value of the date to which the timer will be counting.
'unit' Attached to children element defines time unit to be displayed on element. Possible values: data-"days | hours | minutes | seconds".
'countdownInterval' Number 0 Sets interval in seconds that will reset timer after given amount of time after initial countdown ends.
countdownLabel String '' Attached to children element defines time unit label to be displayed on element.
countdownSeparator String '' Attached to container element defines separator used between each time unit value. Separator is not visible in vertical position of the Countdown element.
countdownPosition String 'horizontal' Positions Countdown element horizontally or vertically.
countdownLabelPosition String 'vertical' Positions the label at the bottom or next to the corresponding time unit value.
countdownTextStyle String '' Adds custom styles to all time unit text elements.
countdownLabelStyle String '' Adds custom styles to all labels.
countdownTextSize String '' Sets size of time unit text element. Text for labels in vertical label position is four times smaller than time unit text.

Methods

Name Parameters Description Example
stop Stops the timer. instance.stop()
start Starts stopped timer. instance.start()
setCountdownDate date Dynamically sets new date to count to instance.setCountdownDate('31 December 2021 23:59:59')
dispose Disposes a Countdown instance. instance.dispose()
getInstance element Static method which allows to get the countdown instance associated with a DOM element. Countdown.getInstance(couontdownElement)

        const countdownElement = document.getElementById('countdown-element');
        const instance = Countdown.getInstance(countdownElement);
        instance.stop();
        instance.start();
      

Events

Name Description
start.mdb.countdown This event fires immediately when the countdown starts counting.
end.mdb.countdown This event fires immediately when the countdown timer stops counting.

          document.addEventListener('start.mdb.countdown', (e)=> {
          // do something...
          })
        

Import

MDB UI KIT also works with module bundlers. Use the following code to import this component:


        import { Countdown } from 'mdb-countdown';