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 class="container">
  <h1>Pomodoro clock</h1>
  <header class="header">
    <div class="header-action-holder">
      <h2>Break Length</h2>
      <div class="header-action">
        <button class="btn" id="break-decrement">-</button>
        <span id="break">5</span>
        <button class="btn" id="break-increment">+</button>
      </div>
    </div>

    <div class="header-action-holder">
      <h2>Session length</h2>
      <div class="header-action">
        <button class="btn" id="session-decrement">-</button>
        <div>
          <span id="session">25</span>
        </div>
      <button class="btn" id="session-increment">+</button>
      </div>
    </div>
  </header>
  <div class="clock-holder">
    <div class="clock-title">
      <h3 id="clock-title">Session</h3>
    </div>
    <div class="clock">
      <span id="time">25:00</span>
    </div>
    <button class="btn btn-action" id="btn-action">
      <span class="btn-start" id="start">Start</span>
      <span class="btn-stop" id="stop">Stop</span>
    </button>
  </div>
</div>

              
            
!

CSS

              
                html {
  box-sizing: border-box;
  font-family: 'PT Mono', monospace;
  font-size: 62.5%;
  line-height: 1.5;
  position: relative;
}

html,
body {
  color: #fff;
  height: 100%;
}

body {
  background: #F92F07;
  display: flex;
}

h1, h2, h3 {
  margin: 0;
}

