cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <html>
<head>
  <link> 
  <meta charset="utf-8">
    <title>Timer</title>
    
</head>
<body>
    <h1>Countdown Clock</h1>
    
    <div class="clockBackground">
        <div id="clockdiv">
            <div>
                <span class="days"></span>
                <div class="smalltext">Days</div>
            </div>
            <div>
                <span class="hours"></span>
                <div class="smalltext">Hours</div>
            </div>
            <div>
                <span class="minutes"></span>
                <div class="smalltext">Minutes</div>
            </div>
            <div>
                <span class="seconds"></span>
                <div class="smalltext">Seconds</div>
            </div>
        </div>
    </div>
</body>
</html>
            
          
!
            
              body {
  text-align: center;
  background: #333232;
  font-family: sans-serif;
  font-weight: 100;
}

.clockBackground {
  background-image: linear-gradient(to top, #1d1c1c, #ccc, #1d1c1c);
}

h1 {
  font-size: 3.5em;
  color: #bdb7f6;
  font-weight: 100;
  margin: 40px 0px 20px;
}

#clockdiv {
  font-family: sans-serif;
  color: #bdb7f6;
  display: inline-block;
  font-weight: 100;
  text-align: center;
  font-size: 30px;
}

#clockdiv > div {
  padding: 10px;
  border-radius: 3px;
  display: inline-block;
}

#clockdiv div > span {
  padding;
  2em;
  margin: .25em;
  border-radius: 3px;
  display: inline-block;
  font-size: 3em;
  color: #333232;
}

.smalltext {
  padding-top: .05em;
  font-size: 1em;
  background-color: #333232;
  box-shadow: 4px 4px 3px #333232;
}

span {
  color: #bdb7f6;
}
            
          
!
            
              
/***** CALCULATE THE TIME REMAINING *****/
function getTimeRemaining(endtime) {
    var t = Date.parse(endtime) - Date.parse(new Date());
    
    /***** CONVERT THE TIME TO A USEABLE FORMAT *****/
    var seconds = Math.floor( (t / 1000) % 60 );
    var minutes = Math.floor( (t / 1000 / 60) % 60 );
    var hours = Math.floor( (t / (1000 * 60 * 60)) %  24);
    var days = Math.floor( t / (1000 * 60 * 60 * 24) );
    
    /***** OUTPUT THE CLOCK DATA AS A REUSABLE OBJECT *****/
    return {
        'total': t,
        'days': days,
        'hours': hours,
        'minutes': minutes,
        'seconds': seconds
    };
}

/***** DISPLAY THE CLOCK AND STOP IT WHEN IT REACHES ZERO *****/
function initializeClock(id, endtime) {
    var clock = document.getElementById(id);
    var daysSpan = clock.querySelector('.days');
    var hoursSpan = clock.querySelector('.hours');
    var minutesSpan = clock.querySelector('.minutes');
    var secondsSpan = clock.querySelector('.seconds');
    
    function updateClock() {
        var t = getTimeRemaining(endtime);
        
        daysSpan.innerHTML = t.days;
        hoursSpan.innerHTML = ('0' + t.hours).slice(-2);
        minutesSpan.innerHTML = ('0' + t.minutes).slice(-2);
        secondsSpan.innerHTML = ('0' + t.seconds).slice(-2);
        
        if (t.total <= 0) {
            clearInterval(timeinterval);
        }
    }

updateClock(); // run function once at first to avoid delay
var timeinterval = setInterval(updateClock,1000);
}

/***** SET A VALID END DATE *****/
var deadline = new Date(Date.parse(new Date()) + 15 * 24 * 60 * 60 * 1000);
initializeClock('clockdiv', deadline);
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console