HTML · HTML Debugging & Developer Tools · Lesson 27 of 32

HTML Debugging & Developer Tools

HTML Debugging & Developer Tools

Debugging is the process of identifying, understanding, and fixing problems in a webpage or web application.

HTML debugging is not limited to finding missing tags. A webpage can have problems related to structure, accessibility, CSS, JavaScript, network requests, responsive layouts, performance, or browser behavior.

Professional Debugging Principle:

Do not guess what is wrong. Observe the problem, inspect the evidence, identify the cause, test the fix, and verify the result.

1. Common HTML Problems

HTML errors can range from simple syntax mistakes to structural problems that affect accessibility and browser behavior.

Problem Example Possible Effect
Missing closing tag <p>Hello Unexpected document structure.
Incorrect nesting Improperly nested elements. Browser may repair the DOM unexpectedly.
Duplicate ID Two elements using id="main". Unreliable CSS/JavaScript targeting.
Missing alt text <img src="photo.jpg"> Accessibility problem.
Broken link Incorrect href. Navigation failure.
Incorrect file path images/logo.png does not exist. Resource fails to load.
Invalid form association Label does not match input ID. Reduced accessibility and usability.

2. View Source vs Inspect

Browsers provide different ways to examine a webpage.

Feature Purpose
View Page Source Shows the HTML source received by the browser.
Elements / Inspector Shows the current DOM after browser parsing and runtime changes.
Important:

The HTML shown in the Elements panel may differ from the original source because JavaScript or browser parsing may have modified the DOM.

3. Opening Browser Developer Tools

Modern browsers such as Chrome, Edge, Firefox, and Safari provide built-in Developer Tools.

Common ways to open Developer Tools include:

  • Right-click a webpage and select Inspect.
  • Use the browser's Developer Tools menu.
  • Use the appropriate keyboard shortcut for the operating system.
Tip:

The exact keyboard shortcuts vary between browsers and operating systems, so learning the browser's own shortcut documentation is preferable to memorizing one universal combination.

4. Elements Panel

The Elements panel is one of the most useful tools for HTML debugging.

It allows you to inspect the DOM and examine:

  • HTML elements.
  • Attributes.
  • Classes and IDs.
  • Element hierarchy.
  • Computed styles.
  • Box model dimensions.
  • Accessibility information.

Example HTML

<article class="course-card">

    <h2>HTML Fundamentals</h2>

    <p>
        Learn the foundations of HTML.
    </p>

</article>

In Developer Tools, you can select the <article> element and inspect its complete DOM representation.

5. Inspecting an Element

The element picker allows you to select a visible webpage element and immediately inspect its corresponding DOM node.

This is particularly useful when you know what is wrong visually but do not know which element is responsible.

Example

Suppose a heading appears too small. Inspect the heading and check:

  • Which HTML element is being used?
  • Which CSS classes are applied?
  • Which CSS rules are active?
  • Which rules are overridden?
  • What is the computed font size?

6. Editing HTML in Developer Tools

Developer Tools allows temporary modifications to the DOM.

For example, you can temporarily change:

<h1>HTML Course</h1>

to:

<h1>Advanced HTML Course</h1>
Important:

Changes made directly in Developer Tools normally affect only the current browser session. They do not automatically modify your original HTML file on the server or computer.

7. Inspecting CSS

Developer Tools can show which CSS rules apply to an element and which rules have been overridden.

<button class="primary-button">
    Start Learning
</button>

If the button does not look as expected, inspect it and check:

  • Applied selectors.
  • Overridden rules.
  • Specificity.
  • Inherited properties.
  • Computed values.
  • Media-query rules.

8. Debugging the CSS Box Model

Many layout problems are caused by misunderstanding the CSS box model.

Inspect the element and examine:

  • Content
  • Padding
  • Border
  • Margin
  • Width and height
Debugging Tip:

If an element appears too large or is unexpectedly pushed away from another element, inspect its margin, padding, border and computed dimensions first.

9. Console Panel

The Console is primarily used for JavaScript messages and runtime errors, but it is essential when debugging a webpage because HTML, CSS and JavaScript work together.

Common console messages include:

  • JavaScript errors.
  • Warnings.
  • Failed resource messages.
  • Security-related messages.
  • Developer-generated debugging messages.

Example

console.log("Page loaded");

The message can be viewed in the browser's Console panel.

10. Understanding Console Errors

Consider this JavaScript:

document.querySelector("#submit-button").addEventListener(
    "click",
    function () {
        console.log("Submitted");
    }
);

