Components Layout

Scroll area

Read inside a bounded viewport with a draggable scrollbar, chapter navigation, and a reading progress indicator.

Live previewGo + JavaScript

A study in light

Field notes on four spaces shaped by daylight.

A row of stone arches casts curved shadows across the floor of an open courtyard.

Beneath the arcade

Arcade Court · Turin

In the covered walk, a few steps carry you from cool shade into the bright court. Each arch draws the boundary again.

Look along the paving and the arches become a sequence of dark pools. Look across the court and the same openings frame the sunlit wall opposite.

A long, low concrete house extends over a rocky stretch of water beneath pine branches.

At the waterline

Harbor House · Seto Inland Sea

A concrete roof reaches past the glass. From under its edge, the horizon seems close enough to draw with a ruler.

The underside of the roof stays dark while the water catches the sky. The narrow band between them changes whenever a ripple passes.

A dark pool and a flight of steps sit between tall, pale quarry walls.

Inside the quarry

Quarry Baths · Limestone pool

At the foot of the cut stone, the pool holds a second set of walls. A passing ripple briefly breaks their straight edges.

The brightest surface is the narrow walkway beside the water. It leads the eye to the steps, where each tread catches a different amount of light.

A small timber studio stands on a wooded slope with light filtering between the trunks.

Among the cedars

Cedar Studio · Woodland elevation

Daylight reaches the studio in narrow shafts. The forest floor stays dim even as the branches overhead catch the sun.

From the slope below, the window reads as a pale rectangle among the trunks. The roof nearly disappears into the canopy behind it.

Usage

Give the viewport a Label. Pass Sections for a chapter reader or Items for a compact list. The reader works with a wheel, trackpad, touch, and keyboard.

Register scroll-area with Head and pass its properties to Render. Go setup guide

Choosing the content

Use Sections for a reader with a chapter index. Each mono.ScrollSection has a Title and can include Text, Paragraphs, ImageURL, Alt, and Caption. A list of maps with the same keys works as well. Serve your own photographs or reuse the WebP files in examples/components/projects/architecture.

For a compact list, pass Items as a slice of strings. To wrap existing content, pass Content. Plain strings are escaped. Use Go’s template.HTML for trusted markup from your application. The reader checks Sections, then Content, then Items.

Scrolling and sizing

Scroll naturally, drag the handle, or select a chapter. Focus the scrollbar to use the arrow keys, Page Up, Page Down, Home, or End. The percentage tracks the distance through the viewport. The custom rail appears when the contents overflow. With JavaScript disabled, the browser supplies the scrollbar.

Set --sa-height on a specific instance to size its viewport. For example, #delivery-notes { --sa-height: 16rem; } sets the height for the custom content sample below.

Use the scrollbar for a whole page

The rail at the edge of this page follows the document. On desktop, drag the handle or focus it and use the arrow keys, Page Up, Page Down, Home, or End. On phones, swipe anywhere to scroll. A slim indicator appears while the page is moving. A Scroll area inside the page keeps its own position.

To add the rail to your own pages, save the two files together and include them in your shared HTML head. The module attaches to the document automatically. Download the stylesheet · Download the module

