View Source shows the HTML response or source document as it arrived, while Inspect shows the browser's current document structure, called the DOM. JavaScript and HTML parsing can change that structure.
What You Need to Know
In the example, JavaScript changes the paragraph after the document has loaded. Inspect shows the new words, while the original HTML source still has the earlier words.
The goal is not to collect as many tags as possible. Pick the element that best describes what the content really is.
Example: See It in Action
Add this example to the appropriate part of a practice HTML page. Read each line before you open the page in your browser.
This is a short HTML fragment. To try it as a webpage, put it inside the body element of a complete HTML document.
<div id="message">
<p>Inspect can show a live, changed page.</p>
</div>
<script>
document.querySelector('#message p').textContent = 'Updated in the DOM';
</script>
Let’s Understand the Example
- Div groups content but has no special meaning of its own; prefer a meaningful element when one fits.
- A p groups a paragraph of related text. Start another paragraph for a new thought.
- A script adds JavaScript or declares another kind of script data. HTML alone does not run most interactive behavior.
- Id gives one element a unique name within the page, so a link, label, or script can point to it.
Look for the text “Inspect can show a live, changed page.” in the page. If the visible result surprises you, inspect the rendered elements to see what the browser actually built.
What Should You See?
The page should include “Inspect can show a live, changed page.”. If it looks different from what you expected, open developer tools and compare the source with the elements the browser created.
Try removing one piece of markup in a scratch copy, refresh the page, and compare the behavior. This is often the fastest way to understand what that piece contributes.
Try It Yourself
- Open View Source and Inspect on the same page and find the difference in the paragraph.
- Save your changes, open or refresh the page, and compare the result with the original example.
- Tell a friend what your change did. If you are not sure, undo it, refresh the page, and compare.
Common Beginner Mistakes
- Using View Source to check a change that JavaScript made after loading.
- Avoid picking tags just for their default bold, italic or spaced appearance. Use CSS for presentation.
Key Takeaways
- View Source shows the HTML response or source document as it arrived, while Inspect shows the browser's current document structure, called the DOM.
- Div groups content but has no special meaning of its own; prefer a meaningful element when one fits.
- In the example, JavaScript changes the paragraph after the document has loaded. Inspect shows the new words, while the original HTML source still has the earlier words.