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. 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


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.


                <!DOCTYPE html>
<html lang="en">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" type="text/css" href="css/styles.css">
  <title>Analog Clock</title>

  <div class="clock">
    <div class="hand hour"></div>
    <div class="hand minute"></div>
    <div class="hand second"></div>

  <script type="text/javascript" src="js/script.js"></script>


                body {
  min-width: 100vw;
  min-height: 100vh;
  overflow: hidden;
  background-color: #2948ff;
  display: flex;
  justify-content: center;
  align-items: center;

/* clock */

.clock {
  width: 300px;
  height: 300px;
  background-color: #73ff00;
  border-radius: 50%;
  border: 8px solid #000;
  box-shadow: 2px 2px 8px 2px rgba(22, 45, 75, 0.92);
  background-image: url('');
  background-size: cover;
  position: relative;

/* clock style ends */

/* round center */

.clock::before {
  content: '';
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background-color: #000;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 999;

/* round center style ends */

/* common style for every hand */

.hand {
  position: absolute;
  bottom: 50%;
  left: 50%;
  transform: translateX(-50%) rotate(90deg);
  transform-origin: bottom;
  border-top-left-radius: 7px;
  border-top-right-radius: 7px;

/* common style ends */

/* hour hand */

.hour {
  width: 8px;
  height: 28%;
  background-color: #000;

/* hour hand style ends */
/* minute hand style */

.minute {
  width: 5px;
  height: 38%;
  background-color: #000;

/* minute hand style ends */
/* second hand style */

.second {
  width: 3px;
  height: 40%;
  background-color: #ff0000;

/* second hand style ends */


                // grab a reference of every hands

// hour hand
let hourHand = document.querySelector('.hour');
// minute hand 
let minuteHand = document.querySelector('.minute');
// second hand
let secondHand = document.querySelector('.second');

// function that rotates the hands
function rotate() {
  // get the current Date object from which we can obtain the current hour, minute and second
  const currentDate = new Date();

  // get the hours, minutes and seconds
  const hours = currentDate.getHours();
  const minutes = currentDate.getMinutes();
  const seconds = currentDate.getSeconds();

  // rotating fraction --> how many fraction to rotate for each hand.
  const secondsFraction = seconds / 60;
  const minutesFraction = (secondsFraction + minutes) / 60;
  const hoursFraction = (minutesFraction + hours) / 12;

  // actual deg to rotate
  const secondsRotate = secondsFraction * 360;
  const minutesRotate = minutesFraction * 360;
  const hoursRotate = hoursFraction * 360;

  // apply the rotate style to each element
  // use backtick `` instead of single quotes '' = `rotate(${secondsRotate}deg)`; = `rotate(${minutesRotate}deg)`; = `rotate(${hoursRotate}deg)`;

// for every 1000 milliseconds(ie, 1 second) interval, activate the rotate() function.
setInterval(rotate, 1000);