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

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

              
                <main>
	<div class="clock" role="img" aria-label="Analog clock">
		<div class="clock__inner-frame"></div>
		<div class="clock__ticks">
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
			<div class="clock__tick"></div>
		</div>
		<div class="clock__digits">
			<div class="clock__digit">1</div>
			<div class="clock__digit">2</div>
			<div class="clock__digit">3</div>
			<div class="clock__digit">4</div>
			<div class="clock__digit">5</div>
			<div class="clock__digit">6</div>
			<div class="clock__digit">7</div>
			<div class="clock__digit">8</div>
			<div class="clock__digit">9</div>
			<div class="clock__digit">10</div>
			<div class="clock__digit">11</div>
			<div class="clock__digit">12</div>
		</div>
		<div class="clock__text">
			<em>Radio Controlled</em>
		</div>
		<div class="clock__hands">
			<div class="clock__hand clock__hand--hr"></div>
			<div class="clock__hand clock__hand--min"></div>
			<div class="clock__hand clock__hand--sec"></div>
		</div>
	</div>
</main>
              
            
!

CSS

              
                @mixin handRotate($iteration,$iterations,$maxPct: 100%)
	$frac: $iteration / $iterations
	#{($maxPct * $frac)}
		transform: rotate(-360deg * (($iterations - 1) / $iterations) * $iteration)

$hue: 223

*
	border: 0
	box-sizing: border-box
	margin: 0
	padding: 0

\:root
	--bg: #{hsl($hue,10%,90%)}
	--fg: #{hsl($hue,10%,10%)}
	font-size: calc(16px + (24 - 16) * (100vw - 320px) / (1280 - 320))

body
	background: var(--bg)
	color: var(--fg)
	font: 1em/1.5 -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Helvetica, sans-serif
	height: 100vh
	display: grid
	place-items: center
main
	padding: 1.5em 0

