Skip to content
IndexRequest a UIAboutContact

Interactive Bar Chart

A bar chart that grows in, dims the other bars on hover and shows the exact value.

Open alone ↗

AI prompt

PROMPT: PASTE INTO YOUR AI CODING TOOL
Build a 300x170px bar chart for the days Mon to Sun with values 32, 48, 41, 66, 58, 27 and 19 visits. Use flex columns, a baseline line and day labels in 11px secondary text. Each bar is a button element with an aria-label like "Thursday: 66 visits", rounded top corners and a mid-grey fill (#b9b9b3). On load animate each bar from scaleY(0) with transform-origin bottom to full height over 600ms cubic-bezier(.2,.7,.2,1) with a 50ms stagger. On hover and focus-visible set the bar to #171717, reduce the opacity of the other bars to 0.45 over 150ms and show a small tooltip above the bar with the value. Taps toggle the tooltip on touch devices. Scale bar heights to the maximum value. Keep a 2px focus ring. Under prefers-reduced-motion skip the grow animation.

About this pattern

Definition

A chart of seven bars whose height encodes a value. Hovering or focusing one bar highlights it, dims the rest and shows its exact number in a tooltip.

Purpose & UX principles

  • Bars make comparison quick; the tooltip supplies the exact value so the chart does not need clutter.
  • Each bar is focusable with an aria-label such as "Wednesday: 48 visits", so keyboard and screen-reader users get the same data.
  • Dimming the others focuses attention without hiding context.

Interaction states

  • Rest, hover or focus (bar dark, others dimmed, tooltip), selected by tap, entering (growing).

Motion specification

  • On load each bar grows from the baseline over 600ms cubic-bezier(.2,.7,.2,1) with a 50ms stagger.
  • Highlight and dim: 150ms ease.
  • Reduced motion: bars appear at full height.

Responsive behaviour

  • The chart fills its container and bars share the width equally.
  • On touch, tapping a bar shows its tooltip until the next tap.

Code

HTML
<div class="ch" id="ch" role="group" aria-label="Weekly visits"></div>

Related patterns

Stacked Bars with Series Toggle

↗
Stacked Bars with Series ToggleData Visualization

Sortable Ranking Bars

↗
Sortable Ranking BarsData Visualization

Line Chart with Crosshair

↗
Line Chart with CrosshairData Visualization