Lighthouse & HTML Auditing
By the end of this lesson you will be able to run a Lighthouse audit on any page, read every part of the report, and fix the HTML problems it points out: missing alt text, a missing title or lang, no viewport tag, small touch targets and render-blocking files. You will also run it from the command line and learn why the score changes a little every time.
What you should know first: HTML Performance Optimization, HTML Accessibility Fundamentals and HTML Testing & Quality Assurance. Lighthouse Performance Auditing goes deep on the performance side later.
What Lighthouse is
Lighthouse is a free, open-source tool from the Chrome team. It loads a page, watches what happens, runs a long list of checks called audits, and writes a report with scores and advice. It is built into Chrome's developer tools (DevTools), and it also runs from the command line and inside PageSpeed Insights.
Lighthouse is a lab tool. It tests one page load, on one machine, under conditions it controls. Think of the driving test at an RTO track in Lucknow: the examiner sees how you handle a fixed course on a quiet morning. It is fair and repeatable, but it is not real traffic at 6 pm. Data from real visitors is called field data.
All results in this lesson come from Lighthouse 13.6, the version we checked in November 2026.
Step 1: run Lighthouse in Chrome DevTools
- Open the page in a Chrome Incognito window, which usually runs without extensions that could skew the results.
- Press F12 (or Ctrl+Shift+I) and open the Lighthouse panel. If you cannot see it, look under the
>>menu. - Leave Mode on Navigation. It reloads the page and measures the load. (Timespan records while you click around; Snapshot checks the page as it is right now, without reloading.)
- Choose Device: Mobile (the default) or Desktop. Mobile is stricter and matches how most Indian visitors browse.
- Tick the categories you want, then click Analyze page load.
After about 20 to 60 seconds, the report appears with a row of score circles at the top.
The categories
| Category | Question it answers | Score |
|---|---|---|
| Performance | How quickly does the page load and respond? | 0-100 |
| Accessibility | Can people using assistive technology use it? | 0-100 |
| Best Practices | Does it follow safe, modern web practices? | 0-100 |
| SEO | Can search engines read and understand it? | 0-100 |
| Agentic Browsing | Can AI agents read and use it? | A ratio of checks passed |
The first four are the classic scored categories. Scores from 90 to 100 are green (good), 50 to 89 orange (needs improvement) and 0 to 49 red (poor).
Reading the report
Each category opens into sections:
- Metrics (Performance only): measured numbers such as First Contentful Paint, Largest Contentful Paint (LCP), Total Blocking Time and Cumulative Layout Shift (CLS). Only these metrics make up the Performance score.
- Insights (Performance): suggestions linked to the metrics, such as "Render-blocking requests". In Lighthouse 13 these replaced most of the older performance audits, so an old tutorial may use different names.
- Failed audits in the other categories. Expand one to see the HTML elements that failed.
- Passed audits and Not applicable: collapsed lists of what is already fine.
- Additional items to manually check: things a machine cannot judge, such as logical focus order. Lighthouse is telling you to test these yourself.
HTML audits you will meet most
Many failures are plain HTML mistakes. The titles below are exactly as Lighthouse 13.6 shows them when the audit fails.
| Failing audit title | Category | The HTML fix |
|---|---|---|
Image elements do not have [alt] attributes | Accessibility, SEO | Add alt text (or alt="" for decoration) |
Document doesn't have a <title> element | Accessibility, SEO | Add a unique <title> in <head> |
<html> element does not have a [lang] attribute | Accessibility | <html lang="en-IN"> |
| Optimize viewport for mobile | Performance (insight) | <meta name="viewport" content="width=device-width, initial-scale=1"> |
| Touch targets do not have sufficient size or spacing. | Accessibility | Make buttons and links at least 24 by 24 CSS pixels, or space them apart |
| Render-blocking requests | Performance (insight) | defer scripts; inline small critical CSS |
| Document does not have a meta description | SEO | Add <meta name="description" content="..."> |
| Links do not have a discernible name / Buttons do not have an accessible name | Accessibility | Give icon-only links and buttons text or aria-label |
Image elements do not have explicit width and height | Performance (diagnostic) | Add width and height to prevent layout shift |
Touch targets used to be an SEO audit called "tap targets". Since Lighthouse 12 the check lives in Accessibility, based on the 24-pixel minimum in WCAG 2.2. You can see why size matters in the demo below. It measures each button the same way the audit does.
<!DOCTYPE html>
<html lang="en-IN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Touch target sizes</title>
<style>
body { font-family: system-ui, sans-serif; margin: 16px; }
.tiny button { font-size: 10px; padding: 0 2px; margin: 0; }
.good button { min-width: 44px; min-height: 44px; margin: 4px; }
li.fail { color: #b00020; }
</style>
</head>
<body>
<h1>Quantity for Jaipur Blue Pottery mug</h1>
<p class="tiny">Too small: <button type="button">-</button><button type="button">+</button></p>
<p class="good">Comfortable: <button type="button">-</button><button type="button">+</button></p>
<h2>Measured sizes</h2>
<ul id="sizes"></ul>
<script>
for (const button of document.querySelectorAll("button")) {
const box = button.getBoundingClientRect();
const ok = box.width >= 24 && box.height >= 24;
const li = document.createElement("li");
li.className = ok ? "" : "fail";
li.textContent = `"${button.textContent}" in ${button.parentElement.className} row: ` +
`${Math.round(box.width)} x ${Math.round(box.height)} px, ${ok ? "OK" : "below 24 px"}`;
document.querySelector("#sizes").append(li);
}
</script>
</body>
</html>The real audit also passes a small target if it has enough empty space around it, hence "or spacing" in its title.
Step 2: audit a broken page and fix it
Here is a small page with typical mistakes, served from a local test server:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Kochi Spice House</h1>
<img src="pepper.png">
<p>Fresh black pepper from Idukki, ₹450 per kg.</p>
<a href="#"><span class="icon"></span></a>
<button class="icon"></button>
</body>
</html>The external stylesheet is render-blocking: the browser waits for it before drawing anything. The first tryit below lets you spot such problems in a page's <head> yourself, before Lighthouse does.
<!DOCTYPE html>
<html lang="en-IN">
<head>
<meta charset="utf-8">
<title>Head checker</title>
<style>
body { font-family: system-ui, sans-serif; margin: 16px; }
textarea { width: 100%; height: 9rem; font-family: monospace; }
</style>
</head>
<body>
<label for="src">Paste a page's HTML:</label>
<textarea id="src"><html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="print.css" media="print">
<script src="slider.js"></script>
<script src="app.js" defer></script>
</head>
<body><h1>Kochi Spice House</h1><img src="pepper.png"></body>
</html></textarea>
<p><button type="button" id="run">Check</button></p>
<ul id="out"></ul>
<script>
function check() {
const doc = new DOMParser().parseFromString(document.querySelector("#src").value, "text/html");
const found = [];
if (!doc.documentElement.getAttribute("lang")) found.push("No lang on <html>");
if (!doc.querySelector("title")) found.push("No <title>");
if (!doc.querySelector('meta[name="viewport"]')) found.push("No meta viewport");
if (!doc.querySelector('meta[name="description"]')) found.push("No meta description");
doc.querySelectorAll("img:not([alt])").forEach((img) => found.push(`Image ${img.getAttribute("src")} has no alt`));
doc.head.querySelectorAll('link[rel="stylesheet"]').forEach((link) => {
const media = link.getAttribute("media");
if (!media || media === "all" || media === "screen") found.push(`Render-blocking CSS: ${link.getAttribute("href")}`);
});
doc.head.querySelectorAll("script[src]").forEach((s) => {
if (!s.defer && !s.async && s.type !== "module") found.push(`Render-blocking script: ${s.getAttribute("src")}`);
});
const out = document.querySelector("#out");
out.replaceChildren(...(found.length ? found : ["No problems found"]).map((text) => {
const li = document.createElement("li");
li.textContent = text;
return li;
}));
}
document.querySelector("#run").addEventListener("click", check);
check();
</script>
</body>
</html>The checker lists seven problems, including style.css and slider.js as render-blocking. print.css is not blocking, because its media="print" tells the browser it is not needed for the screen, and app.js has defer. Lighthouse also weighs how long each file takes, but the rules are the same.
Running Lighthouse on the broken page and then on a fixed version (with lang, a title, a description, the viewport tag, alt, width and height, a <main>, labelled 48-pixel icon buttons, CSS inlined in a <style> element and a robots.txt file) gave these scores:
Lighthouse 13.6.0, mobile Performance: 96 Accessibility: 28 Best Practices: 100 SEO: 67 Agentic Browsing: 1/4 checks passed Lighthouse 13.6.0, mobile Performance: 100 Accessibility: 100 Best Practices: 100 SEO: 100 Agentic Browsing: 2/4 checks passed
The broken page still scored 96 for Performance because it is tiny: a fast page can still be unusable. Accessibility jumped from 28 to 100 with HTML fixes alone. The remaining Agentic Browsing failures needed an llms.txt file and an agent manifest, outside this lesson.
Step 3: Lighthouse from the command line
The command-line version suits many pages and automation. It needs Node.js (Lighthouse 13 asks for version 22.19 or newer) and an installed Chrome:
npm install -g lighthouse
lighthouse http://localhost:8080/ --view
lighthouse http://localhost:8080/ --only-categories=accessibility,seo --view
lighthouse http://localhost:8080/ --preset=desktop --output=json --output-path=./report.json
lighthouse http://localhost:8080/ --quiet --chrome-flags="--headless=new" --output=json --output-path=./report.json--view opens the HTML report afterwards, --only-categories skips the rest, --preset=desktop tests as a desktop, and --output=json saves the results as data. The score lines above came from a few lines of Node.js reading that JSON file:
import { readFileSync } from "node:fs";
const report = JSON.parse(readFileSync(process.argv[2], "utf8"));
console.log(`Lighthouse ${report.lighthouseVersion}, ${report.configSettings.formFactor}`);
for (const [id, category] of Object.entries(report.categories)) {
if (id === "agentic-browsing") {
const audits = category.auditRefs.map((ref) => report.audits[ref.id]);
const applicable = audits.filter((audit) => audit.score !== null);
const passed = applicable.filter((audit) => audit.score === 1);
console.log(`${category.title}: ${passed.length}/${applicable.length} checks passed`);
} else {
console.log(`${category.title}: ${Math.round(category.score * 100)}`);
}
}In the JSON, each category score runs from 0 to 1, and each audit has its own score and title. Teams use this to fail a build when, say, accessibility drops below 90.
Why lab scores vary
Run Lighthouse three times and the Performance score may read 82, 88 and 85. That is normal. In mobile mode, Lighthouse simulates a mid-range phone: our run used a 412 by 823 pixel screen, a CPU slowed down four times, and a slow network (150 ms round trip, about 1.6 Mbps). The simulation starts from your real machine and connection, so other programs using the CPU, extensions, your network, the server's response time and ads or A/B tests that change each load all move the result.
To get a trustworthy number, run it three to five times and use the middle (median) result, on the same machine and settings each time. For real-world speed, look at field data from real Chrome users, which PageSpeed Insights shows above its lab results when a site has enough traffic. Lighthouse Performance Auditing explains that difference in depth.
Common mistakes
- Chasing 100 instead of fixing users' problems. A score is a summary; read the failed audits and the manual-check list.
- Auditing with extensions running. Use Incognito or a clean browser profile.
- Thinking a 100 Accessibility score means accessible. Lighthouse runs only automated checks; keyboard and screen reader testing are still needed.
Interview questions
1. What are the main Lighthouse categories?
Performance, Accessibility, Best Practices and SEO each get a score from 0 to 100. Since Lighthouse 13.3 (Chrome 150) there is also an informational Agentic Browsing category, shown as a ratio of passed checks. The old PWA category was removed in Lighthouse 12.
2. What is the difference between lab data and field data?
Lab data comes from a controlled test such as Lighthouse: one load, simulated device and network, repeatable and good for debugging. Field data comes from real users over time, for example the Chrome UX Report shown in PageSpeed Insights. Field data reflects real experience, while lab data explains why a page is slow.
3. Why might two Lighthouse runs give different Performance scores?
The simulation starts from the real machine and network, so CPU load, extensions, network speed, server response time and changing third-party content all affect it. The median of several runs reduces the noise.
4. Name three Lighthouse audits you can fix with HTML alone.
Missing alt attributes on images, a missing <title> element, and a missing lang attribute on <html>. A meta viewport tag, a meta description and image width and height are others.
5. What makes a script render-blocking, and how do you fix it?
A classic <script src> in the <head> without defer, async or type="module" stops HTML parsing until it downloads and runs, so nothing can be drawn. Adding defer lets the HTML parse first and runs the script afterwards in order. Stylesheets block rendering too, unless their media attribute does not match the current screen.
Key points
- Lighthouse is a free lab tool built into Chrome DevTools, available as a command and inside PageSpeed Insights.
- It scores Performance, Accessibility, Best Practices and SEO from 0 to 100; Agentic Browsing (Lighthouse 13.3 and later) shows a ratio of checks.
- Read the failed audits, insights and the manual-check list, not just the score.
- Many failures are HTML fixes:
alt,<title>,lang, viewport, meta description, accessible names, image dimensions, 24-pixel touch targets. - The CLI (
lighthouse <url> --view,--output=json) supports automation and needs Node.js and Chrome. - Performance scores vary between runs; use Incognito, the same settings and the median of several runs, and compare with field data.
Exercise
Choose a page you built earlier, such as your Level 2 business website. Run Lighthouse in an Incognito window in Mobile mode and write down the four main scores. List every failed Accessibility and SEO audit, fix the ones you can with HTML, and run the audit three more times. Report the median Performance score before and after, and one item from "Additional items to manually check" that you tested by hand.
Show solution
A typical before-and-after record:
Page: index.html (business website), Lighthouse 13.6, Mobile, Incognito
Before: Performance 71, 74, 69 (median 71) | Accessibility 78 | Best Practices 96 | SEO 82
Failed: image-alt (3 images), html-has-lang, meta-description, button-name (menu icon),
target-size (footer social icons), Render-blocking requests (slider.js)
Fixes: alt text on 3 images; <html lang="en-IN">; meta description;
aria-label="Open menu" on the icon button; social icons 44 x 44 px;
defer on slider.js
After: Performance 86, 84, 88 (median 86) | Accessibility 100 | Best Practices 96 | SEO 100
Manual: tabbed through the whole page; focus order followed the visual orderYour numbers will differ. What matters is that each failed audit maps to a specific HTML change, the medians come from several runs, and you tested at least one manual item yourself.
Quick Quiz
1. Which category was removed from Lighthouse in version 12?
The PWA category was removed in Lighthouse 12; SEO and Best Practices remain.
2. A page scores 100 in Accessibility. What can you conclude?
Automated audits cover only what a machine can measure.
3. What is the best way to get a reliable Performance score?
Lab scores vary between runs, so the median of several runs is more trustworthy.
4. Which change fixes the "Render-blocking requests" insight for <script src="slider.js"> in the head?
defer lets the HTML parse and render first and runs the script afterwards.
Learn HTML with a mentor
Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.
- Project-based learning
- Mentor code reviews
- Free counselling call
