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.


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