Page layout
<link rel="stylesheet" href="./page-scroll.css">
<script type="module" src="./page-scroll.js"></script>
Build a chapter reader
Build a chapter reader
err := mono.UI.Render(w, "scroll-area", mono.Props{
	"Label": "Studio handbook",
	"Sections": []mono.ScrollSection{
		{Title: "Paper", Text: "Choose a stock and fold a mock-up.",
			Paragraphs: []string{"Check the grain direction before folding."}},
		{Title: "Binding", Text: "Mark your sewing stations along the spine.",
			ImageURL: "/images/spine.webp", Alt: "Three sewing stations marked on a folded spine."},
	},
})
Scroll a compact list
Scroll a compact list
err := mono.UI.Render(w, "scroll-area", mono.Props{
	"Label": "Print queue",
	"Items": []string{"Cover proof", "Title page", "Contents spread", "Colophon",
		"Inside cover", "Reference index", "Acknowledgments", "Dust jacket"},
})
Wrap custom content
Wrap custom content
// Import "html/template" for this application-owned markup.
err := mono.UI.Render(w, "scroll-area", mono.Props{
	"ID": "delivery-notes",
	"Label": "Delivery notes",
	"Content": template.HTML("<ol><li>Inspect the proof.</li><li>Pack the print.</li></ol>"),
})
Go usage
Go usage
err := mono.UI.Render(w, "scroll-area", mono.Props{
	"Description": "Field notes on four spaces shaped by daylight.",
	"Label":       "A study in light",
	"Sections": []any{
		map[string]any{
			"Alt":      "A row of stone arches casts curved shadows across the floor of an open courtyard.",
			"Caption":  "Arcade Court · Turin",
			"ImageURL": "../components/projects/architecture/arcade-court-720.webp",
			"Paragraphs": []any{
				"Look along the paving and the arches become a sequence of dark pools. Look across the court and the same openings frame the sunlit wall opposite.",
			},
			"Text":  "In the covered walk, a few steps carry you from cool shade into the bright court. Each arch draws the boundary again.",
			"Title": "Beneath the arcade",
		},
		map[string]any{
			"Alt":      "A long, low concrete house extends over a rocky stretch of water beneath pine branches.",
			"Caption":  "Harbor House · Seto Inland Sea",
			"ImageURL": "../components/projects/architecture/harbor-house-720.webp",
			"Paragraphs": []any{
				"The underside of the roof stays dark while the water catches the sky. The narrow band between them changes whenever a ripple passes.",
			},
			"Text":  "A concrete roof reaches past the glass. From under its edge, the horizon seems close enough to draw with a ruler.",
			"Title": "At the waterline",
		},
		map[string]any{
			"Alt":      "A dark pool and a flight of steps sit between tall, pale quarry walls.",
			"Caption":  "Quarry Baths · Limestone pool",
			"ImageURL": "../components/projects/architecture/quarry-baths-720.webp",
			"Paragraphs": []any{
				"The brightest surface is the narrow walkway beside the water. It leads the eye to the steps, where each tread catches a different amount of light.",
			},
			"Text":  "At the foot of the cut stone, the pool holds a second set of walls. A passing ripple briefly breaks their straight edges.",
			"Title": "Inside the quarry",
		},
		map[string]any{
			"Alt":      "A small timber studio stands on a wooded slope with light filtering between the trunks.",
			"Caption":  "Cedar Studio · Woodland elevation",
			"ImageURL": "../components/projects/architecture/cedar-studio-720.webp",
			"Paragraphs": []any{
				"From the slope below, the window reads as a pale rectangle among the trunks. The roof nearly disappears into the canopy behind it.",
			},
			"Text":  "Daylight reaches the studio in narrow shafts. The forest floor stays dim even as the branches overhead catch the sun.",
			"Title": "Among the cedars",
		},
	},
})
Rendered HTML
Rendered HTML
<section data-mono="scroll-area" id="demo-scroll-area" class="sa-reader sa-chapters" aria-labelledby="demo-scroll-area-heading">
  <header class="sa-mast">
    <div class="sa-title-block">
      <h2 id="demo-scroll-area-heading">A study in light</h2>
      <p>Field notes on four spaces shaped by daylight.</p>
    </div>
    <div class="sa-progress" data-sa-progress hidden>
      <span>Scroll position</span>
      <strong><svg width="20" height="20" viewBox="0 0 24 24" aria-hidden="true"><circle class="sa-ring" cx="12" cy="12" r="9" fill="none" stroke-width="2"/><circle class="sa-ring-value" cx="12" cy="12" r="9" fill="none" stroke-width="2" pathLength="1" transform="rotate(-90 12 12)"/></svg><span data-sa-percent>0%</span></strong>
    </div>
  </header>
  <div class="sa-layout">
    
      <nav class="sa-index" data-sa-nav aria-label="Section navigation" hidden>
        <div class="sa-index-title"><svg viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.45" stroke-linecap="round" aria-hidden="true"><path d="M2.5 5h2m3 0h10m-15 5h2m3 0h10m-15 5h2m3 0h10"/></svg>Contents</div>
        <ol class="sa-index-list">
        <li><button type="button" data-sa-jump="0" aria-controls="demo-scroll-area-section-0"><span class="sa-index-num" aria-hidden="true"></span><span class="sa-index-name">Beneath the arcade</span><svg class="sa-index-arrow" width="16" height="16" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 10h11m-4.5-4.5L15 10l-4.5 4.5"/></svg></button></li><li><button type="button" data-sa-jump="1" aria-controls="demo-scroll-area-section-1"><span class="sa-index-num" aria-hidden="true"></span><span class="sa-index-name">At the waterline</span><svg class="sa-index-arrow" width="16" height="16" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 10h11m-4.5-4.5L15 10l-4.5 4.5"/></svg></button></li><li><button type="button" data-sa-jump="2" aria-controls="demo-scroll-area-section-2"><span class="sa-index-num" aria-hidden="true"></span><span class="sa-index-name">Inside the quarry</span><svg class="sa-index-arrow" width="16" height="16" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 10h11m-4.5-4.5L15 10l-4.5 4.5"/></svg></button></li><li><button type="button" data-sa-jump="3" aria-controls="demo-scroll-area-section-3"><span class="sa-index-num" aria-hidden="true"></span><span class="sa-index-name">Among the cedars</span><svg class="sa-index-arrow" width="16" height="16" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 10h11m-4.5-4.5L15 10l-4.5 4.5"/></svg></button></li>
        </ol>
      </nav>
    
    <div class="sa-reader-pane">
      <div data-sa-viewport id="demo-scroll-area-viewport" class="sa-window mu-scroll-window" role="region" aria-labelledby="demo-scroll-area-heading" tabindex="0">
        <div data-sa-content class="sa-content">
          
            <article class="sa-section" data-sa-section id="demo-scroll-area-section-0" aria-labelledby="demo-scroll-area-section-title-0">
              <header class="sa-section-head sa-cover">
                <img class="sa-cover-img" src="../components/projects/architecture/arcade-court-720.webp" alt="A row of stone arches casts curved shadows across the floor of an open courtyard." decoding="async">
                <div class="sa-section-titles"><span class="sa-folio" aria-hidden="true"><span></span> / 04</span>
                  <h3 id="demo-scroll-area-section-title-0">Beneath the arcade</h3>
                </div>
              </header>
              <p class="sa-caption">Arcade Court · Turin</p>
              <div class="sa-copy"><p class="sa-lead">In the covered walk, a few steps carry you from cool shade into the bright court. Each arch draws the boundary again.</p><p>Look along the paving and the arches become a sequence of dark pools. Look across the court and the same openings frame the sunlit wall opposite.</p></div>
            </article>
          
            <article class="sa-section" data-sa-section id="demo-scroll-area-section-1" aria-labelledby="demo-scroll-area-section-title-1">
              <header class="sa-section-head sa-cover">
                <img class="sa-cover-img" src="../components/projects/architecture/harbor-house-720.webp" alt="A long, low concrete house extends over a rocky stretch of water beneath pine branches." decoding="async" loading="lazy">
                <div class="sa-section-titles"><span class="sa-folio" aria-hidden="true"><span></span> / 04</span>
                  <h3 id="demo-scroll-area-section-title-1">At the waterline</h3>
                </div>
              </header>
              <p class="sa-caption">Harbor House · Seto Inland Sea</p>
              <div class="sa-copy"><p class="sa-lead">A concrete roof reaches past the glass. From under its edge, the horizon seems close enough to draw with a ruler.</p><p>The underside of the roof stays dark while the water catches the sky. The narrow band between them changes whenever a ripple passes.</p></div>
            </article>
          
            <article class="sa-section" data-sa-section id="demo-scroll-area-section-2" aria-labelledby="demo-scroll-area-section-title-2">
              <header class="sa-section-head sa-cover">
                <img class="sa-cover-img" src="../components/projects/architecture/quarry-baths-720.webp" alt="A dark pool and a flight of steps sit between tall, pale quarry walls." decoding="async" loading="lazy">
                <div class="sa-section-titles"><span class="sa-folio" aria-hidden="true"><span></span> / 04</span>
                  <h3 id="demo-scroll-area-section-title-2">Inside the quarry</h3>
                </div>
              </header>
              <p class="sa-caption">Quarry Baths · Limestone pool</p>
              <div class="sa-copy"><p class="sa-lead">At the foot of the cut stone, the pool holds a second set of walls. A passing ripple briefly breaks their straight edges.</p><p>The brightest surface is the narrow walkway beside the water. It leads the eye to the steps, where each tread catches a different amount of light.</p></div>
            </article>
          
            <article class="sa-section" data-sa-section id="demo-scroll-area-section-3" aria-labelledby="demo-scroll-area-section-title-3">
              <header class="sa-section-head sa-cover">
                <img class="sa-cover-img" src="../components/projects/architecture/cedar-studio-720.webp" alt="A small timber studio stands on a wooded slope with light filtering between the trunks." decoding="async" loading="lazy">
                <div class="sa-section-titles"><span class="sa-folio" aria-hidden="true"><span></span> / 04</span>
                  <h3 id="demo-scroll-area-section-title-3">Among the cedars</h3>
                </div>
              </header>
              <p class="sa-caption">Cedar Studio · Woodland elevation</p>
              <div class="sa-copy"><p class="sa-lead">Daylight reaches the studio in narrow shafts. The forest floor stays dim even as the branches overhead catch the sun.</p><p>From the slope below, the window reads as a pale rectangle among the trunks. The roof nearly disappears into the canopy behind it.</p></div>
            </article>
          
        </div>
      </div>
      <div data-sa-track class="sa-track" hidden>
        <div data-sa-thumb class="sa-thumb" role="scrollbar" aria-label="Scroll position" aria-controls="demo-scroll-area-viewport" aria-orientation="vertical" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" tabindex="0"><span aria-hidden="true"></span></div>
      </div>
    </div>
  </div>
