# Torque Dial

> A rotary knob you can twist, flick with momentum, scroll or drive from the keyboard.

- Kind: Element
- Page: https://ownlyplans.com/bhaskar/torque-dial/
- Licence: MIT (do anything, keep the notice)

## Code

`index.html`

```html
<!--
  MIT License
  Copyright (c) 2026 Suraj Maurya
  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  documentation files (the "Software"), to deal in the Software without restriction, including without limitation
  the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
  to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  The above copyright notice and this permission notice shall be included in all copies or substantial portions
  of the Software.
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
-->
<div class="td-stage">
  <div class="td-row">
    <div class="td" data-label="Volume" data-value="64" data-min="0" data-max="100" data-step="1" data-unit="%"></div>
    <div class="td" data-label="Temperature" data-value="21" data-min="10" data-max="30" data-step="0.5" data-unit="°C" data-color="#f97316"></div>
    <div class="td" data-label="Gain" data-value="-6" data-min="-24" data-max="12" data-step="1" data-unit=" dB" data-color="#34d399"></div>
  </div>
</div>
```

`styles.css`

```css
.td-stage{width:100%;min-height:calc(100vh - 40px);display:grid;place-items:center;padding:24px 14px;border-radius:16px;background:#111113;font-family:Inter,system-ui,-apple-system,"Segoe UI",sans-serif}
.td-row{display:flex;flex-wrap:wrap;justify-content:center;gap:36px}
.td{display:inline-flex;flex-direction:column;align-items:center;user-select:none}
.td-knob{position:relative;display:flex;align-items:center;justify-content:center;width:120px;height:120px;border-radius:50%;outline:none;cursor:grab;touch-action:none;transition:box-shadow .2s}
.td-knob:active{cursor:grabbing}
.td-knob:focus-visible{box-shadow:0 0 0 2px #fff}
.td-knob svg{position:absolute;inset:0;width:100%;height:100%;pointer-events:none}
.td-track{fill:none;stroke:#1F1F1F;stroke-width:5;stroke-linecap:round}
.td-fill{fill:none;stroke-width:5;stroke-linecap:round}
.td-cap{position:relative;display:flex;align-items:center;justify-content:center;width:65%;height:65%;border:1px solid #1F1F1F;border-radius:50%;background:radial-gradient(circle at 35% 30%,#1c1c1c,#121212);box-shadow:0 1px 2px rgba(0,0,0,.4),inset 0 1px 0 rgba(255,255,255,.04);transition:border-color .2s,box-shadow .2s}
.td.drag .td-cap{border-color:color-mix(in srgb,var(--c) 60%,transparent);box-shadow:0 0 15px color-mix(in srgb,var(--c) 22%,transparent)}
.td-pip{position:absolute;top:8px;width:6px;height:12px;border-radius:999px;background:var(--c)}
.td-hub{width:16px;height:16px;border:1px solid #1F1F1F;border-radius:50%;background:#0E0E0E}
.td-val{margin-top:12px;color:#FAFAFA;font:600 14px ui-monospace,SFMono-Regular,Menlo,monospace;letter-spacing:-.01em;font-variant-numeric:tabular-nums;text-align:center}
.td-lab{color:#6B6B6B;font:10px ui-monospace,SFMono-Regular,Menlo,monospace}
.td.off{opacity:.4}.td.off .td-knob{cursor:not-allowed}
@media (max-width:480px){.td-row{gap:20px}.td-knob{width:96px;height:96px}}
```

`script.js`

