๐งช Lesson 20: Testing & Validation
Your site is built and polished โ but how do you know it actually works? Not just on your laptop, in your favorite browser, at your screen size. What about someone on a phone? On Firefox? Using a screen reader? With slow internet? Testing answers these questions. In this lesson, you'll validate your code, audit performance and accessibility, test across browsers and devices, and fix the issues that testing reveals. This is the step that separates "it works for me" from "it works for everyone."
๐ฏ Learning Objectives
By the end of this lesson, you will be able to:
- Validate HTML using the W3C Markup Validation Service
- Validate CSS using the W3C CSS Validation Service
- Run a Lighthouse audit and interpret the scores
- Test your site in multiple browsers and screen sizes
- Check accessibility with automated tools and manual keyboard testing
- Identify and fix the most common HTML/CSS errors
- Create a pre-launch checklist for any future project
Estimated Time: 45โ60 minutes
Prerequisites: Lesson 19 (Adding Polish) โ all four pages complete with polish features.
๐ In This Lesson
Why Testing Matters
You've been checking your site in the browser as you built it โ that's informal testing, and it's a good habit. But it has blind spots. You've only tested in one browser, at one screen size, with your eyes. Formal testing covers the gaps:
- Validation catches typos and structural errors in your HTML and CSS that browsers silently forgive but that can cause unpredictable behavior.
- Lighthouse measures performance, accessibility, SEO, and best practices โ things you can't evaluate by just looking at a page.
- Cross-browser testing reveals rendering differences between Chrome, Firefox, Safari, and Edge.
- Accessibility testing ensures your site works for people who navigate with keyboards, screen readers, or assistive devices.
Think of testing as a safety net, not a punishment. Every bug you catch now is a bug your visitors never encounter.
HTML Validation
The W3C Markup Validation Service checks your HTML against the official specification. It catches errors that browsers ignore โ like unclosed tags, duplicate IDs, or missing required attributes โ that can cause subtle layout problems or accessibility issues.
How to Validate
- Open validator.w3.org
- Choose the "Validate by Direct Input" tab
- Copy-paste your entire HTML file into the text box
- Click "Check"
- Review the results โ fix errors (red), consider warnings (yellow)
Repeat for every HTML file in your project. Yes, all four.
Common HTML Errors and Fixes
| Error | What It Means | Fix |
|---|---|---|
End tag for "div" omitted |
A <div> was opened but never closed |
Find the unclosed <div> and add </div>. Use VS Code's bracket matching (Ctrl+Shift+\) to find the partner. |
Duplicate ID "name" |
Two elements have the same id attribute |
IDs must be unique per page. Rename one of them. |
Element "li" not allowed as child of "div" |
A <li> is outside a <ul> or <ol> |
Wrap list items in their proper parent element. |
Attribute "alt" required on "img" |
An image is missing alternative text | Add alt="description" to every <img>. Use alt="" (empty) for purely decorative images. |
The "for" attribute value must refer to an ID |
A <label for="x"> doesn't match any element's id |
Make sure the for and id values match exactly, including case. |
Stray end tag "div" |
An extra closing </div> with no matching opening tag |
Delete the extra closing tag. Count your opening and closing tags โ they should match. |
๐ก VS Code Helps You Catch Errors Early
Install the HTMLHint or W3C Web Validator VS Code extension to see validation errors in real time as you type, without leaving your editor. Squiggly red underlines in your code mean something needs attention.
CSS Validation
The W3C CSS Validation Service checks your stylesheet for syntax errors, unknown properties, and incorrect values.
How to Validate
- Open jigsaw.w3.org/css-validator
- Choose "By direct input"
- Paste your
style.csscontent - Click "Check"
Common CSS Errors and Fixes
| Error | What It Means | Fix |
|---|---|---|
Property "colour" doesn't exist |
Typo in a property name | Check spelling. CSS uses American English: color, not colour. |
Value error: "20 px" is not valid |
Space between number and unit | Remove the space: 20px, not 20 px. Exception: 0 needs no unit. |
Missing semicolon |
A declaration is missing its ending ; |
Add the semicolon. The last declaration in a block doesn't technically need one, but always include it. |
Unknown pseudo-element "::placeholder-shown" |
The validator may not recognize newer CSS features | If the feature works in browsers, the warning is safe to ignore. The validator can lag behind the spec. |
๐ก Warnings vs. Errors
Errors are things that are definitely wrong โ typos, invalid syntax, missing values. Always fix these. Warnings are suggestions or things the validator can't fully check โ like custom properties (var(--color-primary)) or newer features. Warnings are usually safe to acknowledge and move on.
Lighthouse Audits
Lighthouse is a free tool built into Chrome DevTools that audits your page across four categories: Performance, Accessibility, Best Practices, and SEO. It gives each category a score from 0โ100 and tells you exactly what to fix.
How to Run a Lighthouse Audit
- Open your site in Chrome (use Live Server)
- Open DevTools (F12 or Ctrl+Shift+I)
- Click the Lighthouse tab (you may need to click
ยปto find it) - Select categories: Performance, Accessibility, Best Practices, SEO
- Choose Mobile device (the stricter test)
- Click "Analyze page load"
- Wait about 30 seconds for the results
Understanding the Scores
| Score | Rating | What It Means |
|---|---|---|
| 90โ100 | ๐ข Good | Your page performs well in this category |
| 50โ89 | ๐ Needs improvement | There are opportunities to improve |
| 0โ49 | ๐ด Poor | Significant issues need attention |
Common Lighthouse Fixes
- "Image elements do not have explicit width and height" โ add
widthandheightattributes to every<img>tag. This prevents layout shifts as images load. - "Links do not have discernible names" โ add text content or
aria-labelto links that only contain icons or images. - "Background and foreground colors do not have sufficient contrast" โ your text color is too similar to its background. Use a contrast checker to fix.
- "Document does not have a meta description" โ add
<meta name="description" content="...">to the<head>of every page. - "Properly size images" โ don't serve a 4000px-wide image for a 400px card. Resize images to match their display size.
๐ก Don't Chase Perfection
A perfect 100 in every category is nice for bragging rights but not required. For a first project, aim for: Performance 80+, Accessibility 90+, Best Practices 90+, SEO 90+. Accessibility is the most important โ a low accessibility score means some visitors literally can't use your site.
Cross-Browser Testing
Different browsers render CSS slightly differently. A layout that looks perfect in Chrome might have spacing issues in Safari or font rendering differences in Firefox. Testing across browsers catches these inconsistencies.
Which Browsers to Test
| Priority | Browser | Why |
|---|---|---|
| ๐ด Must test | Chrome (Desktop + Mobile) | ~65% of global web traffic |
| ๐ด Must test | Safari (iOS) | ~25% of mobile traffic; unique rendering engine |
| ๐ Should test | Firefox | Different engine; great DevTools; ~3% traffic |
| ๐ข Nice to test | Edge | Chromium-based; usually matches Chrome |
How to Test Without Owning Every Device
- Chrome DevTools Device Mode โ Ctrl+Shift+M simulates different screen sizes and devices. Not a true browser test, but catches responsive issues.
- Firefox โ free to install on any OS. Open your site with Live Server and test.
- Safari (if you have a Mac or iPhone) โ test on an actual iOS device if possible. Safari on iOS has the most rendering quirks.
- BrowserStack โ paid service with a free trial. Test on real browsers and devices in the cloud.
- Ask friends and family โ the best testing is real people on real devices. Send them your Netlify link (coming in Lesson 21) and ask them to check it on their phones.
What to Look For
- Layout โ do cards stay in rows? Does the nav collapse correctly? Does the footer sit at the bottom?
- Typography โ do fonts load? Is text readable? Are line lengths comfortable?
- Interactions โ do hover effects work? Does the mobile menu toggle? Does dark mode apply?
- Images โ do they load? Are they the right size? Do rounded corners display correctly?
- Forms โ do inputs focus correctly? Does validation feedback show? Can you submit?
Responsive Testing
Testing at specific breakpoints isn't enough โ real devices have unpredictable screen widths. Test by slowly dragging the browser window from wide to narrow and watching for layout breaks.
Key Widths to Check
| Width | Device | What to Check |
|---|---|---|
| 375px | iPhone SE / small phones | Single-column layout, hamburger menu, readable text |
| 390px | iPhone 14 / modern phones | Same as above with slightly more space |
| 768px | iPad / tablets (portrait) | Breakpoint boundary โ nav should switch, cards may be 2-across |
| 1024px | iPad landscape / small laptops | Desktop layout should be active, cards 3-across |
| 1440px | Standard desktop | Content should be centered with comfortable margins |
| 1920px+ | Large/ultrawide monitors | Content shouldn't stretch to full width โ max-width keeps it readable |
The Drag Test
- Open your site in the browser
- Grab the right edge of the browser window
- Slowly drag it narrower, watching for anything that breaks
- Note the exact width where issues appear (DevTools shows the width in the top-right of the viewport when resizing)
- Fix the issue with a media query or by adjusting your Flexbox/Grid values
๐ก Common Responsive Issues
- Horizontal scrollbar appears โ something is wider than the viewport. Check for fixed-width elements, images without
max-width: 100%, or padding causing overflow. - Text overflows its container โ long words or URLs can break out. Fix with
overflow-wrap: break-word. - Touch targets too small โ buttons and links on mobile should be at least 44ร44px. Increase padding if needed.
Accessibility Testing
Automated tools catch about 30โ50% of accessibility issues. The rest require manual testing. A complete accessibility check includes both.
Automated Testing
Lighthouse's accessibility audit is a good start. For deeper analysis, install the axe DevTools browser extension (free):
- Install the axe DevTools extension for Chrome
- Open DevTools โ find the axe tab
- Click "Scan ALL of my page"
- Review the results โ each issue includes a description, severity, and how to fix it
Manual Keyboard Testing
Put your mouse aside and navigate your entire site using only the keyboard:
| Key | Action |
|---|---|
| Tab | Move to the next interactive element |
| Shift+Tab | Move to the previous interactive element |
| Enter | Activate a link or button |
| Space | Activate a button, check a checkbox, scroll down |
| Escape | Close a dialog or dropdown |
| Arrow keys | Navigate within menus, radio groups, selects |
Keyboard Testing Checklist
- Can you see where focus is at all times? (The focus ring should be clearly visible)
- Does the skip-to-content link appear when you first press Tab?
- Can you navigate all menu items and links?
- Can you open and close the mobile menu with the keyboard?
- Can you fill out and submit the contact form?
- Does focus ever get "trapped" somewhere you can't escape?
- Is the tab order logical (top to bottom, left to right)?
Screen Reader Quick Test
Every operating system has a free screen reader built in:
- Windows: Narrator (press Win+Ctrl+Enter) or download free NVDA
- macOS: VoiceOver (press Cmd+F5)
- ChromeOS: ChromeVox (Ctrl+Alt+Z)
You don't need to become a screen reader expert. Just navigate your homepage and listen: does it make sense? Are images described? Are links and buttons labeled? Can you understand the page structure? Five minutes of screen reader testing reveals issues no automated tool can catch.
Common Issues & Fixes
Here are the issues that come up most often when testing a first website project:
Performance Issues
- Images too large โ a 4MB photo from your camera should be resized to the maximum display size (usually 600โ1200px wide) and compressed. Use Squoosh (free, browser-based) to compress without visible quality loss. Aim for under 200KB per image.
- No image dimensions โ always set
widthandheightattributes on<img>tags. This reserves space in the layout before the image loads, preventing Cumulative Layout Shift (CLS). - Render-blocking CSS โ for a small site with one stylesheet, this is fine. On larger sites, critical CSS goes inline and the rest loads asynchronously.
Accessibility Issues
- Missing alt text โ every
<img>needs analtattribute. For informative images, describe what's shown. For decorative images, usealt=""(empty string). - Low contrast text โ use WebAIM Contrast Checker. Your light-mode text should have at least 4.5:1 contrast; check dark mode separately.
- Missing form labels โ every input needs a
<label>. If you can't use a visible label, usearia-label. - Missing language attribute โ the
<html lang="en">attribute tells screen readers which language to use for pronunciation.
SEO Issues
- Missing or duplicate titles โ every page needs a unique
<title>tag. Format: "Page Name - Site Name". - Missing meta description โ write a unique 150โ160 character description for each page.
- Missing heading hierarchy โ one
<h1>per page, followed by<h2>s, then<h3>s. Don't skip levels (no<h1>followed directly by<h4>).
Cross-Browser Issues
- Flexbox gap not supported โ
gapin Flexbox works in all modern browsers now, but very old browsers don't support it. If you need to support older browsers, use margins instead. - Smooth scrolling in Safari โ
scroll-behavior: smoothworks in Safari 15.4+ but not in older versions. This is a progressive enhancement โ older browsers just jump instead of scrolling. - Custom property fallbacks โ if you need to support very old browsers, provide a fallback before the custom property:
color: #1e40af; color: var(--color-primary);
Pre-Launch Checklist
Use this checklist before publishing any website. It covers the essentials and is designed to be copied and reused for future projects.
โ Content
- All placeholder text replaced with real content
- No "Lorem ipsum" or "TODO" remaining
- Spelling and grammar checked
- All links work (no broken links or
href="#"on live links) - Contact information is correct
- Copyright year is current
โ Technical
- HTML validates (W3C validator, no errors)
- CSS validates (no critical errors)
- All pages have unique
<title>tags - All pages have
<meta name="description"> - All pages have
<meta name="viewport"> - Favicon displays in the browser tab
- Open Graph tags set for social sharing
- All JavaScript works without console errors (check with F12 โ Console)
โ Images
- All images have
altattributes - Images are optimized (compressed, correct dimensions)
- Images have
widthandheightattributes - No broken image links
โ Responsive
- Tested at 375px, 768px, 1024px, 1440px widths
- No horizontal scrollbar at any width
- Mobile menu opens and closes correctly
- Text is readable without zooming on mobile
- Touch targets are at least 44ร44px
โ Accessibility
- Lighthouse Accessibility score 90+
- Keyboard navigation works on all pages
- Focus indicators visible on all interactive elements
- Skip-to-content link works
- Color contrast passes WCAG AA (4.5:1 for text)
- Dark mode doesn't break contrast or readability
prefers-reduced-motiondisables animations
โ Performance
- Lighthouse Performance score 80+
- Page loads in under 3 seconds on a mobile connection
- No layout shifts as the page loads
Hands-on Exercise
๐๏ธ Exercise: Test and Fix Your Website
Objective: Run every type of test on your site and fix the issues you find.
Step 1: Validate HTML (all 4 pages)
- Open validator.w3.org
- Validate each page by direct input
- Fix all errors. Write down how many errors you found and fixed.
Step 2: Validate CSS
- Open jigsaw.w3.org/css-validator
- Validate your
style.css - Fix errors. Note any warnings about custom properties โ those are expected.
Step 3: Run Lighthouse
- Open each page in Chrome with Live Server
- Run a Lighthouse audit (mobile mode, all categories)
- Record your scores. Fix any issues that bring Accessibility below 90.
Step 4: Keyboard Test
- Start at the top of your homepage
- Press Tab repeatedly through the entire page
- Verify: skip link appears, focus is visible, all links/buttons reachable, form works
- Repeat on the contact page (form testing is critical)
Step 5: Cross-Browser Test
- Open your site in Firefox (or another browser you have)
- Check layout, typography, hover effects, dark mode
- Note any differences from Chrome
Step 6: Responsive Drag Test
- Slowly resize from 1440px to 320px
- Fix any layout breaks you discover
๐ก Hint โ Quick Fixes for Common Lighthouse Issues
<!-- Fix: "Document does not have a meta description" -->
<meta name="description"
content="Simple recipes made with love โ easy weeknight dinners and crowd-pleasing dishes.">
<!-- Fix: "Image elements do not have explicit width and height" -->
<img src="images/hero.jpg" alt="..." width="600" height="400">
<!-- Fix: "Links do not have discernible names" -->
<a href="/" aria-label="Go to homepage">
<img src="logo.png" alt="">
</a>
๐ฏ Quick Quiz
Question 1: What does the W3C HTML validator check?
Question 2: What Lighthouse Accessibility score should you aim for?
Question 3: Why should you add width and height attributes to images?
Question 4: What percentage of accessibility issues do automated tools typically catch?
Question 5: What causes a horizontal scrollbar to appear on mobile?
Summary
๐ Key Takeaways
- Validate HTML at validator.w3.org โ fix all errors, note warnings
- Validate CSS at jigsaw.w3.org/css-validator โ custom property warnings are expected
- Lighthouse audits four categories โ aim for Performance 80+, Accessibility 90+, Best Practices 90+, SEO 90+
- Add
width/heightto images, meta descriptions to pages, andalttext to all images - Cross-browser test in at least Chrome and one other browser (Firefox or Safari)
- Responsive drag test โ slowly resize and watch for breaks, don't just check specific widths
- Automated accessibility tools catch 30โ50% of issues โ manual keyboard and screen reader testing catches the rest
- Use the pre-launch checklist for every project โ content, technical, images, responsive, accessibility, performance
- Compress images with Squoosh โ aim for under 200KB per image
- Every bug you catch in testing is a bug your visitors never encounter
๐ Your Project After This Lesson
my-website/
โโโ css/
โ โโโ style.css โ validated, errors fixed
โโโ images/
โ โโโ (all optimized, all have alt text)
โโโ js/
โ โโโ script.js โ no console errors
โโโ index.html โ โ
validated, meta description, unique title
โโโ about.html โ โ
validated, meta description, unique title
โโโ recipe.html โ โ
validated, meta description, unique title
โโโ contact.html โ โ
validated, meta description, unique title
Testing Results:
โ
HTML validates (0 errors on all pages)
โ
CSS validates (0 errors, some expected warnings)
โ
Lighthouse: Performance 80+ / Accessibility 90+ / Best Practices 90+ / SEO 90+
โ
Keyboard navigation works on all pages
โ
Tested in Chrome + one other browser
โ
Responsive from 375px to 1920px
โ
Pre-launch checklist complete
๐ What's Next?
Your site is tested, validated, and ready for the world. In the final lesson โ Lesson 21: Publishing to Netlify โ you'll deploy your site to the internet for free. You'll learn about hosting, domain names, continuous deployment, and how to share your creation with anyone, anywhere. This is the finish line.