Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="timer-container">
  <h1>) pomo (</h1>
  <h3>break</h3>
  <button id="increase-break">&uarr;</button>
  <span id="break-time">5</span>
  <button id="decrease-break">&darr;</button>
  
  <h3>session</h3>
  <button id="increase-session">&uarr;</button>
  <span id="session-time">25</span>
  <button id="decrease-session">&darr;</button>

  <h3>ready</h3>
  <button id="play-pause">&#9654;</button>
  <span>) (</span>
  <button id="reset">&#8634;</button>

  <div id="focus-container">
    <h3 id="time-remaining">25:00</h3>
    <h3 id="current-state">ready?</h3>
    <div id="spinner"></div>
  </div>
</div>
              
            
!

CSS

              
                body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin: 0 auto;
  width: 100%;
  height: 100%;
  height: 100vh;
  overflow: hidden;
  background: linear-gradient(to bottom right, #66f, #6f6);
  color: #ddd;
  text-align: center;
  font-family: "Comfortaa", "Century Gothic", sans-serif;
  letter-spacing: 1.5px;
}
.timer-container {
  text-align: center;
  margin: 0 auto;
  width: 320px;
  padding: 2rem;
  overflow: hidden;
}
button {
  color: white;
  border: thin solid #eee;
  background-color: transparent;
  height: 40px;
  width: 40px;
  border-radius: 50%;
  margin-left: 1rem;
  margin-right: 1rem;
  &:focus {
    outline: none;
  }
}
span {
  display: inline-block;
  width: 2rem;
}
#focus-container {
  width: 50%;
  margin: 1rem auto;
  padding: 1rem 0 2.5rem 0;
  border: thin solid #ddd;
  h1 {
    margin-top: 0;
  }
}
#spinner {
  margin: 0 auto;
  max-width: 20px;
  max-height: 20px;
  width:10vh;
  height:10vh;
  background-color: rgba(255,255,255,0.5);
  transform: rotate(45deg);
}
.spin {
  animation: 2s ease-out spin infinite;
}
@keyframes spin {
  0% { transform: rotate(45deg); }
  20% { transform: rotate(45deg); }
  80% { transform: rotate(765deg); }
  100% { transform: rotate(765deg); }
}
              
            
!

JS

              
                (function(){
  /////////////////////////////////////////////
  //////////////////  timer  //////////////////
  /////////////////////////////////////////////
  let timer = {
    countingDown: false,
    resolution: 0.1,
    onBreak: false,
    breakLength: 5,
    sessionLength: 25,
    endTime: null,
    startTime: null,
    minutes: 25,
    seconds: 0
  };

  //////////////////////////////////////////////////
  ////////////////// DOM elements //////////////////
  //////////////////////////////////////////////////
  let els = {
    increaseBreak: document.getElementById('increase-break'),
    decreaseBreak: document.getElementById('decrease-break'),
    breakTime: document.getElementById('break-time'),
    increaseSession: document.getElementById('increase-session'),
    decreaseSession: document.getElementById('decrease-session'),
    sessionTime: document.getElementById('session-time'),
    timeRemaining: document.getElementById('time-remaining'),
    playPause: document.getElementById('play-pause'),
    reset: document.getElementById('reset'),
    currentState: document.getElementById('current-state'),
    spinner: document.getElementById('spinner')
  };

  ///////////////////////////////////////////////
  ////////////////// listeners //////////////////
  ///////////////////////////////////////////////
  els.increaseBreak.onclick = increaseBreak;
  els.decreaseBreak.onclick = decreaseBreak;
  els.increaseSession.onclick = increaseSession;
  els.decreaseSession.onclick = decreaseSession;
  els.playPause.onclick = toggleTimer;
  els.reset.onclick = resetTimer;

  ///////////////////////////////////////////////
  ////////////////// functions //////////////////
  ///////////////////////////////////////////////
  function increaseBreak() {
    // don't allow breaks longer than 90 mins
    if (timer.breakLength == 90) { return false; }
    timer.breakLength++;
    updateDom();
  }
  function decreaseBreak() {
    // don't allow breaks shorter than 1 minute
    if (timer.breakLength === 1) { return false; }
    timer.breakLength--;
    updateDom();
  }
  function increaseSession() {
    // no sessions longer than 8 hours
    if (timer.sessionLength == 480) { return false; }
    timer.sessionLength++;
    updateDom();
  }
  function decreaseSession() {
    // no sessions shorter than 1 minute
    if (timer.sessionLength === 1) { return false; }
    timer.sessionLength--;
    updateDom();
  }
  function toggleTimer() {
    // handles play/pause
    if (timer.countingDown) {
      // pause
      timer.countingDown = false;
    } else {
      // play
      timer.countingDown = true;
    }
    updateDom();
  }
  function resetTimer() {
    // stop the timer and reset the session
    timer.countingDown = false;
    timer.onBreak = false;
    timer.minutes = timer.sessionLength;
    timer.seconds = 0;
    updateDom();
  }

  // updates all necessary Dom elements
  function updateDom() {
    // set the play button symbol to pause or play
    els.playPause.innerHTML = timer.countingDown ? '&#9208;' : '&#9654;';

    // display whether on break or in session
    els.currentState.textContent = timer.onBreak ? 'breathe' : 'focus';

    // animate spinner if counting down
    els.spinner.className = timer.countingDown ? 'spin' : '';

    // set title bar text
    let titleBarString = 'pomo - ';
    if (timer.onBreak) {
      titleBarString += 'break - ' + getTimeString();
    } else {
      titleBarString += 'session - ' + getTimeString();
    }
    document.title = titleBarString;

    // update the three timer display elements
    els.timeRemaining.textContent = getTimeString();
    els.breakTime.textContent = timer.breakLength;
    els.sessionTime.textContent = timer.sessionLength;
  }

  // formats seconds by rounding and adding leading zeros if necessary
  function formatSeconds(str) {
    var n = Math.floor(Number.parseFloat(str));
    if (n < 10) {
      return '0' + n;
    }
    return n;
  }
  
  // formats a time string
  function getTimeString() {
    return timer.minutes + ':' + formatSeconds(timer.seconds);
  }

  // main app function
  function tick(){
    // if the timer is counting down
    if (timer.countingDown) {
      // subtract the timer resolution from the current seconds if that number would be non-negative
      if (timer.seconds - timer.resolution >= 0) {
        timer.seconds -= timer.resolution;
      } else {
        // if that number would be negative, check if there are minutes left
        if (timer.minutes > 0) {
          timer.minutes--;
        } else {
          // if no minutes left, swap break/session
          if (timer.onBreak) { 
            // if on break, switch to session
            timer.onBreak = false;
            timer.minutes = timer.sessionLength - 1;
          } else {
            // if not on break, switch to break
            timer.onBreak = true;
            timer.minutes = timer.breakLength - 1;
          }
        }
        // for sessions and breaks, seconds are set to 0
        timer.seconds = 60 - timer.resolution;
      }
      updateDom();
    }
  };

  window.setInterval(tick, 1000 * timer.resolution);
  updateDom();
})();
              
            
!
999px

Console