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

              
                main
  h1 Pomodoro Clock
  .settings
    .break-time.time
      h2 Break Length
      button -
      span.display 5
      button +
    .session-time.time
      h2 Session Length
      button -
      span.display 25
      button +
  .session
    h2 Session
    span.display 
    button.startpause Start
    button.reset Reset
              
            
!

CSS

              
                body
  min-height: 100vh
  display: flex
  justify-content: center
  align-items: center
  background-color: lightcyan
  font-family: sans-serif
  font-weight: bold
  text-align: center
  
main
  box-sizing: border-box
  background-color: #fff
  padding: 1em 3em 3em
  border-radius: 2px
  max-width: 500px
  display: flex
  justify-content: space-around
  flex-wrap: wrap
  
button
  font-size: 120%
  font-weight: bold
  border: none
  background-color: lightcyan
  &:hover
    cursor: pointer
    background-color: darken(lightcyan, 10%)

h1, .settings, .session
  flex-basis: 100%
  
.display
  background-color: #ddd
  
.settings
  display: flex
  justify-content: space-around
  margin-bottom: 2em
  div
    flex-basis: 45%
  span
    box-sizing: border-box
    display: inline-block
    font-size: 120%
    width: 10ch
    height: 1.9em
    padding-top: 0.3em

.time
  display: flex
  flex-wrap: wrap
  justify-content: center
  h2
    flex-basis: 100%
    
.session
  display: flex
  justify-content: space-around
  flex-wrap: wrap
  flex-basis: 87%
  span
    flex-basis: 100%
    display: inline-block
    box-sizing: border-box
    height: 2em
    padding: 0
    line-height: 2.1
    font-size: 140%
    margin-bottom: 0.4em
  button
    min-width: 10ch
    padding: 0.4em 1em
    border-radius: 2px
              
            
!

JS

              
                var go = true; // for start / pause
var session = true; // for session / break
var paused = false;
var i;

$('.settings button').on('click', function() {
  var $t;
  if (this.innerHTML === '-') {
    $t = $(this).next();
    if (parseInt($t.text(), 10) > 1) {
      $t.text(parseInt($t.text(), 10) - 1);
    }
  } else {
    $t = $(this).prev();
    if (parseInt($t.text(), 10) < 60) {
      $t.text(parseInt($t.text(), 10) + 1);
    }
  }
});

$('.startpause').on('click', function() {
  if (go) {
    $('.startpause').text('Pause');
    if (!paused) {
      if (session) { timer(parseInt($('.session-time .display').text(), 10) * 60); }
      else { timer(parseInt($('.break-time .display').text(), 10) * 60); }
    }
    paused = false
  } else {
    $('.startpause').text('Start');
    paused = true;
  }
  go = !go;
});

$('.reset').on('click', function() {
  var t;
  clearInterval(i);
  if (session) {
    t = parseInt($('.session-time .display').text(), 10) * 60;
    timer(t); 
  } else {
    t = parseInt($('.break-time .display').text(), 10) * 60;
    timer(t); 
  }
  if (paused) {
    if (t % 60 < 10) { 
      t = Math.floor((t / 60)).toString() + ':0' + (t % 60).toString();
    } else {
      t = Math.floor((t / 60)).toString() + ':' + (t % 60).toString();
    }
    $('.session .display').text(t);
  }
});

function countdown(n) {
  var t;
  if (n % 60 < 10) { 
    t = Math.floor((n / 60)).toString() + ':0' + (n % 60).toString();
  } else {
    t = Math.floor((n / 60)).toString() + ':' + (n % 60).toString();
  }
  $('.session .display').text(t);
}

function timer(n) {
  i = window.setInterval(function() {
    if (!paused) {
      countdown(n);
      n--;
    }
    if (n < 0) {
      clearInterval(i);
      session = !session;
      if (session) { 
        $('.session h2').text('Session');
        timer(parseInt($('.session-time .display').text(), 10) * 60);
      } else { 
        $('.session h2').text('Break');
        timer(parseInt($('.break-time .display').text(), 10) * 60);
      }
    }
  }, 1000);
}
              
            
!
999px

Console