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

              
                <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="style.css">
<script src="script.js"></script>
    <title>25+5 Clock</title>
</head>
<body>
    <div id="clock">
        <div id="session-label">Session</div>
        <div id="time-left">25:00</div>
        <button id="start-stop" onclick="toggleTimer()">Start</button>
        <button id="reset" onclick="resetTimer()">Reset</button>
        <div id="break-label">Break</div>
        <div id="break-time">5:00</div>
    </div>
</body>
</html>
              
            
!

CSS

              
                body {
    font-family: 'Arial', sans-serif;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    margin: 0;
    background-color: #a1d3ff; 
}

#clock {
    text-align: center;
    background-color: #fff;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

#time-left, #break-time {
    font-size: 2em;
    margin: 10px;
    color: #333;
}

button {
    margin: 10px;
    padding: 10px 20px;
    font-size: 1em;
    cursor: pointer;
    background-color: #45a049; 
    color: #fff;
    border: none;
    border-radius: 5px;
    transition: background-color 0.3s;
}

button:hover {
    background-color: #ff6f61; 
}
              
            
!

JS

              
                let timer;
let isRunning = false;

function toggleTimer() {
    if (isRunning) {
        clearInterval(timer);
        isRunning = false;
        document.getElementById("start-stop").textContent = "Start";
    } else {
        timer = setInterval(decrementTime, 1000);
        isRunning = true;
        document.getElementById("start-stop").textContent = "Stop";
    }
}

function decrementTime() {
    let timeLeft = document.getElementById("time-left");
    let timeArr = timeLeft.textContent.split(":");
    let minutes = parseInt(timeArr[0]);
    let seconds = parseInt(timeArr[1]);

    if (minutes === 0 && seconds === 0) {
        clearInterval(timer);
        isRunning = false;
        document.getElementById("start-stop").textContent = "Start";
       
        startBreak();
    } else {
        if (seconds === 0) {
            minutes--;
            seconds = 59;
        } else {
            seconds--;
        }

        timeLeft.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
    }
}

function startBreak() {
    let breakTime = document.getElementById("break-time");
    let breakArr = breakTime.textContent.split(":");
    let minutes = parseInt(breakArr[0]);
    let seconds = parseInt(breakArr[1]);

    timer = setInterval(function () {
        if (minutes === 0 && seconds === 0) {
            clearInterval(timer);
            isRunning = false;
            document.getElementById("start-stop").textContent = "Start";
            
            resetTimer();
        } else {
            if (seconds === 0) {
                minutes--;
                seconds = 59;
            } else {
                seconds--;
            }

            breakTime.textContent = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
        }
    }, 1000);
}

function resetTimer() {
    clearInterval(timer);
    isRunning = false;
    document.getElementById("start-stop").textContent = "Start";
    document.getElementById("time-left").textContent = "25:00";
    document.getElementById("break-time").textContent = "5:00";
}
              
            
!
999px

Console