css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

<div>  <h1 class="text-center"> Jack's awesome countdown clock.</h1>
  <h3 class="text-center"> I want to countdown <select  id="countId" class="min-select">
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
  <option value="8">8</option>
  <option value="9">9</option>
  <option value="10">10</option>
  <option value="11">11</option>
  <option value="12">12</option>
  <option value="13">13</option>
  <option value="14">14</option>
  <option value="15">15</option>
  <option value="16">16</option>
  <option value="17">17</option>
  <option value="18">18</option>
  <option value="19">19</option>
  <option value="20">20</option>
  <option value="21">21</option>
  <option value="22">22</option>
  <option value="23">23</option>
  <option value="24">24</option>
  <option value="25">25</option>
  <option value="26">26</option>
  <option value="27">27</option>
  <option value="28">28</option>
  <option value="29">29</option>
  <option value="30">30</option>
  <option value="31">31</option>
  <option value="32">32</option>
  <option value="33">33</option>
  <option value="34">34</option>
  <option value="35">35</option>
  <option value="36">36</option>
  <option value="37">37</option>
  <option value="38">38</option>
  <option value="39">39</option>
  <option value="40">40</option>
</select> minutes</h3>
<div class="container clock">
   <div class="row row-centered">
      <div class="col-xs-6 clock-display"><h3 id=time_left>00:00<h3></div>
     <div class="row row-centered">
       <div class="buttons">
         <button id="playpause" class="btn btn-default btn-start">Start</button>
         <button id="reset" class="btn btn-default btn-reset">Reset</button></div>
              body {
  font-family: 'Roboto Slab', serif;
  font-style: bold;
  background-color: #f7f7f7;

.clock {
  background-color: yellow;
  width: 70%;
  margin-top: 100px;
  height: 170px;
  box-shadow: 0 7px 4px #777;
    -webkit-box-shadow: 0 7px 4px #777;
	-moz-box-shadow: 0 7px 4px #777;

.row-centered {
  text-align: center;
.clock-display {
  margin-top: 20px; 
  width: 70%; 
  background: rgba(0, 0, 0, 0.2);
	border-radius: 3px;
	box-shadow: inset 0px 4px rgba(0, 0, 0, 0.2);

.buttons {
  margin: 20px 5px 0px 0px; 
  width: 70%;

.btn-start {
  width: 45%;
  margin-right: 5px;

.btn-reset {
  width: 45%;
  margin-left: 5px;
.panel {
  background-color: orange;
  margin: 20px 0px 0px 20px;
              var playpause = document.getElementById('playpause');
var reset = document.getElementById('reset');
var counterSelect = document.getElementById('countId');

 * Provide conditions for initial state.

var counterValue = counterSelect.value * 60;
var playing = false;

 * Handle play/pause click events. 
 * Begin or pause the countdown.

playpause.onclick = function() {

  if (!playing) {
    playing = true;
    playpause.innerHTML = "Pause";
  } else {
    playpause.innerHTML = "Play";
    playing = false;


 * Reset the countdown to the value on the select field.
 * Also pauses the countdown.

reset.onclick = function() {
  playing = false;
  counterValue = selectedCounterValue();
  playpause.innerHTML = "Start";

 * React to change events on the select field.
 * i.e. change the time rendered and reset the counterValue.

counterSelect.onchange = function(e) {
  renderTime(counterValue = selectedCounterValue());

 * Retrieve the current value of the select field.

function selectedCounterValue() {
  return counterSelect.value * 60;

 * Recursively count down to zero given an initial value.

function countDownFrom(seconds) {

  if (playing) {
    if (seconds > -1) {
      setTimeout(function() {
        counterValue = countDownFrom(seconds = seconds - 1)
      }, 1000);
    } else {
      playing = false;
      seconds = 0;

  return seconds;


 * Output a human readable timestamp given an inital value.

function secondsToTime(seconds) {

  var hours = Math.floor(seconds / 3600);
  seconds -= hours * 3600;
  var minutes = Math.floor(seconds / 60);
  seconds -= minutes * 60;

  if (hours < 1) {
    return leadingZero(minutes) + ':' + leadingZero(seconds);
  } else {
    return hours + ':' + leadingZero(minutes) + ':' + leadingZero(seconds);


 * Determine where to place the zeros in a time stamp.

function leadingZero(Time) {
  return (Time < 10) ? "0" + Time : +Time;

 * Render a timestamp on the page.

function renderTime(seconds) {
  document.getElementById('time_left').innerHTML = secondsToTime(seconds);
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................