</section>
Go template
Go template
{{- $sections := scrollSections .Sections -}}
<section data-mono="scroll-area" id="{{.ID}}" class="sa-reader {{if $sections}}sa-chapters{{else if .Content}}sa-custom{{else}}sa-list-only{{end}}" aria-labelledby="{{.ID}}-heading">
  <header class="sa-mast">
    <div class="sa-title-block">
      <h2 id="{{.ID}}-heading">{{or .Label "Scroll area"}}</h2>
      {{with .Description}}<p>{{.}}</p>{{end}}
    </div>
    <div class="sa-progress" data-sa-progress hidden>
      <span>Scroll position</span>
      <strong><svg width="20" height="20" viewBox="0 0 24 24" aria-hidden="true"><circle class="sa-ring" cx="12" cy="12" r="9" fill="none" stroke-width="2"/><circle class="sa-ring-value" cx="12" cy="12" r="9" fill="none" stroke-width="2" pathLength="1" transform="rotate(-90 12 12)"/></svg><span data-sa-percent>0%</span></strong>
    </div>
  </header>
  <div class="sa-layout">
    {{with $sections}}
      <nav class="sa-index" data-sa-nav aria-label="Section navigation" hidden>
        <div class="sa-index-title"><svg viewBox="0 0 20 20" width="16" height="16" fill="none" stroke="currentColor" stroke-width="1.45" stroke-linecap="round" aria-hidden="true"><path d="M2.5 5h2m3 0h10m-15 5h2m3 0h10m-15 5h2m3 0h10"/></svg>Contents</div>
        <ol class="sa-index-list">
        {{range $i, $s := .}}<li><button type="button" data-sa-jump="{{$i}}" aria-controls="{{$.ID}}-section-{{$i}}"><span class="sa-index-num" aria-hidden="true"></span><span class="sa-index-name">{{or $s.Title "Untitled section"}}</span><svg class="sa-index-arrow" width="16" height="16" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 10h11m-4.5-4.5L15 10l-4.5 4.5"/></svg></button></li>{{end}}
        </ol>
      </nav>
    {{end}}
    <div class="sa-reader-pane">
      <div data-sa-viewport id="{{.ID}}-viewport" class="sa-window mu-scroll-window" role="region" aria-labelledby="{{.ID}}-heading" tabindex="0">
        <div data-sa-content class="sa-content">
          {{if $sections}}{{range $i, $s := $sections}}
            <article class="sa-section" data-sa-section id="{{$.ID}}-section-{{$i}}" aria-labelledby="{{$.ID}}-section-title-{{$i}}">
              <header class="sa-section-head{{if $s.ImageURL}} sa-cover{{end}}">
                {{with $s.ImageURL}}<img class="sa-cover-img" src="{{.}}" alt="{{$s.Alt}}" decoding="async"{{if $i}} loading="lazy"{{end}}>{{end}}
                <div class="sa-section-titles"><span class="sa-folio" aria-hidden="true"><span></span> / {{printf "%02d" (len $sections)}}</span>
                  <h3 id="{{$.ID}}-section-title-{{$i}}">{{or $s.Title "Untitled section"}}</h3>
                </div>
              </header>
              {{if and $s.ImageURL $s.Caption}}<p class="sa-caption">{{$s.Caption}}</p>{{end}}
              {{if or $s.Text $s.Paragraphs}}<div class="sa-copy">{{with $s.Text}}<p class="sa-lead">{{.}}</p>{{end}}{{range $s.Paragraphs}}<p>{{.}}</p>{{end}}</div>{{end}}
            </article>
          {{end}}{{else if .Content}}<div class="sa-body">{{.Content}}</div>
          {{else}}<ul class="mu-list">{{range .Items}}<li class="mu-item">{{.}}</li>{{end}}</ul>{{end}}
        </div>
      </div>
      <div data-sa-track class="sa-track" hidden>
        <div data-sa-thumb class="sa-thumb" role="scrollbar" aria-label="Scroll position" aria-controls="{{.ID}}-viewport" aria-orientation="vertical" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" tabindex="0"><span aria-hidden="true"></span></div>
      </div>
    </div>
  </div>