.btn {
  appearance: none;
  background-color: transparent;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  display: inline-block;
  font-family: inherit;
  font-size: 3.6vw;
  line-height: 1rem;
  padding: 1.4vw;
  margin: 0;
  outline: none;
  text-decoration: none;
  transition: 0.25s;
  letter-spacing: 0.64px;
  vertical-align: middle;
  text-transform: uppercase;
  transition: 0.25s;
  color: #808080;
  background-color: #fff;
  min-width: 40px;

  &:active, &:hover {
    background-color: darken(#fff, 10%);
  }
}

.btn-action {
  background-color: #F92F07;
  padding: 2.6vw;
  color: #fff;
  font-size: 3vw;

  &:hover, &:active {
    background-color: darken(#F92F07, 5%);
  }
}

.btn-start,
.btn-stop {
  vertical-align: middle;
}

.btn-stop {
  display: none;
}

.is-clicked {
  .btn-start {
    display: none;
  }

  .btn-stop {
    display: block;
  }
}

.clock-holder {
  width: 90%;
  background-color: #fff;
  margin: auto;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;


  @media screen and (min-width: 768px) {
    width: 45vw;
    padding: 6rem 0;
  }

  h3 {
    color: #999;
    font-size: 5vw;
    margin-bottom: 3rem;

    @media screen and (min-width: 768px) {
      font-size: 3vw;
    }
  }
}

.container {
  width: 100%;
  max-width: 500px;
  padding: 4vw 2vw;
  margin: auto;

  @media screen and (min-width: 768px) {
    max-width: 55vw;
  }

  h1 {
    font-size: 4vw;
    text-align: center;
    margin-bottom: 1rem;
  }
}

//Header 

.header {
  display: flex;
  justify-content: space-around;
  align-items: center;
  margin-bottom: 3rem;

  @media screen and (min-width: 768px) {
    justify-content: space-between;
    margin-bottom: 5rem;
  }

  h2 {
    font-size: 3.6vw;
    margin-bottom: 0.4rem;
    text-align: center;

    @media screen and (min-width: 768px) {
      font-size: 3vw;
    }
  }
}

.header-action-holder {
  min-width: 13rem;
}

.header-action {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: auto;

  span {
    font-size: 3.5vw;
  }
}

//Clock styles

.clock {
  width: 300px;
  height: 300px;
  border-radius: 50%;
  border: 10px solid #ddd;
  margin-bottom: 4rem;
  color: #999;
  font-size: 5vw;
  display: flex;
  align-items: center;
  justify-content: center;

  @media screen and (min-width: 768px) {
    width: 300px;
    height: 300px;
  }

  @media screen and (min-width: 982px) {
    width: 400px;
    height: 400px;
  }
}

//Flex helpers

.flexbox {
  display: flex;
}

.justify-space-between {
  justify-content: space-between;
}

.align-items-center {
  align-items: center;
}

              
            
!

JS

              
                var display = document.querySelector('#time');
var action = document.getElementById('btn-action');
var sessionDecrement = document.getElementById('session-decrement');
var sessionIncrement = document.getElementById('session-increment');
var breakDecrement = document.getElementById('break-decrement');
var breakIncrement = document.getElementById('break-increment');
var sessionLength = document.getElementById('session');
var breakLength = document.getElementById('break');
var clockTitle = document.getElementById('clock-title');
var time = document.getElementById('time');

var ONE_MINUTE = 60;

var defaultState = {
  session: 25 * 60,
  break: 5 * 60
};

var state = Object.assign({
  interval: null,
  running: false,
  status: 'session'
}, defaultState);

function displayTime (timer, dom) {
  var minutes;
  var seconds;

  minutes = parseInt(timer / 60, 10);
  seconds = parseInt(timer % 60, 10);

  minutes = minutes < 10 ? '0' + minutes : minutes;
  seconds = seconds < 10 ? '0' + seconds : seconds;
  dom.textContent = minutes + ':' + seconds;
}

function startCountDown (duration, display) {
  function resetInterval () {
    clearInterval(state.interval);

    state = Object.assign(state, {
      running: false
    }, defaultState);
  }

  // session
  function getTimerSession () {
    clockTitle.textContent = 'Session';
    displayTime(timer, display);
    timer = timer - step;
    state = Object.assign(state, {
      session: timer,
      status: 'session'
    });

    if (timer < 0) {
      resetInterval ();

      timer = state.break;
      startBreak();
    }
  }

  function getTimerBreak () {
    clockTitle.textContent = 'Break';
    displayTime(timer, display);
    timer = timer - step;
    state = Object.assign(state, {
      break: timer,
      status: 'break'
    });

    if (timer < 0) {
      resetInterval ();

      timer = state.session;
      startSession();
    }
  }

  function startSession (inmediately) {
    state = Object.assign(state, {
      interval: setInterval(getTimerSession, step * 1000),
      running: true
    });

    inmediately && getTimerSession();
  }

  //break
  function startBreak (inmediately) {
    state = Object.assign(state, {
      interval: setInterval(getTimerBreak, step * 1000),
      running: true
    });

    inmediately && getTimerBreak();
  }

  var timer = duration;
  var step = 1;

  if (state.status === 'session') {
    startSession(true);
  } else {
    startBreak(true);
  }
}

function stopTimer () {
  clearInterval(state.interval);

  state = Object.assign(state, {
    interval: null,
    running: false
  });
}

function getDuration () {
  var duration;
  if (state.status === 'session') {
    duration = state.session;
  } else {
    duration = state.break;
  }
  return duration;
}

action.addEventListener('click', function () {
  if (state.running) {
    action.classList.remove('is-clicked');
    stopTimer();
  } else {
    action.classList.add('is-clicked');
    startCountDown(getDuration(), display);
  }
});

function increment (what, value) {
  defaultState[what] += value;
  defaultState[what] = Math.min(defaultState[what], 30 * ONE_MINUTE);
  state = Object.assign(state, defaultState);
}

function decrement (what, value) {
  defaultState[what] -= value;
  defaultState[what] = Math.max(defaultState[what], 1 * ONE_MINUTE);
  state = Object.assign(state, defaultState);
}

sessionDecrement.addEventListener('click', function () {
  decrement('session', ONE_MINUTE);
  sessionLength.innerHTML = state.session / ONE_MINUTE;
  !state.running && displayTime(state.session, time);
});

sessionIncrement.addEventListener('click', function () {
  increment('session', ONE_MINUTE);
  sessionLength.innerHTML = state.session / ONE_MINUTE;
  !state.running && displayTime(state.session, time);
});

breakDecrement.addEventListener('click', function () {
  decrement('break', ONE_MINUTE);
  breakLength.innerHTML = state.break / ONE_MINUTE;
});

breakIncrement.addEventListener('click', function () {
  increment('break', ONE_MINUTE);
  breakLength.innerHTML = state.break / ONE_MINUTE;
});

displayTime(state.session, display);
breakLength.innerHTML = state.break / ONE_MINUTE;
sessionLength.innerHTML = state.session / ONE_MINUTE;

              
            
!
999px

Console