Get started with HTML and the DOM
This is the first in a series of tutorials that teach you the basics of web development. Learn about a set of web developer tools, named Microsoft Edge DevTools, that will increase your productivity.
This tutorial describes HTML and the Document Object Model (DOM). HTML is one of the core technologies of web development. It is the language that controls the structure and content of webpages. The DOM is also related to the structure and content of webpages, which we learn more about later.
You're going to learn web development by building a website. By the time you complete all of the tutorials in the DevTools for Beginners series, your finished site will look like the following figure.
By the end of this tutorial, you'll understand the following concepts:
- How HTML and the DOM create the content displayed on webpages.
- How Microsoft Edge DevTools can help you experiment with HTML and DOM changes.
- The difference between HTML and the DOM.
You'll also have a working website. You can use the site to host your resume or blog.
Before doing this tutorial:
If you are unfamiliar with HTML, read Getting Started with HTML.
Download the Microsoft Edge web browser. This tutorial uses a set of web development tools, called the Microsoft Edge DevTools, that are built into Microsoft Edge.
Set up your code
You'll build a site in the Glitch online code editor.
Open the source code. This tab is called the editor tab throughout this tutorial.
Select alluring-shock. The Project Options menu opens.
Select Remix Project. Glitch creates a copy of the project that you can edit and randomly generates a new name for the project. The content is the same as before.
If you plan to complete the next tutorial in this series, select Sign In to Glitch using your Facebook, GitHub, or Google account; or email yourself a magic link. If you don't sign in to an account, you can't edit the project after closing the editor tab.
Select Show > In a New Window. A new tab opens, showing the live page. This tab is called the live tab throughout this tutorial.
Your site needs more information. To add some content:
In the editor tab, replace
<!-- You're "About Me" will go here. -->with
<body> <p> Your site!</p> <main> <h1>About Me</h1> </main>
View your changes in the live tab. The text
About Meis visible on the page. The text is larger than the surrounding text because the
<h1>element represents a Heading 1. Your web browser automatically styles headings in larger font sizes.
Back in the editor tab, insert
<p>I am learning web development. Recent accomplishments:</p>on the line below
<body> <p> Your site!</p> <main> <h1>About Me</h1> <p>I am learning web development. Recent accomplishments:</p> </main>
View your change in the live tab.
Back in the editor tab, add a list of your accomplishments using the following code.
<p>I am learning web development. Recent accomplishments:</p> <ul> <li>Learned how to set up my code in Glitch.</li> <li>Added content to my HTML.</li> <li>TODO: Learn how to use Microsoft Edge DevTools to experiment with content changes.</li> <li>TODO: Learn the difference between HTML and the DOM.</li> </ul>
View the live tab to make sure that the new content is displayed correctly.
Experiment with content changes in Microsoft Edge DevTools
If you are developing a page with a lot of HTML, it becomes tedious to go back-and-forth between the editor tab and the live tab to see your changes. Microsoft Edge DevTools helps you experiment with content changes without ever leaving the live tab.
Learn the difference between HTML and the DOM
Before editing content from Microsoft Edge DevTools, let's understand the difference between HTML and the DOM. Proceed with the following steps to learn from an example.
Navigate to the live tab. At the bottom of your page, the text
A new element!?!is displayed.
Open the editor tab and try to find the text in
index.html. The text doesn't appear in this view.
Open the live tab, right-click
A new element!?!, and then select Inspect.
DevTools opens alongside your page.
<div>A new element!?!</div>is highlighted. Although this structure in DevTools looks like HTML, it's actually the DOM Tree.
When your page loads, the browser uses the HTML to create the initial content of the page. The DOM represents the current content of the page, which can change over time.
<div>A new element!?!</div> content is added to your page because of the
<div>A new element!?!</div> to your page. That is why this text is displayed in the live tab, but not in the HTML.
Edit the DOM
To quickly experiment with content changes without leaving the live tab:
In DevTools, right-click
Your site!, and then select Edit as HTML.
<p>Your site!</p>with the following code.
<header> <p><b>Welcome to my site!</b></p> <button>Download my resume</button> </header>
Enter(Windows, Linux) or
Enter(macOS) to save your changes, or select outside the box. Your changes automatically show up in the live view of your page. The text
Your site!has been replaced with the new content.
This workflow is only suitable for experimenting with content changes. If you refresh the page or close the tab, your changes are lost. If you want to save your changes, manually copy the code to your HTML file. The next couple of sections show you some more ways to change content from the DOM Tree.
You can also change the order of DOM nodes. For example, on your web page the navigation menu is near the bottom.
Move the navigation menu to the top:
<nav>node in the DOM Tree of DevTools.
<nav>node to the top, so that the node is the first child after the
Delete a node
Remove a node from the DOM Tree:
In the DOM Tree, select
<div>A new element!?!</div>. DevTools highlights the node.
<div>A new element!?!</div>node is removed from the DOM Tree.
Copy your changes
You're almost done. You made a few changes to the page in DevTools, but they're not saved to your source code.
Refresh the live tab. The changes that you made in the DOM Tree disappear. In particular, the text
Your site!returns to the top of the page, and the text
A new element!?!returns to the bottom.
Copy the following code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> </head> <body> <header> <p>Welcome to my site!</p> </header> <nav> <ul> <li><a href="/">Home</a></li> <li><a href="/contact.html">Contact</a></li> </ul> </nav> <main> <h1>About Me</h1> <p>I am learning web development. Recent accomplishments:</p> <ul> <li>Learned how to set up my code in Glitch.</li> <li>Added content to my HTML.</li> <li>Learned how to use Microsoft Edge DevTools to experiment with content changes.</li> <li>Learned the difference between HTML and the DOM.</li> </ul> </main> </body> </html>
Go back to the editor tab and replace the content of your
index.htmlfile with the code that you copied.
Complete the next tutorial in this series, Get started with CSS, to learn how to style your page and experiment with style changes in Microsoft Edge DevTools.
Read Introduction to the DOM to learn more about the DOM.
Check out a course such as Introduction to Web Development, to gain additional hands-on experience with web development.
Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons Attribution 4.0 International License.
The original page was found at
https://developers.google.com/web/tools/chrome-devtools/beginners/html and was authored by Katherine Jackson (Technical Writer Intern, Chrome DevTools).
This work is licensed under a Creative Commons Attribution 4.0 International License.
Submit and view feedback for