.clock
	background: radial-gradient(100% 100% at 50% 10%,hsl($hue,10%,50%),hsl($hue,10%,10%) 50%)
	border-radius: 50%
	box-shadow: 0 0.5em 1em hsla(0,0%,0%,0.5)
	position: relative
	width: 15em
	height: 15em
	&__inner-frame,
	&__ticks,
	&__tick,
	&__digits,
	&__digit,
	&__text,
	&__hands,
	&__hand,
	&__hand-trail
		position: absolute
	&__inner-frame,
	&__ticks,
	&__digits,
	&__hands
		border-radius: inherit
	&__inner-frame
		background: linear-gradient(hsl($hue,10%,60%),hsl($hue,10%,80%))
		box-shadow: 0 0.1em 0 hsl(0,0%,80%) inset
		top: 1em
		left: 1em
		width: 13em
		height: 13em	
	&__ticks
		background: linear-gradient(hsl($hue,10%,90%),hsl($hue,10%,100%))
		box-shadow: 0 0.5em 0.5em 0.75em hsla(0,0%,0%,0.2) inset, 0 0 0 0.15em hsl($hue,10%,10%)
		top: 1.5em
		left: 1.5em
		width: 12em
		height: 12em
	&__tick,
	&__hand
		background: currentColor
	&__tick
		bottom: 50%
		left: calc(50% - 0.025em)
		width: 0.05em
		min-width: 1px
		height: 0.25em
		transform-origin: 50% 100%
		&:nth-child(5n + 1)
			left: calc(50% - 0.05em)
			width: 0.1em
			min-width: 2px
			height: 0.5em	
		$ticks: 60
		$transY: -5.5em
		@for $t from 1 through $ticks
			$transYAdj: $transY
			@if $t % 5 == 1
				$transYAdj: $transY + 0.25
			&:nth-child(#{$t})
				transform: rotate(360deg/$ticks * ($t - 1)) translateY($transYAdj)
	&__digits
		top: 2.5em
		left: 2.5em
		width: 10em
		height: 10em
	&__digit
		font-size: 1.5em
		line-height: 1
		letter-spacing: -0.05em
		text-align: center
		top: calc(50% - 0.75rem)
		left: calc(50% - 1.25rem)
		width: 2.5rem
		height: 1.5rem
		@for $t from 1 through 12
			&:nth-child(#{$t})
				transform: rotate(30deg * $t) translateY(-4.25rem) rotate(-30deg * $t)
	&__text
		font-size: 0.4em
		text-align: center
		text-transform: uppercase
		top: 65%
		left: 0
		width: 100%
	&__hands
		filter: drop-shadow(0 0.5em 0.1em hsla(0,0%,0%,0.3))
		top: 2.5em
		left: 2.5em
		width: 10em
		height: 10em
	&__hand
		$timing: cubic-bezier(0.8,0,0.2,1)
		&--hr
			animation: hrHand 86400s $timing infinite
			border-radius: 0 0 0.2em 0.2em
			bottom: calc(50% - 0.2em)
			left: calc(50% - 0.2em)
			width: 0.4em
			height: 3.25em
			transform-origin: 50% calc(100% - 0.2em)
		&--min
			animation: longHand 3600s $timing infinite
			border-radius: 0 0 0.15em 0.15em
			bottom: calc(50% - 0.15em)
			left: calc(50% - 0.15em)
			width: 0.3em
			height: 5em
			transform-origin: 50% calc(100% - 0.15em)
		&--sec
			animation: longHand 60s $timing infinite
			bottom: calc(50% - 1.5em)
			left: calc(50% - 0.1em)
			width: 0.2em
			height: 6.5em
			transform-origin: 50% calc(100% - 1.5em)
			&:before
				background-color: inherit
				border-radius: 50%
				content: ""
				display: block
				position: absolute
				bottom: 1.3em
				left: calc(50% - 0.2em)
				width: 0.4em
				height: 0.4em

/* Dark theme */
@media (prefers-color-scheme: dark)
	\:root
		--bg: #{hsl($hue,10%,20%)}
		--fg: #{hsl($hue,10%,90%)}
	.clock
		background: radial-gradient(100% 100% at 50% 10%,hsl($hue,10%,100%),hsl($hue,10%,60%) 50%)
		&__inner-frame
			background: linear-gradient(hsl($hue,10%,30%),hsl($hue,10%,50%))
			box-shadow: 0 0.1em 0 hsl(0,0%,60%) inset
		&__ticks
			background: linear-gradient(hsl($hue,10%,10%),hsl($hue,10%,20%))

/* Animations */
@keyframes hrHand
	@for $h from 0 through 24
		@include handRotate($h,12,50%)
@keyframes longHand
	@for $l from 0 through 60
		@include handRotate($l,60)
              
            
!

JS

              
                window.addEventListener("DOMContentLoaded",() => {
	const clock = new ReverseClock(".clock");
});

class ReverseClock {
	constructor(qs,h,m,s,ms) {
		const el = document.querySelector(qs);
		const msInSec = 1000;
		const msInMin = msInSec * 60;
		const msInHr = msInMin * 60;
		const msInDay = msInHr * 24;
		const date = new Date();

		let time = (h === undefined ? date.getHours() : h) * msInHr;
		time += (m === undefined ? date.getMinutes() : m) * msInMin;
		time += (s === undefined ? date.getSeconds() : s) * msInSec;
		time += ms === undefined ? date.getMilliseconds() : ms;

		if (el) {
			const handCl = ".clock__hand";
			const hr = el.querySelector(`${handCl}--hr`);
			const min = el.querySelector(`${handCl}--min`);
			const sec = el.querySelector(`${handCl}--sec`);

			if (hr) {
				const hrDelay = (msInDay * ((time % msInDay) / msInDay)) / msInSec;
				hr.style.animationDelay = `${-hrDelay}s`;
			}
			if (min) {
				const minDelay = (msInHr * ((time % msInHr) / msInHr)) / msInSec;
				min.style.animationDelay = `${-minDelay}s`;
			}
			if (sec) {
				const secDelay = (msInMin * ((time % msInMin) / msInMin)) / msInSec;
				sec.style.animationDelay = `${-secDelay}s`;
			}
		}
	}
}
              
            
!
999px

Console