How to Check Every Section on a Page Lines Up
Nov 17, 2026
Most of the pages I build are a stack of sections: services, projects, reviews, contact. Each one wraps its content in a container that caps the width and centers it. When every container uses the same max-width, every heading starts at the same spot down the left side of the page.
When one doesn't, that section's heading sits a little left or right of the others. It's a small offset, and it's easy to miss for two reasons. It never causes horizontal scroll, so an overflow check won't catch it. And it only shows up on screens wider than the smaller cap. Below that, both containers fill the screen and everything lines up.
A Playwright Script to Compare Section Alignment
This measures where each section's first heading starts, finds the most common position, and flags anything else. Save it as check-alignment.mjs (you'll need Playwright):
import { chromium } from 'playwright';
const url = process.argv[2] ?? 'http://localhost:8080/';
const width = Number(process.argv[3] ?? 1920);
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width, height: 1000 } });
await page.goto(url, { waitUntil: 'networkidle' });
const rows = await page.evaluate(() =>
[...document.querySelectorAll('section')].map((section) => {
const heading = section.querySelector('h1, h2, h3');
if (!heading) return null;
const box = heading.getBoundingClientRect();
return { heading: heading.textContent.trim().slice(0, 40), left: Math.round(box.left) };
}).filter(Boolean)
);
await browser.close();
const counts = {};
rows.forEach((r) => (counts[r.left] = (counts[r.left] ?? 0) + 1));
const common = Number(Object.keys(counts).sort((a, b) => counts[b] - counts[a])[0]);
for (const r of rows) {
const flag = r.left === common ? 'ok' : `OFF by ${r.left - common}px`;
console.log(`${String(r.left).padStart(5)}px ${flag.padEnd(14)} ${r.heading}`);
}Run it with a URL and a width: node check-alignment.mjs http://localhost:8080/ 1920.
Example: One Section 100px Off
I built a test page with four sections. Three containers cap at 1200px; the "Recent Projects" one caps at 1400px. At 1920:
360px ok Our Services
260px OFF by -100px Recent Projects
360px ok Reviews
360px ok Contact UsAt 1024, the same page:
16px ok Our Services
16px ok Recent Projects
16px ok Reviews
16px ok Contact UsEvery container is wider than a 1024px screen, so they all fill it and the problem disappears. That's why I always run it at 1920. If you test on a laptop, the widest container cap on your site is probably bigger than your screen, and you'll never see this one by eye.
It assumes your sections are <section> elements with a heading inside. If your markup is different, change the two selectors and the rest still works.



Comments
Leave a Comment