HTML · Lesson 2 of 9
Elements, tags & attributes
Opening and closing tags, nesting and attributes.
An element is usually an opening tag, some content and a closing tag: <p>Text</p>. Some elements are empty and have no closing tag, like <br> and <img>.
Attributes
Attributes add extra information inside the opening tag, written as name="value". Common ones: id, class, href, src, alt, title.
Nesting
Elements can contain other elements. Close them in the reverse order you opened them: <p><strong>Hi</strong></p>.
Try it yourself
Edit the code and press Run (or Ctrl/⌘ + Enter). Code runs only in your browser, in a sandbox.
Key points
- Most elements need a closing tag.
- Attributes live in the opening tag.
- Close nested tags in reverse order.
Quick check
Where do attributes go?
Attributes are always written inside the opening tag, e.g. <a href="…">.
Practice task
Write a paragraph that uses <strong>, <em> and a line break, and give it a title attribute.
Interview corner
What is a void (empty) element?
An element that cannot have content or a closing tag, such as <br>, <img>, <input> and <meta>.
Difference between id and class?
An id must be unique on the page and identifies one element; a class can be shared by many elements and is used for styling groups.
Further reading
Official documentation, linked for deeper study. These are outside sites; this lesson's text is our own.
Original lesson written by the InfoparkDaily team · © 2026 InfoparkDaily · Free to learn — no paid course or subscription.