Skip to content
animorio
IT
All components

Brush size slider

Sliders, Hover, SVGGSAP, CSS onlyMediumCompressed weight: Demo 8.4 KBGSAP 28 KBFreeDownload the zip

The brush size slider of a made-up drawing app, alone in the middle on white. Drag the handle along a wedge-shaped track, thin on the left and thick on the right, and the freehand stroke in the little canvas above swells and thins on a spring, with the brush tip appearing at its end as a dashed circle. The size in pixels rolls, the handle snaps onto the usual sizes (2, 4, 8, 12, 16, 24, 32, 48) with a little jump of the tick, and pressed it tightens with a blue halo. Also with the minus and plus buttons and the arrow keys.

The code

A folder that runs on its own: index.html, style.css, script.js and the libraries from a CDN. The React and Vue tabs hold the same demo as a ready component, which switches its animations off when it leaves the page.

<!doctype html>
<!--
  "Brush size slider" from Animorio · https://animorio.com
  License: free on your own sites and your clients’ sites, paid work included.
  Not for resale, redistribution, templates or code collections · https://animorio.com/en/license/
-->
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Brush size slider</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/mona-sans@5.3.0/wdth.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fontsource-variable/jetbrains-mono@5.3.0/index.css">
  <link rel="stylesheet" href="style.css">
</head>
<body>
  <main class="stage">
    <!-- the brush size control of a made-up drawing app: drag the handle and the soft stroke above swells and thins,
         the brush tip circle grows at its end, the size in pixels rolls, and the handle snaps onto the usual sizes -->
    <section class="tool" data-tool aria-label="Brush">
      <header class="tool__head">
        <span class="tool__title">
          <svg class="tool__icon" viewBox="0 0 24 24" aria-hidden="true">
            <path class="brush__handle" d="M19.6 3.6c.7.7.7 1.8 0 2.5l-7.4 7.4-2.5-2.5 7.4-7.4c.7-.7 1.8-.7 2.5 0z"></path>
            <path class="brush__tip" d="M9.2 11.6l2.6 2.6c-.4 2.6-2.4 4.4-5.6 4.6-1 .1-2-.3-2.6-.9 1.6-.4 2.2-1.4 2.4-2.8.2-2 1.4-3.3 3.2-3.5z"></path>
          </svg>
          <span data-label>Brush size</span>
        </span>
        <span class="readout" aria-hidden="true">
          <span class="reels" data-reels>
            <span class="reel reel--tens" data-reel="0"><span class="reel__strip"><span>0</span><span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span><span>9</span></span></span>
            <span class="reel" data-reel="1"><span class="reel__strip"><span>0</span><span>1</span><span>2</span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span><span>9</span></span></span>
          </span>
          <span class="readout__unit">px</span>
        </span>
      </header>

      <div class="canvas" aria-hidden="true">
        <svg class="canvas__svg" viewBox="0 0 300 140" preserveAspectRatio="xMidYMid meet">
          <path class="guide" data-guide d="M30 92 C 66 34, 118 30, 146 66 S 220 116, 268 52"></path>
          <path class="stroke__shadow" data-shadow d=""></path>
          <path class="stroke" data-stroke d=""></path>
          <circle class="tipring" data-tipring cx="268" cy="52" r="6"></circle>
        </svg>
      </div>

      <div class="control">
        <button class="step" type="button" data-step="-1" aria-label="Smaller brush" tabindex="-1">
          <svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8h9"></path></svg>
        </button>
        <div class="track" data-track>
          <svg class="track__svg" viewBox="0 0 300 36" preserveAspectRatio="none" aria-hidden="true">
            <defs>
              <clipPath id="fill-clip"><rect data-fillclip x="0" y="0" width="0" height="36"></rect></clipPath>
            </defs>
            <path class="wedge" data-wedge d=""></path>
            <path class="wedge wedge--fill" data-wedgefill d="" clip-path="url(#fill-clip)"></path>
          </svg>
          <div class="ticks" data-ticks aria-hidden="true"></div>
          <div class="handle" data-handle role="slider" tabindex="0" aria-label="Brush size" aria-valuemin="1" aria-valuemax="48" aria-valuenow="12" aria-valuetext="12 pixels">
            <span class="handle__halo" data-halo></span>
            <span class="handle__body" data-body>
              <span class="handle__dot" data-dot></span>
            </span>
          </div>
        </div>
        <button class="step" type="button" data-step="1" aria-label="Bigger brush" tabindex="-1">
          <svg viewBox="0 0 16 16" aria-hidden="true"><path d="M3.5 8h9M8 3.5v9"></path></svg>
        </button>
      </div>
    </section>
  </main>
  <script src="https://cdn.jsdelivr.net/npm/gsap@3.15.0/dist/gsap.min.js"></script>
  <script src="script.js"></script>
</body>
</html>

Playground

Change values, colours and text with the controls and watch the animation respond live. Or write in the code yourself. Then download the folder with your changes.

