Pen Settings



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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


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


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.


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.


    <title>Countdown Timer</title>

    <div class="timer">
      <div class="timer__controls">
        <button data-time="20" class="timer__button">20 secs</button>
        <button data-time="300" class="timer__button">Work 5</button>
        <button data-time="900" class="timer__button">Work 15</button>
        <button data-time="1200" class="timer__button">Work 20</button>
        <button data-time="3600" class="timer__button">Break</button>
        <form name="customForm" id="custom">
          <input type="text" name="minutes" placeholder="Enter minutes">
      <div class="display">
        <h1 class="display__time-left"></h1>
        <p class="display__end-time"></p>
      <h4 style="color: white">Video tutorial <a href="" target="_blank">here</a></h4>



                html {
  box-sizing: border-box;
  font-size: 10px;
  background: blueviolet;

body {
  margin: 0px;
  text-align: center;
  font-family: monospace;

.timer {
  display: flex;
  min-height: 100vh;
  flex-direction: column;

.timer__controls {
  display: flex;

.timer__controls > * {
  flex: 1;

.timer__controls form {
  flex: 1;
  display: flex;

.timer__controls input {
  flex: 1;
  border: 0;
  padding: 2rem;

.timer__button {
  background: none;
  border: 0;
  cursor: pointer;
  color: white;
  font-size: 2rem;
  text-transform: uppercase;
  border-bottom: 3px solid rgba(0,0,0,0.2);
  border-right: 1px solid rgba(0,0,0,0.2);
  padding: 1rem;
  font-family: monospace;

.timer__button:focus {
  background: rgba(0,0,0,0.2);
  outline: 0;

.display {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;

.display__time-left {
  font-weight: 100;
  font-size: 20rem;
  margin: 0;
  color: white;

.display__end-time {
  color: white;
  font-size: 4rem;



                let countdown;
const timerDisplay = document.querySelector('.display__time-left');
const endTime = document.querySelector('.display__end-time');
const buttons = document.querySelectorAll('[data-time]');

function timer(seconds) {
  // clear any existing timers

  const now =;
  const then = now + seconds * 1000;

  countdown = setInterval(() => {
    const secondsLeft = Math.round((then - / 1000);
    // check if we should stop it!
    if(secondsLeft < 0) {
    // display it
  }, 1000);

function displayTimeLeft(seconds){
	const minutes = Math.floor(seconds/60);
	const remainderSeconds = seconds % 60; 
	const display = `${minutes}:${remainderSeconds < 10 ? '0' : '' }${remainderSeconds}`;``
	document.title = display;
	timerDisplay.textContent = display;

function displayEndTime(timestamp){
	const end = new Date(timestamp);
	const hour = end.getHours();
	const minutes = end.getMinutes();
	endTime.textContent = `Be Back At ${hour}:${minutes}`;

function startTimer() {
  const seconds = parseInt(this.dataset.time);

buttons.forEach(button => button.addEventListener('click', startTimer));

document.customForm.addEventListener('submit', function(e) {
  const mins = this.minutes.value;
  timer(mins * 60);