</section>
Component CSS
Component CSS
.sa-reader[data-mono] {
  --sa-paper:#fff;
  --sa-ink:#191919;
  --sa-muted:#626262;
  --sa-rule:#d8d8d8;
  --sa-track-bg:#f0f0f0;
  --sa-tick:#aeaeae;
  --sa-index-bg:#202020;
  --sa-index-ink:#f8f8f8;
  --sa-mono:ui-monospace,SFMono-Regular,Consolas,monospace;
  --sa-serif:"Iowan Old Style","Palatino Linotype","Book Antiqua",Georgia,serif;
  container-type:inline-size;
  width:100%;
  min-width:0;
  margin:0;
  color:var(--sa-ink);
  background:var(--sa-paper);
  border:1px solid var(--sa-rule);
  border-radius:.65rem;
  overflow:hidden;
}
[data-theme="dark"] .sa-reader[data-mono] {
  --sa-paper:#202020; --sa-ink:#f5f5f5; --sa-muted:#b9b9b9; --sa-rule:#484848;
  --sa-track-bg:#292929; --sa-tick:#707070; --sa-index-bg:#141414;
}
.sa-reader [hidden] { display:none !important; }
.sa-mast {
  display:flex; align-items:center; justify-content:space-between; gap:.75rem 1.2rem;
  padding:clamp(1.05rem,3.2cqi,2.25rem); border-bottom:1px solid var(--sa-rule);
}
.sa-title-block { min-width:0; }
.sa-reader .sa-title-block h2 {
  margin:0; color:var(--sa-ink); font:540 clamp(1.85rem,5.6cqi,3.6rem)/1.04 Inter,"Helvetica Neue",Arial,sans-serif;
  letter-spacing:-.065em; overflow-wrap:anywhere;
}
.sa-reader .sa-title-block p { margin:.48rem 0 0; color:var(--sa-muted); font-size:.85rem; line-height:1.45; overflow-wrap:anywhere; }
.sa-progress { flex:none; display:grid; justify-items:end; gap:.18rem; }
.sa-progress > span, .sa-index-title {
  font:550 .62rem/1.3 var(--sa-mono); letter-spacing:.085em; text-transform:uppercase;
}
.sa-progress > span { color:var(--sa-muted); }
.sa-progress strong { display:flex; align-items:center; gap:.4rem; color:var(--sa-ink); font:600 1.05rem/1.2 var(--sa-mono); font-variant-numeric:tabular-nums; }
.sa-ring { stroke:var(--sa-rule); }
.sa-ring-value { stroke:var(--sa-ink); stroke-dasharray:1; stroke-dashoffset:calc(1 - var(--sa-progress,0)); }
.sa-layout { display:grid; min-width:0; }
.sa-reader-pane { min-width:0; display:flex; align-items:stretch; position:relative; }
.sa-reader .sa-window {
  flex:1 1 0; min-width:0; height:var(--sa-height,clamp(19rem,53svh,32rem)); overflow:auto;
  position:relative; overscroll-behavior:contain; scrollbar-width:thin; scrollbar-color:var(--sa-tick) var(--sa-paper);
}
.sa-reader[data-sa-enhanced][data-sa-overflow] .sa-reader-pane:has(> .sa-track:not([hidden])) > .sa-window { scrollbar-width:none; }
.sa-reader[data-sa-enhanced][data-sa-overflow] .sa-reader-pane:has(> .sa-track:not([hidden])) > .sa-window::-webkit-scrollbar { display:none; }
.sa-reader .sa-window:focus-visible { outline:2px solid var(--sa-ink); outline-offset:-3px; }
.sa-track {
  flex:none; position:relative; width:clamp(1.8rem,4.3cqi,2.55rem); touch-action:none; user-select:none;
  cursor:pointer; border-inline-start:1px solid var(--sa-rule); background-color:var(--sa-track-bg);
  background-image:repeating-linear-gradient(to bottom,var(--sa-tick) 0 1px,transparent 1px 8px),repeating-linear-gradient(to bottom,var(--sa-tick) 0 1px,transparent 1px 40px);
  background-size:26% 100%,48% 100%; background-position:left 5px,left 5px; background-repeat:no-repeat;
}
.sa-thumb {
  position:absolute; inset:0 0 auto; width:100%; display:grid; place-items:center; z-index:1; cursor:grab; touch-action:none; user-select:none;
}
.sa-thumb::before {
  content:""; position:absolute; inset:0 12% 0 26%; background:var(--sa-ink); border:2px solid var(--sa-track-bg); border-radius:20px;
}
.sa-thumb span {
  position:relative; width:28%; height:7px; margin-inline-start:14%; pointer-events:none;
  background:repeating-linear-gradient(to bottom,var(--sa-paper) 0 1px,transparent 1px 3px);
}
.sa-reader[data-sa-dragging] .sa-thumb, .sa-thumb:active { cursor:grabbing; }
.sa-reader .sa-thumb:focus-visible { outline:0; }
.sa-thumb:focus-visible::before { outline:2px solid var(--sa-ink); outline-offset:0; }
.sa-index { min-width:0; color:var(--sa-index-ink); background:var(--sa-index-bg); }
.sa-index-title { display:flex; align-items:center; gap:.5rem; padding:.7rem .9rem .54rem; }
.sa-index-title svg { flex:none; }
.sa-index-list {
  margin:0; padding:0 .5rem .6rem; display:grid; grid-template-columns:repeat(auto-fit,minmax(min(9.4rem,100%),1fr));
  list-style:none; max-height:8.2rem; overflow:auto; overscroll-behavior:contain; scrollbar-width:thin; scrollbar-color:#888 var(--sa-index-bg);
  counter-reset:sa-nav;
}
.sa-index-list li { counter-increment:sa-nav; min-width:0; }
.sa-index-list button {
  width:100%; display:flex; align-items:center; gap:.47rem; border:0; border-radius:.24rem; padding:.48rem .48rem;
  background:transparent; color:#cacaca; text-align:start; font:500 .77rem/1.3 Inter,"Helvetica Neue",Arial,sans-serif;
}
.sa-index-list button:hover { color:#fff; background:#343434; }
.sa-index-list button[aria-current="location"] { color:#181818; background:#f6f6f6; }
.sa-index-list button:focus-visible { outline:2px solid currentColor; outline-offset:-3px; }
.sa-index-num { flex:none; font:.62rem/1 var(--sa-mono); color:#adadad; }
.sa-index-num::before { content:counter(sa-nav,decimal-leading-zero); }
.sa-index-list [aria-current] .sa-index-num { color:#494949; }
.sa-index-name { overflow-wrap:anywhere; }
.sa-index-arrow { display:none; flex:none; margin-inline-start:auto; }
.sa-content { counter-reset:sa-section; }
.sa-section { counter-increment:sa-section; min-height:var(--sa-height,clamp(19rem,53svh,32rem)); border-block-end:1px solid var(--sa-rule); }
.sa-section:last-child { border-block-end:0; }
.sa-section-head { position:relative; isolation:isolate; }
.sa-section-titles { position:relative; padding:clamp(1.15rem,3.5cqi,2.5rem); }
.sa-reader .sa-section-head h3 { margin:.46rem 0 0; font:400 clamp(1.95rem,5.7cqi,4.1rem)/1.03 var(--sa-serif); letter-spacing:-.055em; color:inherit; text-wrap:balance; overflow-wrap:anywhere; }
.sa-folio { display:inline-flex; align-items:center; gap:.3rem; font:550 .66rem/1.2 var(--sa-mono); letter-spacing:.04em; }
.sa-folio span::before { content:counter(sa-section,decimal-leading-zero); }
.sa-folio::before { content:""; display:block; width:1.6rem; height:1px; background:currentColor; margin-inline-end:.22rem; }
.sa-cover { min-height:clamp(12rem,30cqi,18rem); display:flex; align-items:end; color:white; background:#313131; }
.sa-cover-img { z-index:-2; position:absolute; inset:0; width:100%; height:100%; object-fit:cover; filter:grayscale(1); }
.sa-cover::before { content:""; z-index:-1; position:absolute; inset:0; background:linear-gradient(180deg,#0000 18%,#0005 58%,#000d 100%); }
.sa-reader .sa-caption { margin:.52rem clamp(1.15rem,3.5cqi,2.5rem) 0; color:var(--sa-muted); font:.66rem/1.5 var(--sa-mono); overflow-wrap:anywhere; }
.sa-copy { padding:.8rem clamp(1.15rem,3.5cqi,2.5rem) clamp(1.4rem,4cqi,2.9rem); }
.sa-section-head:not(.sa-cover) + .sa-copy { padding-top:0; }
.sa-reader .sa-copy p { max-width:65ch; margin:.74rem 0 0; color:var(--sa-muted); font:400 .96rem/1.62 Inter,"Helvetica Neue",Arial,sans-serif; overflow-wrap:anywhere; }
.sa-reader .sa-copy p:first-child { margin-top:0; }
.sa-reader .sa-copy .sa-lead { color:var(--sa-ink); font:400 clamp(1.16rem,2.6cqi,1.7rem)/1.32 var(--sa-serif); letter-spacing:-.02em; }
.sa-body { padding:clamp(.8rem,2.6cqi,1.55rem); }
.sa-list-only .sa-mast { padding:.65rem .95rem; }
.sa-reader.sa-list-only .sa-title-block h2 { font:600 .98rem/1.4 Inter,"Helvetica Neue",Arial,sans-serif; letter-spacing:-.02em; }
.sa-list-only .sa-progress > span { display:none; }
.sa-list-only .sa-progress strong { font-size:.76rem; }
.sa-list-only .sa-progress svg { width:15px; height:15px; }
.sa-reader.sa-list-only .sa-window { height:auto; max-height:var(--sa-height,7.6rem); }
.sa-list-only .sa-content > .mu-list { padding:.24rem .85rem; gap:0; }
.sa-list-only .sa-content > .mu-list > .mu-item { padding:.48rem 0; border-bottom:1px solid var(--sa-rule); }
.sa-list-only .sa-content > .mu-list > .mu-item:last-child { border-bottom:0; }
@container (min-width:44rem) {
  .sa-layout:has(> .sa-index:not([hidden])) { grid-template-columns:minmax(10.1rem,22%) minmax(0,1fr); }
  .sa-index { display:flex; flex-direction:column; min-height:0; max-height:var(--sa-height,clamp(19rem,53svh,32rem)); padding:.6rem .15rem; }
  .sa-index-title { padding:.8rem .8rem 1rem; }
  .sa-index-list { display:block; max-height:none; }
  .sa-index-list li + li { margin-top:.16rem; }
  .sa-index-list button { min-height:2.55rem; padding:.55rem .5rem; }
  .sa-index-list [aria-current="location"] .sa-index-arrow { display:block; }
}
@container (max-width:24rem) {
  .sa-progress > span { max-width:7ch; text-align:end; font-size:.56rem; }
  .sa-index-list { grid-template-columns:1fr 1fr; }
  .sa-index-list button { min-height:2rem; }
  .sa-cover { min-height:11.5rem; }
}
@media (forced-colors:active) {
  .sa-reader .sa-thumb::before { forced-color-adjust:none; background:ButtonText; border-color:Canvas; }
  .sa-reader .sa-thumb span { forced-color-adjust:none; background:repeating-linear-gradient(to bottom,Canvas 0 1px,transparent 1px 3px); }
  .sa-reader .sa-cover::before { background:Canvas; }
  .sa-reader .sa-index-list button[aria-current] { outline:1px solid Highlight; }
}
JavaScript module
JavaScript module
export function mount(root) {
  // A custom content slot can itself contain another Scroll area.
  const owned = (selector, scope = root) => [...scope.querySelectorAll(selector)]
    .filter(element => element.closest('[data-mono="scroll-area"]') === root);
  const [viewport] = owned('[data-sa-viewport]');
  const [content] = owned('[data-sa-content]');
  const [track] = owned('[data-sa-track]');
  const [thumb] = owned('[data-sa-thumb]');
  const win = root.ownerDocument.defaultView;
  if (!viewport || !content || !track || !thumb || !win.ResizeObserver) return;

  const [nav] = owned('[data-sa-nav]');
  const [indexList] = owned('.sa-index-list');
  const [progress] = owned('[data-sa-progress]');
  const [percent] = owned('[data-sa-percent]');
  const motion = win.matchMedia('(prefers-reduced-motion: reduce)');
  let buttons = [], starts = [];
  let range = 0, travel = 0, thumbHeight = 0;
  let active = -1, percentage = -1, frame = 0;
  let pointer = null, grabOffset = 0;

  function paint() {
    const top = Math.max(0, Math.min(viewport.scrollTop, range));
    const ratio = range ? top / range : 0;
    thumb.style.transform = 'translateY(' + ratio * travel + 'px)';
    if (progress) progress.style.setProperty('--sa-progress', ratio);
    const value = Math.round(ratio * 100);
    if (value !== percentage) {
      percentage = value;
      thumb.setAttribute('aria-valuenow', value);
      thumb.setAttribute('aria-valuetext', value + '% scrolled');
      if (percent) percent.textContent = value + '%';
    }
    if (!buttons.length) return;
    let index = starts.length - 1;
    if (!top) index = 0;
    else if (top < range - 1) {
      while (index > 0 && starts[index] > top + 1) index--;
    }
    if (index !== active) {
      buttons[active]?.removeAttribute('aria-current');
      buttons[index]?.setAttribute('aria-current', 'location');
      active = index;
      if (indexList && buttons[index] && indexList.scrollHeight > indexList.clientHeight) {
        const list = indexList.getBoundingClientRect();
        const item = buttons[index].getBoundingClientRect();
        if (item.top < list.top) indexList.scrollTop += item.top - list.top;
        else if (item.bottom > list.bottom) indexList.scrollTop += item.bottom - list.bottom;
      }
    }
  }

  function measure() {
    frame = 0;
    range = Math.max(0, viewport.scrollHeight - viewport.clientHeight);
    const overflow = range > 0 && viewport.clientHeight > 0;
    const focused = root.ownerDocument.activeElement;
    if (!overflow && (track.contains(focused) || nav?.contains(focused))) {
      viewport.focus({ preventScroll: true });
    }
    root.toggleAttribute('data-sa-overflow', overflow);
    track.hidden = !overflow;
    if (progress) progress.hidden = !overflow;
    const sections = nav ? owned('[data-sa-section]', content) : [];
    buttons = nav ? owned('[data-sa-jump]', nav) : [];
    if (nav) nav.hidden = !overflow || buttons.length < 2;
    const origin = viewport.getBoundingClientRect().top + viewport.clientTop - viewport.scrollTop;
    starts = sections.map(section => section.getBoundingClientRect().top - origin);
    const height = track.clientHeight;
    const minimum = Math.min(32, height / 2);
    thumbHeight = Math.min(height, Math.max(minimum, height * viewport.clientHeight / (viewport.scrollHeight || 1)));
    travel = height - thumbHeight;
    thumb.style.height = thumbHeight + 'px';
    paint();
  }

  function scheduleMeasure() {
    if (!frame) frame = win.requestAnimationFrame(measure);
  }

  function pointerY(event) {
    const rect = track.getBoundingClientRect();
    return rect.height ? (event.clientY - rect.top) * track.clientHeight / rect.height : 0;
  }

  function dragTo(event) {
    if (!travel) return;
    const ratio = (pointerY(event) - grabOffset) / travel;
    viewport.scrollTo({ top: range * Math.min(1, Math.max(0, ratio)), behavior: 'instant' });
  }

  track.addEventListener('pointerdown', event => {
    if (!event.isPrimary || event.button !== 0 || pointer !== null || !travel) return;
    event.preventDefault();
    thumb.focus({ preventScroll: true });
    pointer = event.pointerId;
    grabOffset = thumb.contains(event.target)
      ? pointerY(event) - travel * viewport.scrollTop / range
      : thumbHeight / 2;
    track.setPointerCapture(pointer);
    root.setAttribute('data-sa-dragging', '');
    dragTo(event);
  });
  track.addEventListener('pointermove', event => {
    if (event.pointerId === pointer) dragTo(event);
  });
  function stopDrag(event) {
    if (event.pointerId !== pointer) return;
    pointer = null;
    root.removeAttribute('data-sa-dragging');
    if (track.hasPointerCapture(event.pointerId)) track.releasePointerCapture(event.pointerId);
  }
  track.addEventListener('pointerup', stopDrag);
  track.addEventListener('pointercancel', stopDrag);
  track.addEventListener('lostpointercapture', stopDrag);

  thumb.addEventListener('keydown', event => {
    if (event.altKey || event.ctrlKey || event.metaKey || !range) return;
    const page = Math.max(1, viewport.clientHeight * .9);
    let top = viewport.scrollTop;
    switch (event.key) {
      case 'ArrowUp': top -= 40; break;
      case 'ArrowDown': top += 40; break;
      case 'PageUp': top -= page; break;
      case 'PageDown': top += page; break;
      case ' ': top += event.shiftKey ? -page : page; break;
      case 'Home': top = 0; break;
      case 'End': top = range; break;
      default: return;
    }
    event.preventDefault();
    viewport.scrollTo({ top, behavior: 'instant' });
  });
  nav?.addEventListener('click', event => {
    const button = event.target.closest('[data-sa-jump]');
    if (!button || !nav.contains(button)) return;
    const target = starts[Number(button.dataset.saJump)];
    if (target !== undefined) viewport.scrollTo({ top: target, behavior: motion.matches ? 'instant' : 'smooth' });
  });

  root.setAttribute('data-sa-enhanced', '');
  viewport.addEventListener('scroll', paint, { passive: true });
  const resize = new win.ResizeObserver(scheduleMeasure);
  for (const box of [viewport, content, track]) resize.observe(box);
  if (nav) for (const section of owned('[data-sa-section]', content)) resize.observe(section);
  content.addEventListener('load', scheduleMeasure, true);
  measure();
}
Use the HTML in a static site

Copy the rendered HTML above. Download these assets into the same folder as your page, then add the tags below to its head.

Shared CSS Component CSS Ready-to-use module

HTML head
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./scroll-area.css">
<script type="module" src="./scroll-area.js"></script>

Copy into your project

Run this command from the Mono checkout. Set -out to the component directory in your application.

Terminal
go run ./cmd/mono-ui add -out ./components scroll-area
Example properties (JSON)
example.json
{
  "Description": "Field notes on four spaces shaped by daylight.",
  "Label": "A study in light",
  "Sections": [
    {
      "Alt": "A row of stone arches casts curved shadows across the floor of an open courtyard.",
      "Caption": "Arcade Court · Turin",
      "ImageURL": "../components/projects/architecture/arcade-court-720.webp",
      "Paragraphs": [
        "Look along the paving and the arches become a sequence of dark pools. Look across the court and the same openings frame the sunlit wall opposite."
      ],
      "Text": "In the covered walk, a few steps carry you from cool shade into the bright court. Each arch draws the boundary again.",
      "Title": "Beneath the arcade"
    },
    {
      "Alt": "A long, low concrete house extends over a rocky stretch of water beneath pine branches.",
      "Caption": "Harbor House · Seto Inland Sea",
      "ImageURL": "../components/projects/architecture/harbor-house-720.webp",
      "Paragraphs": [
        "The underside of the roof stays dark while the water catches the sky. The narrow band between them changes whenever a ripple passes."
      ],
      "Text": "A concrete roof reaches past the glass. From under its edge, the horizon seems close enough to draw with a ruler.",
      "Title": "At the waterline"
    },
    {
      "Alt": "A dark pool and a flight of steps sit between tall, pale quarry walls.",
      "Caption": "Quarry Baths · Limestone pool",
      "ImageURL": "../components/projects/architecture/quarry-baths-720.webp",
      "Paragraphs": [
        "The brightest surface is the narrow walkway beside the water. It leads the eye to the steps, where each tread catches a different amount of light."
      ],
      "Text": "At the foot of the cut stone, the pool holds a second set of walls. A passing ripple briefly breaks their straight edges.",
      "Title": "Inside the quarry"
    },
    {
      "Alt": "A small timber studio stands on a wooded slope with light filtering between the trunks.",
      "Caption": "Cedar Studio · Woodland elevation",
      "ImageURL": "../components/projects/architecture/cedar-studio-720.webp",
      "Paragraphs": [
        "From the slope below, the window reads as a pale rectangle among the trunks. The roof nearly disappears into the canopy behind it."
      ],
      "Text": "Daylight reaches the studio in narrow shafts. The forest floor stays dim even as the branches overhead catch the sun.",
      "Title": "Among the cedars"
    }
  ]
}