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

              
                
<body>
    <div class="clock">
        <div class="hand hour" id="hand hour"></div>
        <div class="hand minute" id="hand minute"></div>
        <div class="hand second" id="hand second"></div>
        <div class="number number1">1</div>
        <div class="number number2">2</div>
        <div class="number number3">3</div>
        <div class="number number4">4</div>
        <div class="number number5">5</div>
        <div class="number number6">6</div>
        <div class="number number7">7</div>
        <div class="number number8">8</div>
        <div class="number number9">9</div>
        <div class="number number10">10</div>
        <div class="number number11">11</div>
        <div class="number number12">12</div>
      </div>
       
    <script src="index.js"></script>
</body>

              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css2?family=Roboto:wght@700;900&display=swap');


*, *::after, *::before {
    box-sizing: border-box;
}
  
body {
    background: rosybrown;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden;
    font-family: "Roboto", sans-serif;
}
  
.clock {
    width: 300px;
    height: 300px;
    background-color: #d4f542;
    border-radius: 50%;
    border: 4px solid black;
    position: relative;
}
  
.number {
    --rotation: 0;
    position: absolute;
    width: 100%;
    height: 100%;
    text-align: center;
    transform: rotate(var(--rotation));
    font-size: 2.5rem;
    font-weight: bold;
}
  
.number1 { --rotation: 30deg; }
.number2 { --rotation: 60deg; }
.number3 { --rotation: 90deg; }
.number4 { --rotation: 120deg; }
.number5 { --rotation: 150deg; }
.number6 { --rotation: 180deg; }
.number7 { --rotation: 210deg; }
.number8 { --rotation: 240deg; }
.number9 { --rotation: 270deg; }
.number10 { --rotation: 300deg; }
.number11 { --rotation: 330deg; }
  
.hand {
    --rotation: 0;
    position: absolute;
    bottom: 50%;
    left: 50%;
    border: 1px solid white;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    transform-origin: bottom;
    z-index: 10;
    transform: translateX(-50%) rotate(calc(var(--rotation) * 1deg));
}

.clock::after {
    content: '';
    position: absolute;
    background-color: black;
    z-index: 11;
    width: 15px;
    height: 15px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    border-radius: 50%;
}

.clock .hand.second {
    width: 3px;
    height: 45%;
    background-color: red;
}

.clock .hand.minute {
    width: 7px;
    height: 40%;
    background-color: black;
}

.clock .hand.hour {
    width: 10px;
    height: 35%;
    background-color: black;
}
              
            
!

JS

              
                setInterval(clock, 1000);

const hourHand = document.getElementById("hand hour");
const minuteHand = document.getElementById("hand minute");
const secondHand = document.getElementById("hand second");



function clock() {
    const currentDate = new Date();
    const secondsRatio = currentDate.getSeconds() / 60;
    const minutesRatio = (secondsRatio + currentDate.getMinutes()) / 60;
    const hoursRatio = (minutesRatio + currentDate.getHours()) / 12;
    setRotation(secondHand, secondsRatio);
    setRotation(minuteHand, minutesRatio);
    setRotation(hourHand, hoursRatio);
}

function setRotation(element, rotationRatio) {
  element.style.setProperty('--rotation', rotationRatio * 360);
}

clock();
              
            
!
999px

Console