```js
(function(){
  var R=40,CIRC=2*Math.PI*R,ARC=CIRC*270/360,reduce=matchMedia('(prefers-reduced-motion: reduce)').matches;
  document.querySelectorAll('.td').forEach(function(root){
    var d=root.dataset,min=+d.min||0,max=d.max!=null?+d.max:100,step=+d.step||1,unit=d.unit||'',label=d.label||'Dial control',val=+d.value,drag=false,lastA=0,vel=0,mom=null,shown=null,sv=0,raf=null,dec=(String(step).split('.')[1]||'').length;
    root.style.setProperty('--c',d.color||'#3B82F6');
    root.innerHTML='<div class="td-knob" role="slider" tabindex="0"><svg viewBox="0 0 100 100" aria-hidden="true"><circle class="td-track" cx="50" cy="50" r="'+R+'" stroke-dasharray="'+ARC+' '+CIRC+'" transform="rotate(135 50 50)"/><circle class="td-fill" cx="50" cy="50" r="'+R+'" stroke="'+(d.color||'#3B82F6')+'" stroke-dasharray="'+ARC+' '+CIRC+'" transform="rotate(135 50 50)"/></svg><div class="td-cap"><span class="td-pip"></span><div class="td-hub"></div></div></div><div class="td-val"></div><span class="td-lab"></span>';
    var knob=root.querySelector('.td-knob'),fill=root.querySelector('.td-fill'),cap=root.querySelector('.td-cap'),out=root.querySelector('.td-val');
    root.querySelector('.td-lab').textContent=label;knob.setAttribute('aria-label',label);knob.setAttribute('aria-valuemin',min);knob.setAttribute('aria-valuemax',max);
    function clamp(v){var s=Math.round((v-min)/step)*step+min;return Math.min(max,Math.max(min,+s.toFixed(4)));}
    function prog(v){return Math.min(1,Math.max(0,(v-min)/(max-min||1)));}
    function draw(p){fill.setAttribute('stroke-dashoffset',ARC*(1-p));cap.style.transform='rotate('+(-135+p*270)+'deg)';}
    function set(v){v=clamp(v);if(v===val&&shown!==null)return;val=v;out.textContent=val.toFixed(dec)+unit;knob.setAttribute('aria-valuenow',val);knob.setAttribute('aria-valuetext',val.toFixed(dec)+unit);
      var t=prog(val);if(drag||reduce||shown===null){shown=t;sv=0;draw(t);return;}
      if(raf==null){var lt=performance.now();raf=requestAnimationFrame(function f(now){var dt=Math.min(.05,(now-lt)/1000);lt=now;var tt=prog(val);for(var s=0;s<dt;s+=.004){sv+=(-380*(shown-tt)-30*sv)*.004;shown+=sv*.004;}draw(shown);if(Math.abs(shown-tt)>.0005||Math.abs(sv)>.005)raf=requestAnimationFrame(f);else{shown=tt;draw(tt);raf=null;}});}}
    function ang(x,y){var r=knob.getBoundingClientRect(),a=Math.atan2(y-(r.top+r.height/2),x-(r.left+r.width/2))*180/Math.PI+90;return a>180?a-360:a;}
    var acc=val;
    knob.addEventListener('pointerdown',function(e){if(mom){cancelAnimationFrame(mom);mom=null;}drag=true;root.classList.add('drag');lastA=ang(e.clientX,e.clientY);vel=0;acc=val;knob.setPointerCapture(e.pointerId);knob.focus({preventScroll:true});});
    knob.addEventListener('pointermove',function(e){if(!drag)return;var a=ang(e.clientX,e.clientY),da=a-lastA;if(da>180)da-=360;if(da<-180)da+=360;lastA=a;vel=da;acc=Math.min(max,Math.max(min,acc+da/270*(max-min)));set(acc);});
    function up(){if(!drag)return;drag=false;root.classList.remove('drag');if(!reduce&&Math.abs(vel)>.4){var v=vel;mom=requestAnimationFrame(function f(){v*=.92;if(Math.abs(v)>.05){acc=Math.min(max,Math.max(min,acc+v/270*(max-min)));drag=true;set(acc);drag=false;mom=requestAnimationFrame(f);}else mom=null;});}}
    knob.addEventListener('pointerup',up);knob.addEventListener('pointercancel',up);
    knob.addEventListener('wheel',function(e){e.preventDefault();set(val+(e.deltaY<0?step:-step));acc=val;},{passive:false});
    knob.addEventListener('keydown',function(e){var k=e.key;if(k==='ArrowRight'||k==='ArrowUp')set(val+step);else if(k==='ArrowLeft'||k==='ArrowDown')set(val-step);else if(k==='PageUp')set(val+step*10);else if(k==='PageDown')set(val-step*10);else if(k==='Home')set(min);else if(k==='End')set(max);else return;e.preventDefault();acc=val;});
    knob.addEventListener('dblclick',function(){set((max+min)/2);acc=val;});
    set(val);
  });
})();
```

## About

A tactile rotary control for volume, gain, temperature or any value in a range. Drag around the knob to turn it, and a quick flick keeps it spinning with momentum that slows under friction. The scroll wheel steps it, arrow keys nudge it, Home and End jump to the limits, and a double-click resets to the middle. A blue arc fills the 270° track and the notch on the knob points to the value, both easing with a spring when you are not dragging. It is a proper slider for assistive tech with min, max and current value announced.

---
Also available as JSON: https://ownlyplans.com/bhaskar/torque-dial/?format=json
MCP server: https://ownlyplans.com/mcp
