Skip to content
IndexRequest a UIAboutContact

Sortable Ranking Bars

Horizontal bars that glide into their new order when the sort changes.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build a ranking of six frameworks with values (Alpha 82, Bravo 64, Charlie 91, Delta 47, Echo 73, Foxtrot 58), each row 34px tall with a 60px label, a horizontal bar whose width is value divided by the maximum and the number at the end. Add a group of three buttons "High to low", "Low to high" and "A to Z" with aria-pressed. When a sort is chosen, use the FLIP technique: record each row's top, reorder the DOM, record the new tops and animate each row from translateY(old minus new) to 0 over 420ms cubic-bezier(.2,.7,.2,1) with element.animate. Announce "Sorted high to low" in an aria-live polite region. Bars have a dark fill with a light track. Under prefers-reduced-motion reorder without animation.

About this pattern

Definition

A ranked list where each row has a horizontal bar. Changing the sort order moves the rows smoothly to their new positions instead of redrawing the list.

Purpose & UX principles

  • Animated reordering lets people follow which item went where, which a sudden jump hides.
  • Sort controls are a labelled group of buttons with aria-pressed, and the new order is announced.
  • Values are written as numbers beside the bars, so the chart does not rely on length alone.

Interaction states

  • Sorted by value (descending), by value (ascending), by name; the active button is pressed.

Motion specification

  • FLIP: rows are measured, reordered and animated from their old positions with a 420ms cubic-bezier(.2,.7,.2,1) transform.
  • Bars keep their width; only position changes.
  • Reduced motion: rows jump to place.

Responsive behaviour

  • Rows fill the width; labels truncate with ellipsis on narrow screens.

Code

HTML
<div class="box">
  <div class="seg" role="group" aria-label="Sort order"><button data-s="hi" aria-pressed="true">High to low</button><button data-s="lo" aria-pressed="false">Low to high</button><button data-s="az" aria-pressed="false">A to Z</button></div>
  <ul class="rk" id="rk"></ul><p class="live" id="live" aria-live="polite"></p>
</div>

Related patterns

Interactive Bar Chart

↗
Interactive Bar ChartData Visualization

Stacked Bars with Series Toggle

↗
Stacked Bars with Series ToggleData Visualization

Drag to Reorder

↗
Drag to ReorderGestures & Touch