Skip to content

Polar Slider Angle Dial

Pick an angle with a round dial, such as a rotation or a direction. ring with solid makes a filled dial that changes only the angle, center-line draws the hand, the thumb slot holds the knob, and a <datalist> in markers-angle adds ticks that the thumb snaps to.

Since the angle runs clockwise from 0 at the top, like CSS angles, angle works as is in rotate or linear-gradient().

Code

The following example assumes that you have imported the component and set up the theme.

Angle Dial
<!-- eslint-disable html/use-baseline -->
<div class="angle-dial">
24 collapsed lines
<sv-polar-slider
id="angle-dial-slider"
class="dial"
aria-label="Angle"
center-line
ring
solid
value="135"
>
<datalist slot="markers-angle">
<option value="0"></option>
<option value="45"></option>
<option value="90"></option>
<option value="135"></option>
<option value="180"></option>
<option value="225"></option>
<option value="270"></option>
<option value="315"></option>
</datalist>
<div class="knob" slot="thumb"></div>
<output id="angle-dial-output" class="readout"></output>
</sv-polar-slider>
</div>
<script type="application/x-typescript" module>
11 collapsed lines
const dial = document.querySelector<PolarSlider>("#angle-dial-slider")!;
const angleOutput = document.querySelector<HTMLOutputElement>("#angle-dial-output")!;
dial.valueLabelHandler = value => `${value} degrees`;
updateAngle();
dial.addEventListener("valuechange", updateAngle);
function updateAngle() {
angleOutput.value = `${dial.angle}°`;
}
</script>
<style>
38 collapsed lines
.angle-dial {
display: grid;
justify-items: center;
.dial {
--sv-polar-slider-sz: 10em;
--sv-polar-slider-track-thickness: 1.6em;
--sv-polar-slider-thumb-sz: 1.4em;
--sv-polar-slider-marker-offset: 0.6em;
--sv-polar-slider-tick-length: 5px;
}
.knob {
inline-size: 1.1em;
block-size: 1.1em;
background: radial-gradient(circle, var(--sv-accent-content) 18%, var(--sv-accent) 22%);
border-radius: 50% 50% 0;
box-shadow:
0 0 0 2px var(--sv-gray-6),
0 2px 6px rgb(0 0 0 / 35%);
transform: rotate(225deg);
}
.readout {
position: absolute;
inset: 30%;
z-index: 1;
display: grid;
place-content: center;
font-variant-numeric: tabular-nums;
background: var(--sv-gray-5);
border-radius: 50%;
box-shadow:
inset 0 1px 0 rgb(255 255 255 / 8%),
0 2px 4px rgb(0 0 0 / 20%),
0 8px 20px rgb(0 0 0 / 25%);
}
}
</style>