HTML chapters

Chapter 3 of 17

Elements, attributes and nesting

Try this in our HTML Compiler →

The idea

An element normally has an opening tag, content and a closing tag. Attributes provide extra information on the opening tag. Void elements such as img and input do not have closing tags. Nest elements in reverse closing order so a child closes before its parent.

Worked example

<p>Read <strong>one chapter</strong> today.</p>
<input type="text" name="topic" aria-label="Study topic">

What to check

strong expresses importance within the paragraph. The input type and name are attributes. A slash on a void element does not turn HTML into XML.

Practice task

Add an emphasised phrase with em inside the paragraph; keep the closing tags properly nested.

Check your understanding

Explain the result in your own words before changing the example. Change one thing at a time, compare the result with your prediction, and keep the version that demonstrates the concept clearly.

Try it yourself

Output
Ctrl/Cmd+Enter runs · Ctrl/Cmd+S downloads the project · Local auto-save is always on