How to Build an Accessible Reading Ruler & Focus Guide in CSS & JavaScript

The Quick Answer

An accessible reading ruler helps neurodivergent readers (such as individuals with dyslexia or ADHD) track lines of text without visual wandering. To build one in CSS and JavaScript, track the cursor Y-coordinate with pointermove and translate a horizontal highlighted band (typically 36px to 48px height) using transform: translateY(y) and pointer-events: none. Alternatively, use an inverted box-shadow like box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5) or CSS mask-image to dim the rest of the screen.

Interactive Demo Live Preview
Line 1: Typography design tokens establish visual rhythm across digital interfaces.
Line 2: Active Reading Ruler focus line keeps reader attention locked to the current sentence.
Line 3: Background dimming eliminates peripheral clutter and eye fatigue.

Step 1: The Two Modes: Highlight Band vs Screen Dimmer

Reading rulers generally operate in two visual modalities: "Highlight Band" (a semi-transparent yellow or cyan bar that glides under the current line) and "Screen Dimmer" (where the entire screen is darkened except for a transparent slit centered over the active sentence).

ruler-modes.css
/* Mode 1: Highlight Band */
.ruler-band {
  position: fixed;
  left: 0;
  width: 100%;
  height: 40px;
  background: rgba(254, 240, 138, 0.35); /* Yellow Marker Tint */
  border-bottom: 2px solid #eab308;
  pointer-events: none;
  z-index: 9999;
}

/* Mode 2: Inverted Screen Dimmer Slit */
.ruler-dimmer {
  position: fixed;
  left: 0;
  width: 100%;
  height: 48px;
  /* Giant box-shadow dims the entire viewport around the slit */
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6);
  pointer-events: none;
  z-index: 9999;
}

Step 2: 60 FPS Cursor Tracking with pointer-events: none

The reading ruler must never intercept mouse clicks or text selections. Adding pointer-events: none lets user interaction pass through directly to underlying links. Animate movement using transform: translateY().

ruler-tracking.js
const ruler = document.getElementById('readingRuler');

window.addEventListener('pointermove', (e) => {
  const y = e.clientY - (ruler.offsetHeight / 2);
  ruler.style.transform = `translate3d(0, ${y}px, 0)`;
});

Step 3: Customizable Ruler Heights & Tint Controls

Reading preferences vary dramatically across readers with dyslexia. Allow users to adjust ruler height (to match 1 line, 2 lines, or 3 lines of copy) and swap tint colors (warm yellow, soft rose, calming blue) via CSS custom properties.

ruler-variables.css
:root {
  --ruler-height: 42px;
  --ruler-tint: rgba(186, 230, 253, 0.3); /* Calming Soft Blue */
  --ruler-border: #38bdf8;
}

.ruler-custom {
  height: var(--ruler-height);
  background: var(--ruler-tint);
  border-bottom: 2px solid var(--ruler-border);
}

Step 4: Persistence with localStorage & Keyboard Toggle

Allow users to toggle the reading ruler using an accessible keyboard shortcut (like Alt + R) and persist their active preference in localStorage.

ruler-storage.js
// Toggle ruler on Alt + R
window.addEventListener('keydown', (e) => {
  if (e.altKey && e.key.toLowerCase() === 'r') {
    ruler.classList.toggle('active');
    localStorage.setItem('readingRulerActive', ruler.classList.contains('active'));
  }
});

Next-Level Addons: Elevating Your Implementation

Take this technique further by combining it with complementary design token studios and animation tools:

Mode: Dimmer Slit A11Y READY

1. Reading Ruler Studio in Interaction Studio

Explore in Reading Ruler Studio →

Test highlight bands, screen dimmer masks, tint palettes, and customize ruler line heights in real time.

Permanent Marker Highlight

2. Highlighter Effects in Highlighter Studio

Explore in Highlighter Studio →

Combine line reading rulers with permanent hand-drawn marker pen annotations for long-form documentation.

Contrast: 7.8:1 (Safe Over Tint)

3. Contrast Safety in Contrast Checker Studio

Explore in WCAG & APCA Color Contrast Checker →

Audit that reading ruler tint colors do not lower text contrast below WCAG AA thresholds.

Chaam
Chaam's Pro Tip

Here's my golden rule when implementing this in production: test across multiple devices and browsers early. Keep your DOM hierarchy shallow, optimize assets with modern formats (like WebP/AVIF), and verify keyboard navigation for accessibility.

Why I Built the Reading Ruler Studio

I got tired of guessing values and testing browser quirks in DevTools, so I built this tool to tweak and preview values in real time with 1-click code export.

Open in Reading Ruler Studio ↗

Frequently Asked Questions

Practical answers to common implementation questions, browser quirks, and performance tips.

How does a reading ruler benefit readers with dyslexia or ADHD?

Visual crowding and tracking fatigue cause readers with dyslexia to lose their place between lines of text. A reading ruler isolates the active sentence, eliminating peripheral line clutter and reducing cognitive load.

How does the giant box-shadow screen dimmer trick work?

Declaring box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.6) on an element casts a 9,999px spread shadow outward in all directions, dimming the entire screen except for the transparent element itself.

Why must the reading ruler have pointer-events: none?

If pointer events are enabled on the ruler, moving the mouse over the page intercepts all click, hover, and selection events, making it impossible to click links or select text.

Can the reading ruler snap to lines of text automatically?

Yes. By measuring line heights (e.g. getComputedStyle(p).lineHeight) and finding the nearest line bounding box via document.elementFromPoint, you can snap the ruler to discrete lines of text.

What are the most popular tint colors for dyslexia reading overlays?

Pastel yellow (warmth), soft turquoise/cyan (reduced glare), and light peach are the most widely recommended tint overlays in optical accessibility research.

← Back to all blog guides Launch Generator Studio →