If the expected element does not exist, the console may reveal the problem.

Debugging Approach:
  1. Read the error message.
  2. Identify the file and line number.
  3. Inspect the referenced element or variable.
  4. Correct the underlying cause.
  5. Reload and verify.

11. Network Panel

The Network panel helps identify resources requested by the webpage.

It can reveal problems involving:

  • HTML documents.
  • CSS files.
  • JavaScript files.
  • Images.
  • Fonts.
  • API requests.
  • HTTP status codes.

12. Understanding HTTP Status Codes

Status Meaning Example Debugging Situation
200 OK Resource successfully returned.
301 Moved Permanently Resource redirects to another URL.
302 Found / Temporary Redirect Temporary redirection.
400 Bad Request Server rejects an invalid request.
401 Unauthorized Authentication is required or invalid.
403 Forbidden Server refuses access.
404 Not Found Requested resource cannot be found.
500 Internal Server Error Server encountered an unexpected condition.

13. Debugging Broken Images

Consider:

<img
    src="images/logo.png"
    alt="Website logo">

If the image does not appear:

  1. Inspect the src attribute.
  2. Verify the filename.
  3. Check uppercase/lowercase differences.
  4. Check the relative path.
  5. Open the Network panel.
  6. Look for the image request.
  7. Check its HTTP status.
Common Cause:

A path that works on one operating system may fail on a case-sensitive server because filenames do not match exactly.

14. Debugging Relative Paths

Relative paths are interpreted from the location of the current document.

Example Structure

project/
│
├── index.html
│
├── pages/
│   └── courses.html
│
└── images/
    └── logo.png

From index.html:

<img src="images/logo.png" alt="Logo">

From pages/courses.html:

<img src="../images/logo.png" alt="Logo">
Debugging Rule:

Always calculate a relative path from the location of the current HTML document.

15. Responsive Design Mode

Developer Tools can emulate different screen sizes and device dimensions.

This is useful for testing:

  • Mobile layouts.
  • Tablet layouts.
  • Desktop layouts.
  • Responsive images.
  • Navigation menus.
  • Overflow problems.
  • Media queries.
Remember:

Device emulation is useful for development, but testing on real devices and browsers remains important.

16. Debugging the Viewport

A responsive webpage commonly includes an appropriate viewport declaration.

<meta
    name="viewport"
    content="width=device-width, initial-scale=1">

If mobile layouts behave unexpectedly, inspect the document head and confirm that the viewport configuration is present and appropriate.

17. Accessibility Debugging

Developer Tools can help identify accessibility problems.

Check:

  • Heading hierarchy.
  • Accessible names.
  • Form labels.
  • Alternative text.
  • Keyboard focus.
  • ARIA attributes where necessary.
  • Color contrast.
  • Semantic HTML.

Example

<label for="email">
    Email Address
</label>

<input
    id="email"
    name="email"
    type="email">

Inspecting the accessibility information can help verify that the input has a meaningful accessible name.

18. Debugging DOM Structure

Browsers parse HTML into a Document Object Model (DOM).

<main>

    <section>

        <h2>Courses</h2>

        <p>Learn HTML.</p>

    </section>

</main>

In Developer Tools, this becomes a tree of nodes.

Debugging Advantage:

Inspecting the DOM lets you see how the browser actually interpreted your HTML rather than relying only on what you intended to write.

19. Invalid or Incorrect HTML

Browsers are designed to recover from many malformed HTML documents. This can sometimes hide the original problem.

For example:

<p>
    First paragraph

<p>
    Second paragraph

Browsers may automatically infer missing structure. Developers should still write valid, intentional HTML.

Do not rely on browser error recovery.

A page that "looks correct" in one browser may still contain structural, accessibility, maintenance, or compatibility problems.

20. HTML Validation

HTML validation tools can identify standards-related problems in markup.

Validation can help detect:

  • Invalid attributes.
  • Incorrect markup.
  • Structural issues.
  • Duplicate or inappropriate attributes.
  • Other conformance problems.
Professional Practice:

Use automated validation as one part of a larger testing process. Passing validation does not guarantee good accessibility, security, usability or performance.

21. Search Within Developer Tools

Large webpages can contain hundreds or thousands of DOM nodes. Developer Tools provides search capabilities to locate:

  • Element names.
  • Classes.
  • IDs.
  • Text.
  • CSS properties.
  • Source files.

Searching is often much faster than manually expanding the entire DOM tree.

22. Sources Panel

The Sources panel in browser Developer Tools helps developers inspect loaded source files and debug JavaScript.

