Lesson 25 / Debugging

Debugging Web Projects

Time
47 min
Type
Reading + Interactive
Level
Intermediate
Use
Studio Support

Use a calm debugging playbook to find and fix broken HTML, CSS, JavaScript, images, links, responsive layouts, and published-site problems.

Course Role

Studio Support

Best during work sessions, critique, debugging, project planning, or final polish.

Teacher Notes / In-Class Use

Demo Live

  • Walk through the interactive demo before students start changing their own project files.
  • Connect the demo back to the first goal: Use a repeatable debugging process instead of guessing

Try In Class

  • Break one CSS selector on purpose, inspect the element, and fix it.
  • Have students make one visible change, save, refresh, and explain what changed.

Submit Or Check

  • Ask students to show the work in the browser, not only in the editor.
  • Have students commit their progress with a clear message when the checkpoint is stable.

Watch For

  • Students copying code without checking file paths, spelling, or capitalization.
  • Visual changes that work locally but break when the project is published.

Learning Goals

  • Use a repeatable debugging process instead of guessing
  • Use DevTools, the console, the network panel, and validators to locate problems
  • Fix common HTML, CSS, JavaScript, path, responsive, and GitHub Pages issues
  • Test one change at a time and confirm the fix on the live site

Interactive Demo

How to use this demo.

Use the demo as a small lab. Change one thing, observe the result, then connect it back to your own project.

What To Try

  • Switch between CSS, image, JavaScript, and selector symptoms.
  • Move through Describe, Inspect, Fix, and Test instead of jumping straight to editing.

What Changes

  • The preview starts broken in a different way for each symptom.
  • The code sample changes to show the most likely fix pattern.

What To Notice

  • Each fix starts with a clear symptom and a clue from DevTools or the file path.
  • Testing one change at a time makes the bug easier to isolate.

Apply It

  • Use the same four-step process on a real broken page before changing multiple files.

Interactive Demo

Debugging Checklist Lab

Choose a symptom, inspect the clues, then apply one fix at a time.

Start by describing the exact symptom.

Campus Cafe

Image

This card should have styling, an image, and a working details button.

Describe the symptom before editing.

This demo uses extra JavaScript for teaching. The code sample shows the pattern to practice. View full demo source.

Debugging Mindset

Debugging means finding the difference between what you expected and what the browser is actually doing. The goal is not to guess faster. The goal is to make the problem smaller until the cause becomes visible.

Do not change five things at once. Describe the symptom, inspect the page, test one likely cause, refresh, and keep track of what changed.

A calm debugging process is a professional skill. The browser gives you clues; your job is to read them before rewriting the project.

The Debugging Loop

StepQuestionAction
ObserveWhat exactly is broken?Describe the symptom in one sentence before editing.
InspectWhat does the browser see?Use DevTools to inspect HTML, CSS, console messages, and network requests.
IsolateCan I make the problem smaller?Test one file, selector, component, or line at a time.
ChangeWhat is one likely fix?Make one change and refresh.
ConfirmDid the fix work everywhere?Retest locally, at mobile widths, and on the published site.

CSS Is Not Applying

When CSS is not working, first decide whether the stylesheet failed to load or whether the selector/rule is not matching the element.

CheckWhat To Do
Stylesheet pathOpen DevTools Network and confirm the CSS file returns 200, not 404.
Selector matchInspect the element and check whether the selector appears in the Styles panel.
Cascade conflictLook for crossed-out rules and stronger selectors overriding your rule.
SpellingCompare class names in HTML and CSS exactly, including hyphens.
<!-- HTML -->
<section class="project-card">...</section>

/* CSS bug: selector does not match the class */
.projectcard {
  border: 1px solid currentColor;
}

/* Fix */
.project-card {
  border: 1px solid currentColor;
}

Images or Links Are Broken

Broken images and links are usually path problems. The path starts from the file that contains the src or href, not from the project folder you see in VS Code.

  • Use the Network panel to find missing files with 404 status codes.
  • Check spelling and capitalization exactly. Published sites are often case-sensitive.
  • Do not use local computer paths like C:/Users/name/Desktop/image.jpg in HTML.
  • Open the image or linked page URL directly in the browser to confirm it exists.
