Lesson 6 of 51 · Module 1, lesson 6 of 6 · 5 min

View source and developer tools

Use your browser's tools to see the HTML of any page, including your own.

What you'll learn

  • How to see the HTML of any web page with View Source
  • How to open the browser's developer tools and inspect an element
  • How to change a page temporarily to test an idea

Why this matters

Every browser has tools built in that show you the HTML behind any page. Professional developers use them all day: to find mistakes in their own pages, and to learn how other websites are built. Once you know where they are, the whole web becomes a place to learn from.

View Source: the file as it was sent

View Source shows the HTML file exactly as the browser received it.

BrowserWindowsmacOS
Chrome, Edge, FirefoxCtrl + UCommand + Option + U
Safari—first turn on the developer features (below), then Command + Option + U

You can also right-click an empty part of the page and choose View Page Source.

Open your own index.html in the browser and press the shortcut. A new tab shows your code, exactly as you typed it.

Developer tools: the page as the browser understands it

The developer tools (often called DevTools) are a panel that opens next to the page. The first tab, Elements (called Inspector in Firefox), shows the page as a tree of elements.

Chrome, Edge and Firefox: right-click anything on the page and choose Inspect. Or press F12, or Ctrl + Shift + I on Windows, Command + Option + I on macOS.

Safari (macOS): first click Safari › Settings…, open Advanced, and tick Show features for web developers (on older versions: Show Develop menu in menu bar). After that, right-click anything on the page and choose Inspect Element.

A web page above and the developer tools below. The Elements tab shows the page as a tree: html, then head (closed) and body (open), and inside body an h1 "Tomato soup" and a p "Ready in 30 minutes." The h1 line is selected, and the matching heading on the page is highlighted. Below: how to open the tools in Chrome, Edge and Firefox, and the setting you need first in Safari.

What you'll see

When you move the mouse over a line in the Elements panel, the matching part of the page is highlighted. It works the other way too: right-click your heading and choose Inspect, and the <h1> line is selected in the panel.

Small triangles (▸ ▾) next to an element open and close it, so that you can see what is inside. <head> usually starts closed.

Source and Elements can be different

View Source shows your file. The Elements panel shows what the browser built from it. Usually they match. But when your HTML has a mistake, the browser quietly repairs it, and the Elements panel shows the repaired version.

For example, if you forget </p>, View Source shows your code without it. The Elements panel shows a </p>, because the browser added one. When a page looks wrong, comparing the two views is a good way to find the mistake.

Change a page — for a moment

In the Elements panel, double-click the text inside your <h1>. Type something new and press Enter. The heading on the page changes at once.

Now refresh the page. Your change is gone. DevTools changes only the copy of the page in the browser's memory. They never change your file. This makes DevTools a safe place to try ideas. When you like a change, make it in VS Code and save.

Try it yourself

  1. Open a website you use often. Right-click its main heading and choose Inspect. Which tag is it: <h1>, <h2>, or something else?
  2. Open your own index.html. Use DevTools to change your heading to your name. Refresh, and watch it change back.
  3. Press Ctrl + U (or Command + Option + U) on your own page and compare the source with your file in VS Code.

Common mistakes

  • Editing in DevTools and expecting it to last. Changes in DevTools disappear on refresh. Fix: make the real change in VS Code, then save and refresh.
  • Feeling lost in a big website's code. Large sites have thousands of lines. Fix: always start by right-clicking the exact thing you are curious about and choosing Inspect. The panel jumps straight to it.
  • Nothing happens in Safari. The developer features are off by default. Fix: turn them on in Safari › Settings › Advanced.

Check yourself

  1. What is the difference between View Source and the Elements panel?
  2. You changed a heading in DevTools, then refreshed. What happens, and why?
  3. What is the fastest way to find the HTML of one particular heading on a large website?

Answers

  1. View Source shows the file as it was sent. Elements shows the page the browser built from it, including any repairs.
  2. The change disappears. DevTools changes only the copy in the browser, not the file.
  3. Right-click the heading and choose Inspect.

Next: this first module is complete. Before you move on, build your own first page in the practice exercise. Then, in the next module, you will learn the elements for writing text: headings, paragraphs, emphasis, quotes and more.

Practice project

my first page

Goal: build a complete "About me" page from memory, using everything in this module.

Your website after this module

Outcome: you have a website folder and its first real page, a page about you that opens in any browser.

Your my-website folder: index.html, your About me page. In module 3 it moves to about.html.

Every exercise in this course adds to one website. By module 7 you have a finished three-page site, which you then style in the CSS course and can show in your portfolio. Choose its topic now. The course example is a recipe site, but you can choose your own: a hobby, your city, your studies or a small business. When a later exercise says recipe or dish, write about your topic instead. The HTML it asks for stays the same.

What to do

  1. In VS Code, open your my-website folder.
  2. Open index.html (from Create, save and open your first page) or create it if it is not there.
  3. Replace everything in the file with a page that has:
    • the full skeleton: <!DOCTYPE html>, <html lang="en">, a <head> and a <body>;
    • <meta charset="UTF-8"> and the viewport line inside the head;
    • a <title> with the words About and your first name, for example About Ana;
    • one <h1> with your name;
    • two paragraphs: one about who you are, and one about why you are learning HTML.
  4. Save, open the page in your browser, and check it (see the checklist below).
  5. Copy all the code from VS Code, paste it into the box below, and submit.

You can start from the code already in the box. Replace the words in CAPITAL letters.

Checklist before you submit

  • The browser tab shows About and your name.
  • The page shows one large heading and two separate paragraphs.
  • You see no tags like <p> on the page itself.
  • Every opening tag that needs a closing tag has one.
  • View Source (Ctrl + U / Command + Option + U) shows exactly the code you wrote.

Your mentor reviews every submission and replies with feedback. The exercise counts as done when it is marked Passed.

Starter code

html
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>About YOUR NAME</title>
</head>
<body>
  <h1>YOUR NAME</h1>
  <p>WHO YOU ARE, IN ONE OR TWO SENTENCES.</p>
  <p>WHY YOU ARE LEARNING HTML.</p>
</body>
</html>

Build it in your own folder, on your computer. ZAM students hand this project in on their dashboard, and their mentor reviews it.

Chat with us on WhatsApp