On this page10 sections
Lecture 003: Elements & Tags
| Category | 1: Getting Started |
| Lecture | 003 of 048 |
| Estimated video length | 10 min |
| Target | HTML5 · any modern browser |
| Level | Beginner |
An element is one piece of a page: a heading, a paragraph, an image. You write an element with tags. Once you can tell tags, content and elements apart, every other HTML topic is just learning new tag names.
Learning Objectives
- Name the three parts of an element: opening tag, content, closing tag
- Nest elements correctly inside each other
- Recognise empty (self-closing) elements such as
<br>and<img>
1. The Parts of an Element
<p>Hello there</p>
│ │ │
│ │ └── closing tag (has a slash)
│ └──────────── content
└────────────── opening tagThe opening tag, the content and the closing tag together make one element.
Example
<h2>Today's menu</h2>
<p>Chicken karahi with fresh naan.</p>2. Nesting: Elements Inside Elements
An element can hold other elements. The inner one must close before the outer one.
Example
<p>Delivery is <strong>free</strong> today.</p><strong> opens and closes inside the <p>. Think of boxes: a small box must fit
completely inside a bigger box.
Right: <p> ... <strong> ... </strong> ... </p>
Wrong: <p> ... <strong> ... </p> ... </strong>3. Empty Elements
Some elements have no content, so they have no closing tag.
| Element | What it does |
|---|---|
<br> | Line break inside text |
<hr> | A horizontal dividing line |
<img> | An image (Lecture 011) |
Example
<p>House 12, Street 4<br>Lahore<br>Pakistan</p>
<hr>
<p>Open every day, 9am to 9pm.</p>4. Tags Are Not Case-Sensitive, But…
<P> and <p> both work, but always write lowercase. It's the standard, and every
code example you'll find online uses it.
Code Examples
Example 1: A Recipe Card
<h2>Mint Lemonade</h2>
<p>Ready in <strong>5 minutes</strong>.</p>
<hr>
<p>Blend lemon juice, mint, sugar and ice.<br>Serve cold.</p>Common Beginner Mistakes
1. Forgetting the closing tag. Without </strong>, everything after it turns bold.
2. Overlapping tags. <p><strong>Hi</p></strong> closes in the wrong order. Close the
inner tag first.
3. Using <br> for spacing. Several <br>s in a row to push content down is a hack.
Use separate paragraphs, and later CSS margins.
4. Writing </br>. <br> has no closing tag.
Practice Questions
- What are the three parts of
<h1>Welcome</h1>? - Is
<em>Hi <strong>there</em></strong>nested correctly? Why? - Name two empty elements.
- Write HTML that shows "Line one" and "Line two" on separate lines inside one paragraph.
- Should you write tags in upper or lower case?
Practice Answers
- Opening tag
<h1>, contentWelcome, closing tag</h1>. - No.
<strong>opened inside<em>, so it must close before</em>:<em>Hi <strong>there</strong></em>. - Any two of
<br>,<hr>,<img>. <p>Line one<br>Line two</p>- Lowercase.
Key Takeaways
- Element = opening tag + content + closing tag.
- Close inner elements before outer ones, like boxes inside boxes.
- Empty elements (
<br>,<hr>,<img>) have no closing tag. - Write tags in lowercase.