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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

This tutorial is part of the 30 Day Vanilla JS Coding Challenge. To learn more, please visit

<DOCTYPE html>
<html lang="en">
  <meta charset="UTF-8">
  <title>JS + CSS Clock</title>
	<div class="clock">
    <div class="clock-face">
     	<div class="hand hour-hand"></div>
     	<div class="hand min-hand"></div>
     	<div class="hand second-hand"></div>
              html {
	background: linear-gradient(to right, #b7b7fa 50%, #b7fafa 50%);
  font-family: 'helvetica neue';
  text-align: center;
  font-size: 10px;
body {
	margin: 0;
	font-size: 2rem;
	display: flex;
	flex: 1;
	min-height: 100vh;
	align-items: center;
	justify-content: center;

.clock {
	width: 30rem;
	height: 30rem;
	border: 20px solid #ffffff;
	border-radius: 50%;
	margin: 50px auto;
	position: relative;
	padding: 2rem;
		0 0 0 4px rgba(0,0,0,0.1),
		inset 0 0 0 3px #EFEFEF,
		inset 0 0 10px #000000,
		0 0 10px rgba(0,0,0,0.2);

.clock-face {
	position: relative;
	width: 100%;
	height: 100%;
	transform: translateY(-3px); /* account for the height of the clock hands */

.hour-hand {
	width: 40%;
	height: 6px;
	left: 10%;
	/* add left 10% because the hour hand is 10% shorter than the other clock hands.*/	

.min-hand {
	width: 50%;
	height: 6px;

.second-hand {
	width: 50%;
	height: 3px;

.hand {	
	position: absolute;
	top: 50%;
	background-color: rgba(0, 0, 0, 1);
	transform: rotate(90deg);
		/* Rotates each hand div to ensure our clock hands display vertically.*/
	transform-origin: 100%;
	transition: all 0.5s;
	transition-timing-function: cubic-bezier(0.1, 2.7, 0.58, 1);
	To create the ticking effect:
	- Set the transition rotation (for all properties receiving a transition) to every 0.5 seconds. 
	- Set the transition timing to a cubic-bezier to give the tick a slight forward-back motion.
              const secondHand = document.querySelector('.second-hand');
const minsHand = document.querySelector('.min-hand');
const hourHand = document.querySelector('.hour-hand');

function setDate() {
	const now = new Date ();
	const seconds = now.getSeconds();
	const secondsDegrees = ((seconds / 60) * 360) + 90; = `rotate(${secondsDegrees}deg)`;
	adding the 90 degrees to const secondsDegrees offsets the 90 deg rotation we set in the styles
	const mins = now.getMinutes();
	const minsDegrees = ((mins / 60) * 360) + 90; = `rotate(${minsDegrees}deg)`;
	const hour = now.getHours();
	const hourDegrees = ((hour / 12) * 360) + 90; = `rotate(${hourDegrees}deg)`;

setInterval(setDate, 1000);
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.