Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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 id="mainContainer">
  <h1>Pomodoro Clock</h1>

  <div id="timerContainer">
    <div id="timer">
      <h2 id="timer-label">Session</h2>
      <span id="time-left">25:00</span>
    </div>
  </div>

  <div class="controls">
    <button id="start_stop" aria-label="play / pause">
      <svg
           xmlns="http://www.w3.org/2000/svg"
           focusable="false"
           width="1em"
           height="1em"
           style="
                  -ms-transform: rotate(360deg);
                  -webkit-transform: rotate(360deg);
                  transform: rotate(360deg);
                  "
           preserveAspectRatio="xMidYMid meet"
           viewBox="0 0 24 24"
           >
        <path d="M3 5v14l8-7m2 7h3V5h-3m5 0v14h3V5" fill="white" />
      </svg>
    </button>
    <button id="reset" aria-label="reset">
      <svg
           xmlns="http://www.w3.org/2000/svg"
           focusable="false"
           width="1em"
           height="1em"
           style="
                  -ms-transform: rotate(360deg);
                  -webkit-transform: rotate(360deg);
                  transform: rotate(360deg);
                  "
           preserveAspectRatio="xMidYMid meet"
           viewBox="0 0 24 24"
           >
        <path
              d="M13.5 7a6.5 6.5 0 0 1 6.5 6.5a6.5 6.5 0 0 1-6.5 6.5H10v-2h3.5c2.5 0 4.5-2 4.5-4.5S16 9 13.5 9H7.83l3.08 3.09L9.5 13.5L4 8l5.5-5.5l1.42 1.41L7.83 7h5.67M6 18h2v2H6v-2z"
              fill="white"
              />
      </svg>
    </button>
  </div>

  <audio id="beep" src="http://soundbible.com/mp3/A-Tone-His_Self-1266414414.mp3"></audio>

  <div id="duration-controls" class="controls">
    <div class="buttonGroup">
      <h3 id="break-label">Break</h3>
      <button id="break-increment">+</button>
      <span id="break-length">5</span>
      <button id="break-decrement">&minus;</button>
    </div>

    <div class="buttonGroup">
      <h3 id="session-label">Session</h3>
      <button id="session-increment">+</button>
      <span id="session-length">25</span>
      <button id="session-decrement">&minus;</button>
    </div>
  </div>
</div>

              
            
!

CSS

              
                body {
  background-color: #333333;
  color: white;

  font-family: Roboto, sans-serif;
}

#mainContainer {
  width: 100%;
  max-width: 500px;
  margin: 25px auto 0 auto;
}

h1 {
  text-align: center;
  width: 100%;
  margin: 20px 0 20px 0;
  font-size: 6vh;
}

#timerContainer {
  border: 2px solid lime;
  border-radius: 50%;
  height: 250px;
  width: 250px;
  margin: 20px auto 20px auto;
}

#timer {
  background-color: lime;

  background-image: linear-gradient(to top, lime, lime 0%, #333333 0%);

  border-radius: 50%;
  height: 240px;
  width: 240px;
  margin: 5px;

  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-content: center;

  cursor: pointer;
}

#timer > * {
  margin: 0;
  width: 100%;
  text-align: center;
  font-size: 32px;
}

#timer-label {
  padding-top: 30px;
}

#time-left {
  padding-bottom: 30px;
  height: 38px;
}

.controls {
  width: 100%;
  padding-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: space-around;
}

.buttonGroup {
  width: 40%;
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
}

.buttonGroup > span {
  font-size: 30px;
  width: 34px;
  text-align: center;
}

.buttonGroup > h3 {
  width: 100%;
  text-align: center;

  font-weight: normal;
  font-variant: small-caps;
  font-size: 20px;
}

button {
  background-color: inherit;
  border: none;
  font-family: inherit;
  color: inherit;
  font-size: 24px;
  cursor: pointer;
}

              
            
!

JS

              
                (function () {
  const $ = document.querySelector.bind(document);

  let sessionLength = 25;
  let breakLength = 5;
  let remainingSeconds = sessionLength * 60;
  let countDownTimer;
  let isBreak = false;
  let counterRunning = false;

  const beep = $("#beep");

  $("#start_stop").addEventListener("click", toggleTimer);
  $("#duration-controls").addEventListener("click", changeTimes);
  $("#reset").addEventListener("click", reset);

  render();

  function toggleTimer() {
    counterRunning ? stopTimer() : startTimer();
  }

  function stopTimer() {
    clearInterval(countDownTimer);
    counterRunning = false;
  }

  function startTimer() {
    countDownTimer = setInterval(countDown, 1000);
    counterRunning = true;
  }

  function countDown() {
    remainingSeconds--;

    if (remainingSeconds < 0) {
      beep.play();
      switchMode();
    }
    render();
  }

  function reset() {
    stopTimer();
    beep.pause();
    beep.currentTime = 0;
    breakLength = 5;
    sessionLength = 25;
    isBreak = false;
    remainingSeconds = sessionLength * 60;
    render();
  }

  function changeTimes(e) {
    if (counterRunning || e.target.nodeName !== "BUTTON") {
      return;
    }

    switch (e.target.id) {
      case "break-decrement":
        if (breakLength > 1) {
          breakLength--;
        }
        break;
      case "break-increment":
        if (breakLength < 60) {
          breakLength++;
        }
        break;
      case "session-decrement":
        if (sessionLength > 1) {
          sessionLength--;
        }
        break;
      case "session-increment":
        if (sessionLength < 60) {
          sessionLength++;
        }
    }

    remainingSeconds = isBreak ? breakLength * 60 : sessionLength * 60;

    render();
  }

  function switchMode() {
    isBreak = !isBreak;
    remainingSeconds = isBreak ? breakLength * 60 : sessionLength * 60;
  }

  function render() {
    $("#break-length").textContent = breakLength;
    $("#session-length").textContent = sessionLength;
    $("#timer-label").textContent = isBreak ? "Break!" : "Session";
    $("#time-left").textContent = formatTime(remainingSeconds);
    $("#timer").style.background = getBackgroundGradient();
  }

  function formatTime(seconds) {
    const formattedMinutes = Math.floor(seconds / 60)
      .toString()
      .padStart(2, "0");
    const formattedSeconds = (seconds % 60).toString().padStart(2, "0");
    return `${formattedMinutes}:${formattedSeconds}`;
  }

  function getBackgroundGradient() {
    const totalSeconds = isBreak ? breakLength * 60 : sessionLength * 60;
    const percent = Math.round((1 - remainingSeconds / totalSeconds) * 100);
    return `linear-gradient(to top,${getFillColor()},${getFillColor()} ${percent}%,#333333 ${percent}%)`;
  }

  function getFillColor() {
    return isBreak ? "red" : "green";
  }
})();

              
            
!
999px

Console