webdevpuneet.com

Page Minimap — Scrollable Overview & Viewport Indicator

Page Minimap · Navigation · Plain HTML, CSS & JS · Live preview

CategoryNavigation

Copy & paste

Source Code

<main class="pm-page" id="pmPage">
  <section class="pm-sec" data-label="Intro"><h2>Introduction</h2><p>Scroll the page — the minimap on the right mirrors your position. Click or drag it to jump.</p></section>
  <section class="pm-sec" data-label="Setup"><h2>Setup</h2><p>A miniature of the page sits fixed on the right. Each block is a section, sized in proportion to its real height.</p></section>
  <section class="pm-sec pm-tall" data-label="Guide"><h2>The long guide</h2><p>This section is intentionally tall so the minimap clearly shows proportions and the viewport indicator has room to travel.</p></section>
  <section class="pm-sec" data-label="API"><h2>API</h2><p>The shaded box on the minimap is your current viewport. It moves as you scroll and you can drag it.</p></section>
  <section class="pm-sec pm-tall" data-label="Examples"><h2>Examples</h2><p>Click anywhere on the minimap to scroll there instantly; drag the indicator for fine control.</p></section>
  <section class="pm-sec" data-label="FAQ"><h2>FAQ</h2><p>The minimap rebuilds on resize so the proportions always match the real page.</p></section>
</main>
<aside class="pm-map" id="pmMap" aria-label="Page minimap">
  <div class="pm-blocks" id="pmBlocks"></div>
  <div class="pm-view" id="pmView"></div>
</aside>

Extend with AI

Take This Snippet Further With AI

The AI prompt for this one is for Patreon supporters ($3 a month), along with a site with no ads. Supporters enter the passcode once and it is remembered in this browser.

· Become a supporter

What's included

Features

Proportional blocks
Each section is sized to its real height — cheap and faithful.
Live viewport box
Position and height reflect scroll and visible area.
Click to jump
Clicking scrolls that point to the viewport center.
Drag to scrub
Press and drag for continuous navigation.
Active highlight
The block nearest the viewport center lights up.
Passive scroll
A passive listener keeps scrolling smooth.
Rebuilds on resize
Recomputes proportions when section heights change.
No library
Pure HTML/CSS/JS — no minimap dependency.

About this UI Snippet

Page Minimap — Proportional Page Overview with Draggable Viewport

Screenshot of the Page Minimap snippet rendered live

A page minimap is the miniature overview — familiar from code editors like VS Code — that shows the whole document at a glance with a box marking where you are, and lets you click or drag to jump anywhere. This snippet builds one for a scrolling page from its sections, with proportional blocks, a live viewport indicator, and drag-to-navigate, in plain HTML, CSS, and vanilla JavaScript.

Proportional, not a pixel clone

Rather than rendering a scaled screenshot of the page (expensive and fragile), the minimap represents each section as a block sized in proportion to that section's real height. A tall guide section gets a tall block; a short FAQ gets a short one. The whole stack is scaled to a fixed minimap height, so the map is a faithful structural overview that's cheap to build and easy to style.

A live viewport indicator

A translucent box on the minimap represents the current viewport. Its top is the scroll position times the scale factor, and its height is the window height times the same factor — so it grows and shrinks to reflect how much of the page is visible and slides as you scroll. Listening to scroll with a passive listener keeps it smooth without blocking scrolling.

Click and drag to navigate

Clicking anywhere on the minimap scrolls the page so that point sits at the centre of the viewport, with smooth behaviour; pressing and dragging scrolls continuously as you move, for fine control. The mapping is a single ratio — pointer position within the map equals scroll position within the page — which keeps navigation predictable in both directions.

Active-section highlight

The block nearest the viewport's centre is highlighted, giving an at-a-glance "you are here" beyond the viewport box — useful when sections are uneven. The highlight is recomputed on each scroll from the sections' offsets, so it stays accurate as content changes.

Responsive and self-rebuilding

On resize the minimap rebuilds its blocks and rescales, because section heights change with width — so the proportions always match the real page. The whole thing is a build function and a scroll update with no dependencies, a clean reference for the editor-style minimap pattern applied to long pages and docs.

Step by step

How to Use

  1. 1
    Paste HTML, CSS, and JSA long page renders with a minimap fixed on the right.
  2. 2
    ScrollThe viewport box moves and the active section block highlights.
  3. 3
    Click the mapThe page scrolls so that point centers in the viewport.
  4. 4
    Drag the mapPress and move to scrub through the page continuously.
  5. 5
    Mark sectionsEach .pm-sec becomes a proportional block automatically.
  6. 6
    ResizeThe minimap rebuilds so proportions stay accurate.

Real-world uses

Common Use Cases

Long documentation pages
Show an overview and jump control beside a table of contents, with each section block sized to its real height.
Article and guide navigation
Pair with a scroll progress bar so readers see both where they are and how far through they have gone.
Dashboards and reports
Navigate a tall stack of panels quickly, with a live viewport box that reflects scroll position and visible area.
Editors and builders
Provide an editor-style minimap for a document, supporting click to jump and press and drag to scrub continuously.
Landing page section jumps
Jump between sections like a scroll spy nav, and learn the scaling maths behind a proportional overview.
Related: Scrollspy Navigation — Active Link Tracks the Section in View
See the Scrollspy Navigation — Active Link Tracks the Section in View for a related navigation pattern worth pairing with this one.

Got questions?

Frequently Asked Questions

Cloning and scaling the real DOM (or a screenshot) is expensive, breaks with dynamic content, and is hard to keep in sync. Representing each section as a proportionally sized block captures the page structure faithfully at a fraction of the cost, is trivial to style, and rebuilds instantly on resize. It is the same idea as an outline view rather than a literal thumbnail.

The minimap is the page height multiplied by a scale factor. The box's top is window.scrollY times that scale, and its height is window.innerHeight times the scale, so it represents exactly the visible portion and moves as you scroll. The scroll listener is passive, so updating the box never blocks or janks the actual scrolling.

Both use one ratio: the pointer's vertical position within the minimap divided by the minimap height equals the target position within the page. Clicking scrolls (smoothly) so that target sits at the viewport centre; dragging applies the same mapping continuously on pointermove for scrubbing. This symmetry makes the map predictable to use.

Yes. Section heights depend on viewport width (text reflows), so the minimap rebuilds its blocks and recomputes the scale on resize. If your content changes dynamically, call the build function again after the change and the proportions and viewport box will re-sync to the new page height.

Measure the page and section heights after render (in an effect) and store them in state to render the blocks; recompute on a resize listener. Track scrollY in state via a passive scroll listener to position the viewport box, and implement click/drag handlers that call scrollTo with the mapped target. Tailwind users swap the classes for utilities; the scaling math is unchanged.

Yes. While the Page Minimap snippet gives you one pattern to copy, the free Responsive Navbar Builder at webdevpuneet.com/navbar-builder/ designs a whole navigation bar: logo, links and dropdown menus, a mobile hamburger menu (dropdown panel, slide-in drawer or full screen) and a scroll effect (sticky, shrink, hide on scroll or transparent). It has six presets, a live preview that runs the real code, and exports HTML + CSS + vanilla JS, React, Tailwind, Vue 3 or Angular — or you can click Fork & Edit to keep editing it in My Code.