It can be useful when an HTML problem is actually caused by JavaScript that dynamically modifies the DOM.

Key Idea:

A visible HTML problem does not necessarily originate in the HTML source file. Always consider CSS, JavaScript, network resources and server responses.

23. JavaScript Breakpoints

Breakpoints pause JavaScript execution at a selected point so developers can inspect program state.

They are useful when JavaScript dynamically:

  • Creates HTML.
  • Removes elements.
  • Changes attributes.
  • Updates form values.
  • Changes classes.
  • Loads content dynamically.

This makes breakpoints useful for debugging HTML behavior caused by scripts.

24. DOM Breakpoints

Some browser Developer Tools allow breakpoints to be placed on DOM changes.

These can help identify which script is changing an element.

Example Scenario

A button initially has:

<button class="save">
    Save
</button>

but later becomes:

<button class="save disabled">
    Save
</button>

A DOM breakpoint can help identify what caused the class to change.

25. Application / Storage Tools

Developer Tools can also expose browser-managed storage and application information.

Storage Typical Purpose
Cookies Session and other browser-managed state.
localStorage Persistent client-side key-value data.
sessionStorage Data associated with the current browser session.
IndexedDB Structured client-side storage.
Security Reminder:

Do not store sensitive secrets in client-side storage merely because Developer Tools makes that storage easy to access.

26. Performance Debugging

Developer Tools can help investigate webpage performance.

Look for:

  • Large images.
  • Too many network requests.
  • Slow resources.
  • Long-running JavaScript.
  • Layout shifts.
  • Large page resources.
HTML Connection:

Poor HTML structure can contribute indirectly to performance problems when it causes unnecessary resources, excessive DOM complexity, or inefficient rendering patterns.

27. Cache-Related Debugging

Sometimes a developer fixes a file but continues seeing an older version because of caching.

When investigating this type of problem, inspect:

  • Network requests.
  • Response headers.
  • Cached resources.
  • Resource URLs.
  • Browser cache behavior.
Debugging Tip:

Confirm that the browser is actually loading the version of the resource you believe you changed.

28. Debugging Horizontal Overflow

If a webpage scrolls horizontally on a mobile screen, inspect the elements that extend beyond the viewport.

Common causes include:

  • Fixed-width elements.
  • Large images.
  • Long unbroken text.
  • Wide tables.
  • Excessive margins or padding.
  • Positioned elements extending outside the viewport.
Method:

Use responsive device mode and inspect suspicious elements until you identify which element exceeds the intended viewport width.

29. Professional HTML Debugging Workflow

  1. Reproduce the problem.
    Confirm exactly what is failing.
  2. Describe the symptom.
    Example: image missing, link broken, layout overflowing.
  3. Inspect the relevant element.
    Use Developer Tools.
  4. Check the DOM.
    Confirm that the browser created the expected structure.
  5. Check styles.
    Inspect applied and overridden CSS rules.
  6. Check the Console.
    Look for JavaScript and browser errors.
  7. Check Network.
    Confirm that required resources are loading successfully.
  8. Identify the root cause.
    Do not merely hide the symptom.
  9. Fix the source code.
    Make the permanent change in the project files.
  10. Test again.
    Verify the fix in relevant browsers and screen sizes.

30. Debugging Case Study — Missing Image

Problem

A course logo does not appear on a webpage.

HTML

<img
    src="image/logo.png"
    alt="Course logo">

Debugging Process

  1. Inspect the image element.
  2. Check the src attribute.
  3. Open the Network panel.
  4. Locate the image request.
  5. Check the HTTP status.
  6. Verify the actual folder structure.
  7. Correct the path.
  8. Reload the page.

Corrected Example

<img
    src="images/logo.png"
    alt="Course logo">
Lesson:

The visible symptom was "image missing", but the root cause was a resource-path error.

31. Debugging Case Study — Wrong Form Behavior

Problem

Clicking a form button unexpectedly reloads the page.

HTML

<form action="/search" method="get">

    <input
        name="q"
        type="search">

    <button>
        Search
    </button>

</form>

A button inside a form defaults to a submit button unless a different type is specified.

If a Non-Submitting Button Is Intended

<button type="button">
    Open Filters
</button>
Debugging Lesson:

When a control behaves unexpectedly, inspect its element type, attributes and surrounding DOM context.

32. Debugging Case Study — Label Does Not Work

Problem

<label for="email-address">
    Email
</label>

<input
    id="email"
    type="email">

The label's for value does not match the input's id.

