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

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

              
                <!DOCTYPE html>
<html lang="en">
<head>
  <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>
</head>
<body>

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

  </div>
  
  <script type="text/javascript" src="js/script.js"></script>
</body>
</html>
              
            
!

CSS

              
                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('https://lh3.googleusercontent.com/K9m2x7ZJRNZXUg989hTxYLrXyQ7bgpBqcCX5L-9_r34Vewds1cyzFBS2rDOkA6JhBcRKAmoXve_ml-dh1th_UWvAHvldy8IEbMvb3vmiEXAEY0oUVcWusihCkvX5otr6I_YzAeeiWC1I6G-LuPlpSeMwZCJC3RodB43wxtk_AR-Tvf3JGzsFZB5EY-G1cpdq7vmbE-s6wWHB47WscrukY1EW1WSUWSjcfrWS3RDPGR9EEX7qMTUe7upP4PG9zQzEdMRIQ6esFhB2fO6v-cTwG3UQjy0bd1AdjRbTU24QQvp0NfqHwLPwpR6YPfrHhckKzrJIRXtsBNSF99NtoN7HiuKkFbuUPkLM0ZT-llEIWsQiyiU_iDgmRDspXcP6vZkeCDTJhpRRkLzrWjBhlRFQLwyVgtveWCRM05Df_in1Yf6dC16iw5uXU35FyYd3jWIiJMlO2c1uoHd5hlmpiZgo8Gu-KXQYDoz7liojGfqD03qpryjaPc_oxEMWFFZYpawNqWdOMWiw5G8RqiMlxACEkZOSM_MvfiRkF3LkVDCZDgcF_6lxiepDounK6R7JzU255TFAdhg_upt4JDBK8MMTdHjDECV9ppnmjoo9MOTd0wim28_O7mB8VhnwkR3EVjCcPYYhqI1y0PHBRYl4tp3nkHSrQDHaOPmGqFsw__waHsNtM8CQrytxBkdhtY8jcw=w639-h638-no?authuser=0');
  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 */
              
            
!

JS

              
                // 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 ''
  secondHand.style.transform = `rotate(${secondsRotate}deg)`;
  minuteHand.style.transform = `rotate(${minutesRotate}deg)`;
  hourHand.style.transform = `rotate(${hoursRotate}deg)`;
}

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

Console