<!-- index.html is beside the images folder -->
<img src="images/hero.jpg" alt="Student portfolio homepage">

<!-- about/index.html is inside an about folder -->
<img src="../images/hero.jpg" alt="Student portfolio homepage">

JavaScript Does Nothing

When JavaScript stops working, open the console before editing. Read the first error first. Later errors may be caused by the first one.

Uncaught TypeError: Cannot read properties of null

Meaning:
JavaScript tried to use an element that was not found.

First checks:
1. Does the selector match the HTML?
2. Does the script run after the HTML exists?
3. Is the script on the correct page?

Common JavaScript Selector Bug

If querySelector() cannot find the element, it returns null. Calling methods on null causes the script to fail.

<!-- HTML -->
<button class="menu-button" type="button">Menu</button>

// JavaScript bug: selector is missing the hyphen
const button = document.querySelector('.menubutton');
button.addEventListener('click', openMenu);

// Fix
const button = document.querySelector('.menu-button');
button.addEventListener('click', openMenu);

Script Loading Order

If JavaScript runs before the HTML exists, selectors may return null. A simple fix is to place the script at the end of the body or use the defer attribute when loading an external script.

<!-- Good option: defer external JavaScript -->
<script src="script.js" defer></script>

<!-- Good option: place script before closing body tag -->
<script src="script.js"></script>
</body>

HTML Validation

Invalid HTML can create layout, styling, and accessibility problems that look like CSS or JavaScript bugs. Use a validator when the page behaves strangely and the cause is not obvious.

ProblemWhy It Matters
Missing closing tagThe browser may nest content in a different place than you expect.
Duplicate id valuesLabels, links, and JavaScript may connect to the wrong element.
Invalid nestingInteractive elements or layout sections may behave unpredictably.
Missing required attributesForms, images, and metadata may lose meaning.

Published Site Debugging

Always test the published URL. Local preview and GitHub Pages are different environments, so a site can work locally and fail online.

SymptomLikely CauseFirst Check
Published site shows old contentLatest changes were not pushed or deploy is still runningCheck GitHub Desktop and the repository commit history.
CSS missing onlineWrong path, capitalization mismatch, or file not committedOpen the CSS URL from the live page.
Image missing onlineCase-sensitive file name or wrong folder pathCompare the image file name and src exactly.
GitHub Pages shows 404Wrong branch, folder, or published URLCheck repository Settings > Pages.
Works on homepage but not subpagePath assumes the wrong folder depthRewrite the path from the current HTML file.

Mobile Overflow Debugging

Horizontal scrolling usually means something is wider than the viewport. Use the responsive device toolbar and inspect the widest-looking element.

  • Look for fixed widths like width: 1200px.
  • Check large images, tables, long words, and wide flex rows.
  • Use max-width: 100% on images and media.
  • Allow grids and flex layouts to wrap or change at smaller widths.
img,
video {
  max-width: 100%;
  height: auto;
}

.card-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr));
}

Do Not Debug by Shotgun

AvoidDo Instead
Renaming random filesCheck which path the browser requested.
Changing many CSS rules at onceChange one rule and refresh.
Ignoring the first console errorRead and fix the first error first.
Copying absolute local file pathsUse relative paths inside the project.
Trusting only local previewTest the published URL after pushing.

Debugging Checklist

  • Describe the exact symptom before editing.
  • Inspect the element instead of guessing which CSS rule wins.
  • Use the Console for JavaScript errors.
  • Use the Network panel for missing CSS, JavaScript, images, and pages.
  • Validate HTML if the page structure behaves strangely.
  • Check file paths from the current HTML file.
  • Test one change at a time.
  • Commit, push, and test the live URL before submitting.

Checkpoint

Before moving on, make sure these feel true.

  • I can describe the exact symptom before editing.
  • I can use DevTools to inspect HTML, CSS, console errors, and missing files.
  • I can test one possible fix at a time.

Practice

  • Break one CSS selector on purpose, inspect the element, and fix it.
  • Break one image path on purpose and use the Network panel to find the missing file.
  • Create a querySelector() typo, read the console error, and fix the selector.
  • Run your HTML through the W3C validator and fix one issue.
  • Find one mobile overflow issue or confirm your project has none at small widths.
  • Publish your project and verify that the live URL matches your local version.

Resources