Correct Version

<label for="email">
    Email
</label>

<input
    id="email"
    type="email">
Debugging Lesson:

Inspect relationships between attributes such as for and id, not just the visual appearance of an element.

33. HTML Debugging Checklist

Check Question
HTML Is the markup structurally correct?
DOM Did the browser create the expected DOM?
Attributes Are IDs, classes, hrefs and src values correct?
CSS Are styles being overridden?
Console Are there JavaScript or browser errors?
Network Are resources returning successful responses?
Responsive Does the problem occur only at certain widths?
Accessibility Can all users access and understand the content?
Browser Does the issue reproduce across relevant browsers?
Source Was the permanent fix made in the actual project files?

34. Interview Questions

1. What is debugging?

View Answer

Debugging is the systematic process of identifying, analyzing and fixing problems in software or webpages.

2. What are browser Developer Tools?

View Answer

They are built-in browser tools that allow developers to inspect the DOM, CSS, JavaScript, network requests, storage, performance and other aspects of a webpage.

3. What is the difference between View Source and Inspect Element?

View Answer

View Source generally shows the source HTML received from the server, while Inspect/Elements shows the browser's current DOM, which may have been modified after page loading.

4. Which Developer Tools panel is useful for checking a missing image?

View Answer

The Elements panel can inspect the image's src, while the Network panel can show whether the image request succeeded or failed.

5. What is the purpose of the Console?

View Answer

It displays JavaScript errors, warnings, logs and other browser messages that help diagnose runtime problems.

6. What does a 404 error mean?

View Answer

HTTP 404 means that the requested resource could not be found by the server.

7. What is the DOM?

View Answer

The Document Object Model is the browser's structured representation of a webpage that scripts and browser APIs can inspect and manipulate.

8. Why is the Network panel useful?

View Answer

It helps developers inspect resource requests, responses, status codes, headers, timing and failures.

9. Can changes made in Developer Tools permanently modify the webpage?

View Answer

Temporary changes in Developer Tools normally affect the current browser session. The actual project source must be modified to make a permanent change.

10. How would you debug a webpage that works on desktop but breaks on mobile?

View Answer

Reproduce the problem using responsive device tools, inspect the affected elements, check viewport settings, examine media-query rules, identify overflow or sizing issues, and then verify the fix on actual devices where possible.

35. Exam Questions

Q1. What is the purpose of browser Developer Tools?

Answer

Developer Tools help developers inspect and debug webpage structure, styles, scripts, network requests, storage, responsiveness and performance.

Q2. Differentiate between the Elements and Network panels.

Answer

The Elements panel is primarily used to inspect the current DOM and associated styles, while the Network panel is used to inspect resource requests and their responses.

Q3. A webpage displays a broken image. Describe the debugging steps.

Answer

Inspect the image element, verify its src, check the relative path and filename, inspect the Network panel, check the HTTP status, verify that the resource exists and then correct the path.

Q4. What is the difference between a DOM problem and a CSS problem?

Answer

A DOM problem concerns the structure or elements created by the browser, whereas a CSS problem concerns the styling, layout or visual presentation applied to those elements.

Q5. Why should developers inspect the Network panel when debugging a webpage?

Answer

It can reveal failed resources, incorrect URLs, HTTP status codes, redirects, slow requests and other network-related causes of webpage problems.

36. Practical Task — Debug a Broken Webpage

Create a webpage containing intentionally introduced errors. Use Developer Tools to identify and document each problem.

Suggested Errors

  • Broken image path.
  • Broken hyperlink.
  • Incorrect form label association.
  • Duplicate ID.
  • Incorrect relative CSS path.
  • JavaScript error.
  • Mobile overflow.

Student Report

Problem Tool Used Root Cause Fix
Broken image Elements + Network Incorrect path Correct image URL
JavaScript failure Console Incorrect selector Correct selector
Mobile overflow Responsive tools + Elements Oversized element Correct layout rule

37. Quick Revision

Tool / Concept Purpose
Elements Inspect DOM and CSS.
Console View JavaScript errors, warnings and logs.
Network Inspect resource requests and responses.
Sources Inspect source files and debug scripts.
Responsive Mode Test different viewport sizes and devices.
Application / Storage Inspect browser storage and application state.
DOM Browser's structured representation of the document.
404 Requested resource was not found.
500 Server encountered an internal error.
Debugging Find the root cause, fix it and verify the result.
Debugging Mantra:

Reproduce → Inspect → Read Evidence → Find Root Cause → Fix → Test → Verify