40 values to change

Works with Claude, Claude Code, ChatGPT, Cursor, VS Code, Windsurf, Codex, Gemini CLI

Or ask your AI assistant for it

With the Animorio connector, Claude Code, ChatGPT, Cursor or VS Code take it from here, guide included, and fit it into your project. Paste this request:

Take “Brush size slider” from Animorio and fit it into my site
Platform licenseFree on your sites and your clients’ sites. Want it inside a website builder, a template platform or a client dashboard? There’s a license for agencies and platforms.

What it does

On white, the tool card of a drawing app: at the top the brush icon, “Brush size” and the size in pixels, its digits on two reels that roll. Below, a little paper-coloured canvas with a dot grid and a freehand stroke, thinner at its ends as if the pen pressed harder in the middle, with a light shadow two pixels off. Lower down the track, shaped like a wedge: one pixel thick on the left, fifteen on the right, filled with blue up to the handle. The handle is a white round with a black dot inside that grows with the size, like a tip seen from above; on hover it lifts a touch on a spring. Pressed, it tightens to 0.9 and a light blue halo comes on around it; while you drag, the stroke follows on a spring that goes a little past and settles, and a dashed circle as big as the brush appears at the end of the stroke. The track gives more room to small sizes, as real apps do. Underneath are the ticks of the usual sizes: near one, the magnet catches it, the tick jumps and turns blue and its number darkens. Released, the handle settles with a small bounce and the tip circle fades. The two round buttons, minus and plus, jump to the usual size below or above and squash on an elastic. On its own, the demo drags the handle to 24, to 4, to 40 and back to 12.

How it works

The computed stroke

The stroke is not an SVG stroke: it is a filled shape. The script samples 91 points along a hidden curve with getPointAtLength, works out the normal at each and puts two points on either side, half the width away for the pressure (thinner at the ends, with a slight wave); then it closes the shape with two round arcs. So the width changes along the line and is recomputed every frame.

Two speeds

The handle follows the finger almost at once (0.12 seconds), while the stroke width catches up with a back.out tween of FOLLOW seconds: that difference is what makes the stroke feel soft.

A non-linear track

The position is the normalised size raised to 0.6: small sizes, the ones used most, get more room. The ticks are placed with the same function and the wedge is redrawn in real pixels on every resize.

The magnet

If the raw value is within SNAP pixels of a usual size, the handle goes onto the tick; the tick jumps with elastic.out and changes colour. Arrow keys move one pixel at a time without the magnet, Page Up and Down go tick to tick.

The number on reels

Tens and units are two columns of digits in a window one line tall; they move with yPercent and back.out. Below 10 the tens reel shrinks to zero width.

Values to change

NameFileDefaultWhat it changes
LABELscript.jsBrush sizeThe name written at the top of the tool card.
SIZEscript.js12The brush size at the start, in pixels.
MIN_SIZEscript.js1The smallest size, in pixels.
MAX_SIZEscript.js48The largest size, in pixels.
TICKSscript.js2, 4, 8, 12, 16, 24, 32, 48The usual sizes under the track, where the handle snaps, separated by commas.
SNAPscript.js1.5How close to a usual size the magnet catches the handle, in pixels of size.
FOLLOWscript.js0.55How long the stroke takes to reach the new size, in seconds.
BOUNCEscript.js1.6How far the stroke overshoots before settling (0 = no bounce).
LOOP_PAUSEscript.js1.6The pause at the end of the self-running loop before it starts again, in seconds.

Try them in the Playground

When to use it

In the toolbar of a drawing app, a photo editor or a shared whiteboard, for the size of the brush, the eraser or the line; or in any panel where you pick a size and need to see it straight away.

On phones

The card takes at most the width minus 24 pixels and the canvas is sized on the height (between 96 and 132 pixels): everything fits the phone preview box. The track drags with a finger without scrolling the page; the wedge and the ticks are recomputed on the real width.

With reduced motion

No springs or jumps: the stroke is already drawn, the width, the handle and the number change straight to the new value, the halo appears without growing and the self-running loop does not start.

Pitfalls

  • An SVG stroke has the same width everywhere: for a stroke that tapers at its ends you need a filled shape computed from points and normals.
  • The track wedge is drawn in real pixels (viewBox equal to the width): with preserveAspectRatio none the round ends would turn into ovals.

Libraries

GSAP 3.15.0, Mona Sans (font variabile) 5.3.0, JetBrains Mono (font variabile) 5.3.0.

Compressed with gzip, the three demo files weigh 8.4 KB; the libraries: GSAP 28 KB.

Testing

Tested on 23 November 2026

  • Desktop: Done
  • Phone: Done
  • Reduced motion: Done
  • Safari on iPhone: To do

License

Use it in your own projects and in your clients’ projects. Do not resell it or redistribute it as is. GSAP stays under its own Standard license. Full license.

All components