Ratio balancer
A multi-segment allocation track. Drag dividers to rebalance constrained percentages with zero initial jump.
Used forTraffic splitsBudget allocationResource quotasRevenue and payout splits
Install with the shadcn CLI
Older shadcn CLI, or a network that blocks ui.shadcn.com? Install by URL: shadcn add https://hairlineui.com/r/ratio-balancer.json. More
Templates
Need the whole page?
65 Next.js landing pages, each designed from scratch. Try any of them live; one is $39, all of them $159, and 8 are free.
Where it’s used
Traffic splits
Divide traffic between variants of a test or a rollout.
Budget allocation
Split a budget between channels or teams.
Resource quotas
Share compute or storage across projects in cloud settings.
Revenue and payout splits
Divide earnings between collaborators.
What it handles for you
Dividing 100% between several things is awkward with separate number fields that never add up. This is one bar with draggable dividers, where the total is always 100%.
Always 100%
On release every ratio is normalised to whole numbers that add up to 100.
Drag the dividers
Moving a divider rebalances the two segments beside it. It tracks your finger one to one, with no jump at the start.
A minimum share
No segment can drop below minRatio, 5% by default.
Numbers that roll
The percentages roll to their settled totals when you let go.
Commit when done
onValueChange fires while dragging, and onValueCommit fires on release or a keyboard change.
Keyboard and screen readers
Dividers take focus, Left and Right nudge by 1% (5% with Shift), and each divider reports its value.
Overview
Distribute a shared 100% budget among multiple competing categories. Thin hairline dividers glide between segments with 1:1 physical tracking, numbers roll to settled totals, and expanded touch targets make dragging effortless on mobile and desktop. Built with pure flex-grow transitions, zero animation libraries, and zero shadows.
States
- rebalance
- Dragging a divider updates adjacent segment flex-grow styles and DOM text nodes directly.
- settle
- Releasing the pointer normalizes all ratios to 100% and rolls final percentage digits via NumberRoll.
- keyboard
- Dividers accept focus; Left and Right arrow keys nudge allocations by 1% (or 5% with Shift).
Usage
Works with
Allocate resource quotas in cloud settings
Use RatioBalancer to configure server cluster allocation or team spend limits. It maintains total conservation (always 100%) with fluid responsive drag.
Props
- label
- string
- Accessible heading displayed above the allocation bar.
- segments / defaultSegments
- RatioSegment[]
- Array of segment objects with id, label, and ratio (summing to 100).
- minRatio= 5
- number
- Minimum allowed percentage for any segment during drag.
- disabled= false
- boolean
- Disables all divider dragging.
- onValueChange
- (ratios: number[]) => void
- Fired during divider movement with immediate ratio updates.
- onValueCommit
- (ratios: number[]) => void
- Fired upon pointer release or keyboard adjustment with clean normalized integers.
Accessibility and motion
- Dividers act as semantic separators with vertical orientation and aria-valuenow.
- Delta-based drag ensures 1:1 finger tracking without initial jumping on touch devices.
- Segments maintain pure DOM styles during drag; React state updates occur only on commit.
- Reduced motion removes flex-grow easing transitions and rolls digits in place.
Requirements
React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.
The CLI also installs Number roll.
Source
Registry item: /r/ratio-balancer.json


