Viewing HTML in the Browser

Become a web detective and learn how to look "under the hood" of any website to see its underlying code, and understand the power of your browser's built-in tools.

Lesson ProgressStep 1 of 7

Welcome!

<h1>Welcome!</h1>
0 EXP

Welcome, Web Detective! Your mission: uncover the hidden HTML code of any website.

/* Your mission awaits... 🕵️ */

Method 1: View Page Source (The X-Ray)

This is the quickest way to see the raw HTML file. It's like taking an X-ray of a website's skeleton exactly as it was when it left the server, before any JavaScript "muscles" started moving things around.

How to Use It:

  • Right-click anywhere on a webpage and select "View Page Source".
  • Or, use the keyboard shortcut: Ctrl + U (on Windows/Linux) or Cmd + Option + U (on Mac).

This opens a new tab showing you the pure, original HTML. It is **static** and will **not** show any changes made to the page by JavaScript after it loaded.

System Check

If a script adds a new `<div>` to the page after it loads, will you see that `<div>` in 'View Page Source'?

Advanced Holo-Simulations

0 EXP

Log in to unlock these advanced training modules and test your skills.


Achievements

🕵️
Web Detective

Construct a document and learn to inspect it.

🏗️
Render-Flow Whiz

Correctly order the browser rendering steps.

⌨️
Shortcut Expert

Prove your mastery of developer shortcuts.

     

        Mission: Inspect Your Own Code      

     

        Write some simple HTML. Then,         right-click on the rendered output (the text on the         right) and select "Inspect". Your browser's DevTools         will open, highlighting the live DOM for the code you just wrote!      

     
       
                 
       
         

Rendered Output:

         
         

A.D.A. Feedback:

         
           

                > Awaiting input...             

         
       
     
   

Challenge: Order the Browser Process

Drag the steps into the correct logical order from top to bottom, from receiving the file to the final view.

Browser parses the HTML
Server sends the HTML file
JavaScript modifies the DOM
Browser creates the DOM

Challenge: Know the Shortcut

Fill in the blank with the most common key to open Developer Tools.

To open DevTools, press thekey.

Consult A.D.A.

Community Holo-Net

Peer Project Review

Share a screenshot of a cool website you inspected and point out one interesting thing you found in the DOM.

Source Code vs. The DOM: The Blueprint vs. The Living Building

When you first learn to "view code," it seems simple. But you quickly discover two different ways to do it: "View Page Source" and "Inspect Element." The first shows the **source code**, and the second shows the **DOM**. Understanding the monumental difference between these two is perhaps the most critical "a-ha!" moment in web development.

📄 Part 1: The Source Code (The Blueprint)

The **source code** is the raw HTML text file. It is the literal set of instructions, written by a developer, that your browser downloads from a server.

  • How You See It: Right-click → "View Page Source" (Ctrl+U or Cmd+Opt+U).
  • What It Is: A static, read-only text file.
  • Key Trait: It is **pre-JavaScript**. It shows you the code *before* any scripts have had a chance to run, add, or change anything.

Think of it as the original, laminated blueprint for a skyscraper. It's the architect's final plan. It's perfect, it's static, and it doesn't change, even after the building is built.

🌳 Part 2: The DOM (The Finished Building)

The **Document Object Model (DOM)** is a live, in-memory tree of objects that the browser builds *after* it reads the source code. This is the actual, "living" representation of the page.

  • How You See It: Right-click → "Inspect" (F12 or Ctrl+Shift+I).
  • What It Is: A dynamic, interactive tree structure that can be changed.
  • Key Trait: It is post-JavaScript. It shows thecurrent state of the page, including every single change made by JavaScript.

This is the finished skyscraper. You can walk through it. A "JavaScript" construction crew might be inside adding new furniture, painting walls, or even building a new room. What you see with "Inspect" is the building as it exists *right this second*, with all the new furniture in it.

