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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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.

HTML

              
                <link href="https://fonts.googleapis.com/css?family=Pacifico" rel="stylesheet">

<div class="container">
  <h1>Pomodoro Timer</h1>
  
  <div id="pomodoro">  
    <img src="http://pngimages.net/sites/default/files/red-tomato-png-image-16592.png" style="width:350px; height:350px">
    <div id="status"></div>
    <div class="timerDisplay">25:00</div>
    <button id="start-btn" class="btn">START</button>
  </div>
  
  <div class="settings">
    <div id="work">
      <p>Work Duration</p>
      <button class="btn-settings" id="work-plus">+</button>
      <div><span id="work-min">25</span> mins</div>
      <button class="btn-settings" id="work-minus">-</button>
    </div>
    
    <button id="reset" class="btn">RESET</button>
    
    <div id="break">
      <p>Break Duration</p>
      <button class="btn-settings" id="break-plus">+</button>
      <div><span id="break-min">5</span> mins</div>
      <button class="btn-settings" id="break-minus">-</button>
    </div>
  </div>
  
  <p class="footer">Coded and designed by <a href="https://www.cynthialee.io" target="blank">Cynthia Lee</a></p
</div>
              
            
!

CSS

              
                html {
  background-color: #d9e0f7;
  text-align: center;
  min-width: 350px;
  @import url(https://fonts.googleapis.com/css?family=Noto+Sans" rel="stylesheet");
  font-family: 'Noto Sans', sans-serif;
}

h1 {
  font-family: 'Pacifico', cursive;
  font-size: 4em;
  font-weight: lighter;
  padding: 0px;
  margin: 0px 10px;
}

.container {
  padding: 0px;
  width: 100%;
  max-width: 800px;
  margin: auto;
  text-align: center;
}

#pomodoro {
  margin: 0 auto;
  position: relative;
  padding: 0px 10px;
}

#status {
  width: 70%;
  color: #efc4c4;
  font-size: 2em;
  position: absolute;
  top: 45%;
  left:50%;
  transform: translate(-50%, -50%);
}

.timerDisplay {
  color: #fff;
  font-size: 4em;
  font-weight: bold;
  position: absolute;
  top: 60%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.btn {
  margin: 10px;
  padding: 8px 10px;
  color: white;
  font-size: 1em;
  cursor:pointer;
  border: 2px solid white;
}

#start-btn {
  height: 40px;
  width: 90px;
  border-radius: 20px;
  position: absolute;
  bottom: 8%;
  left: 48%;
  transform: translate(-50%, -50%);
  background: #4f8760;
}

.btn-settings {
  background-color: #4e4e5b;
  margin: 10px;
  border: 1px solid #4e4e5b;
  border-radius: 10px;
  padding: 2px 5px;
  min-width: 40px;
  color: white;
  font-size: 2em;
  cursor:pointer;
}

.settings {
  margin: auto;
  width: 80%;
  display: grid;
  grid-template-columns: 2fr 1fr 2fr;
  align-items: center;
}

#reset {
  border-radius: 50px;
  width: 80px;
  height: 80px;
  background: #074082;
  transform: translate(0%, 50%);
  
}

#work, #break {
  color: #4e4e5b;
  font-weight: bold;
} 

#work p, #break p {
  color: #074082;
  background: #efc4c4;
  padding: 5px;
}

.footer {
  padding: 20px 0;
  color: #4e4e5b;
}

@media only screen and (max-width: 400px) {
  .timerDisplay {
  font-size: 2.5em;
  }
}
              
            
!

JS

              
                let countdown = 0; // variable to set/clear intervals
let seconds = 1500; // seconds left on the clock
let workTime = 25;
let breakTime = 5;
let isBreak = true;
let isPaused = true;

const status = document.querySelector("#status");
const timerDisplay = document.querySelector(".timerDisplay");
const startBtn = document.querySelector("#start-btn");
const resetBtn = document.querySelector("#reset");
const workMin = document.querySelector("#work-min");
const breakMin = document.querySelector("#break-min");

const alarm = document.createElement('audio'); // A bell sound will play when the timer reaches 0
alarm.setAttribute("src", "https://www.soundjay.com/misc/sounds/bell-ringing-05.mp3");


/* EVENT LISTENERS FOR START AND RESET BUTTONS */
startBtn.addEventListener('click', () => {
  clearInterval(countdown);
  isPaused = !isPaused;
  if (!isPaused) {
    countdown = setInterval(timer, 1000);
  }
})

resetBtn.addEventListener('click', () => {
  clearInterval(countdown);
  seconds = workTime * 60;
  countdown = 0;
  isPaused = true;
  isBreak = true;
})

/* TIMER - HANDLES COUNTDOWN */
function timer() {
  seconds --;
  if (seconds < 0) {
    clearInterval(countdown);
    alarm.currentTime = 0;
    alarm.play();
    seconds = (isBreak ? breakTime : workTime) * 60;
    isBreak = !isBreak;
    countdown = setInterval(timer, 1000);
  }
}

 
/* UPDATE WORK AND BREAK TIMES */
let increment = 5;

let incrementFunctions =
    {"#work-plus": function () { workTime = Math.min(workTime + increment, 60)},
     "#work-minus": function () { workTime = Math.max(workTime - increment, 5)},
     "#break-plus": function () { breakTime = Math.min(breakTime + increment, 60)},
     "#break-minus": function () { breakTime = Math.max(breakTime - increment, 5)}};

for (var key in incrementFunctions) {
    if (incrementFunctions.hasOwnProperty(key)) {
      document.querySelector(key).onclick = incrementFunctions[key];
    }
}

/* UPDATE HTML CONTENT */
function countdownDisplay() {
  let minutes = Math.floor(seconds / 60);
  let remainderSeconds = seconds % 60;
  timerDisplay.textContent = `${minutes}:${remainderSeconds < 10 ? '0' : ''}${remainderSeconds}`;
}

function buttonDisplay() {
  if (isPaused && countdown === 0) {
    startBtn.textContent = "START";
  } else if (isPaused && countdown !== 0) {
    startBtn.textContent = "Continue"; 
  } else {
    startBtn.textContent = "Pause";
  }
}

function updateHTML() {
  countdownDisplay();
  buttonDisplay();
  isBreak ? status.textContent = "Keep Working" : status.textContent = "Take a Break!";
  workMin.textContent = workTime;
  breakMin.textContent = breakTime;  
}

window.setInterval(updateHTML, 100);

document.onclick = updateHTML;
              
            
!
999px

Console