<label for="size">Document font size: <span id="current-size">16</span>px</label>
<input id="size" type="range" min="8" max="64" value="16" step="1">

<p class="in-rem">I am a paragraph at 1rem</p>

<p class="in-px">I am a paragraph at 16px</p>

<div class="container">
	<div class="box in-rem">This box is 10rem</div>
	<div class="box in-px">This box is 160px</div>
</div>

<div class="container">
	<div class="border in-rem">This border is 0.5rem</div>
	<div class="border in-px">This border is 8px</div>
</div>
.in-rem {
	font-size: 1rem;
}

.in-px {
	font-size: 16px;
}

label, input {
	display: block;
	font-size: 16px;
}

.box,
.border {
	width: 10rem;
	height: 10rem;
	aspect-ratio: 1 / 1;
	display: flex;
	justify-content: center;
	align-items: center;
	background: lightskyblue;
	padding: 16px;
}

.box.in-px {
	width: 160px;
	height: 160px;
	font-size: 16px;
}

.border {
	background: none;
	font-size: 16px;
}

.border.in-px {
	border: 8px solid;
}

.border.in-rem {
	border: 0.5rem solid;
}

#size {
	margin: 0;
	padding: 0;
	height: 16px;
}

.container {
	display: flex;
	gap: 20px;
	margin-bottom: 20px;
}

* {
	box-sizing: border-box;
	line-height: 1.2;
	width: 100%;
}

body {
	line-height: 24px;
	padding: 24px;
}
const slider = document.querySelector('#size')
const currentSizeEl = document.querySelector('#current-size')
const root = document.documentElement

slider.addEventListener('input', (e) => {
	root.style.fontSize = `${e.target.value}px`
	currentSizeEl.innerText = e.target.value
})

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.