Home / Modern UI / Responsive Dashboard Widgets

Responsive Dashboard Widgets in JavaScript, Free with Live Demo

Free responsive dashboard in HTML, CSS and JavaScript. Resize any widget and it switches layout with container queries, while ResizeObserver redraws the charts.

Open live demoDownload HTML fileView code on GitHub
Responsive Dashboard Widgets JavaScript project: dashboard widgets that change layout when you resize them

Runs on: CSS Container Queries. Every modern browser (container queries since 2023).

What is the Responsive Dashboard Widgets?

Drag the corner of any widget on this dashboard and watch it change: a small widget shows just the number, a wider one adds a chart, and a big one adds details. Each widget decides its layout from its own width, not the screen width.

That is what CSS container queries do. The same widget works in a narrow sidebar or a wide main area without extra code. ResizeObserver tells JavaScript the new size so the canvas charts stay sharp.

Good for

  • Admin and analytics dashboards
  • Reusable cards in design systems
  • Sidebars and layouts users can resize
  • Learning container queries

What this project does

How it works

  1. Make it a containerEach widget has container-type: inline-size, so its children can ask how wide the widget is.
  2. Style by size@container rules switch the layout at 260 px and 440 px of widget width, whatever the page width.
  3. Redraw on resizeResizeObserver reports the new size and the canvas chart is redrawn to fit, sharp on high density screens.

The key JavaScript

This is the heart of the project. The full file has the rest, including the screen layout and error handling.

.widget { container-type: inline-size; resize: both; overflow: hidden; }

/* The widget, not the screen, decides the layout */
@container (min-width: 260px) { .widget canvas { display: block; } }
@container (min-width: 440px) { .widget .body { display: grid; grid-template-columns: auto 1fr; } }

// Keep the canvas sharp at every size
new ResizeObserver(([entry]) => {
  const { width, height } = entry.contentRect;
  canvas.width = width * devicePixelRatio;
  canvas.height = height * devicePixelRatio;
  draw();
}).observe(canvas);

How to use it

  1. Click Download HTML file above.
  2. Open the file in a code editor, like VS Code.
  3. Run it from a local server with npx serve . so the camera, microphone and AI features are allowed.
  4. Change the text and colors, then upload it to GitHub Pages, Netlify or your own site. It is one file with no build step.

Questions people ask

What is the difference between media queries and container queries?

Media queries look at the screen size. Container queries look at the size of a parent element, so a component adapts to wherever you place it.

Do container queries work everywhere?

Yes. All major browsers have supported them since 2023.

Why do the charts need JavaScript?

Canvas has a fixed pixel size. ResizeObserver reports the new size, and the chart is redrawn at the right resolution for sharp lines.

More Modern UI projects