The Process: From Blueprint to Building

This is how it all connects. The process is called parsing.

  1. Download: Your browser requests `index.html`. The server sends the (the blueprint).
  2. Parse HTML: The browser reads the source code and builds the initial DOM (the building's frame).
  3. Parse CSS: The browser finds <link> tags, downloads CSS files, and builds the CSSOM (the interior design plan).
  4. Render Tree: The browser combines the DOM and CSSOM to create the Render Tree, which is a map of everything that's actually visible.
  5. Paint: The browser "paints" the pixels on the screen based on the Render Tree.
  6. Execute JavaScript: The browser finds <script> tags. The JavaScript engine runs the code. This code can then say, "Hey DOM, add a <div> here!" or "Change that <p> tag's text!"

This is why "View Source" and "Inspect" are different. "View Source" shows you Step 1. "Inspect" shows you the *result* of Step 6.

❌ Common Pitfall

A junior developer writes JavaScript to add a "Welcome" message. It doesn't appear. They "View Source," see their <script> tag is there, and get confused because the "Welcome" message isn't in the HTML. Their mistake? They are looking at the blueprint (Source) instead of the building (DOM). They should have used "Inspect" to see *why* the DOM didn't update (maybe their script had an error).

✔️ Pro Debugging Tip

Your CSS for `.my-button` isn't working. Don't just "View Source." Instead, **right-click the button and "Inspect" it**. In the "Elements" panel, select the button. In the "Styles" pane, you will see your `.my-button` rule and exactly why it's being overridden (e.g., another rule has higher specificity). You can even uncheck rules live to see what happens!

Key Takeaway: Use **View Source** to see the original file for SEO checks (like meta tags) or to see what the server *originally* sent. Use **Inspect Element** for *everything else*. Debugging layout, styling, and JavaScript is 99% of the job, and that all happens in the live, dynamic DOM.

Browser & Developer Tools Glossary

Source Code
The raw, static HTML file sent from the server. It is read-only and does not reflect any changes made by JavaScript. (Viewed with "View Page Source").
DOM (Document Object Model)
The browser's internal, in-memory representation of a webpage as a live, dynamic tree of objects. This is what JavaScript interacts with and is what you see in the "Elements" tab.
CSSOM (CSS Object Model)
A tree structure, similar to the DOM, that the browser creates from your CSS rules. It maps styles to their corresponding DOM elements.
Render Tree
The combination of the DOM and CSSOM. It's a tree of only the elements that will actually be rendered (or "painted") on the screen. Elements like `display: none;` are excluded.
Parsing
The process where the browser reads the HTML source code and turns it into the DOM tree, and reads the CSS to create the CSSOM.
Developer Tools (DevTools)
The suite of tools built into browsers (opened with F12 or "Inspect") used for debugging and development.
Elements Tab
The panel in DevTools that shows the live, interactive DOM tree. It also includes a "Styles" pane to inspect and modify CSS in real-time.
Console Tab
An interactive JavaScript command line. It's used to log messages (e.g., `console.log()`), run test scripts, and view error messages.
Network Tab
Shows all network requests made by the page (HTML, CSS, JS, images, API calls). Essential for diagnosing slow-loading pages or failed requests.
Application Tab
Allows you to inspect browser storage, such as Local Storage, Session Storage, and Cookies.
Lighthouse
An automated tool (often a tab in DevTools) that audits your page for performance, accessibility, SEO, and other best practices.

About the Author

Author's Avatar

TodoTutorial Team

Passionate developers and educators making programming accessible to everyone.

This article was written and reviewed by our team of web development experts, who have years of experience teaching HTML and building robust and accessible web applications.

Verification and Updates

Last reviewed: October 2025.

We strive to keep our content accurate and up-to-date. This tutorial is based on the latest HTML5 specifications and is periodically reviewed to reflect industry best practices.

External Resources

Found an error or have a suggestion? Contact us!