Sunday, 06 September 2026
Advertisement Advertise Your advert could be here Reach thousands of learners and ICT professionals across Rwanda. Contact us
Advertisement Opportunity Jobs, scholarships & hackathons Fresh openings from Rwandan job boards are pulled in every hour. See openings

Elements, attributes and nesting

Web foundations: HTML & CSS · lesson 2 of 11

In this lesson: Write correctly nested elements and use attributes properly.

An element is normally an opening tag, some content, and a closing tag:

<p>This is a paragraph.</p>
 ↑        ↑                ↑
opening  content        closing

A few elements have no content and therefore no closing tag. These are called void elements:

<br>      <!-- a line break -->
<hr>      <!-- a horizontal rule -->
<img src="photo.jpg" alt="A photo">
<input type="text" name="email">

Attributes

Attributes go in the opening tag and configure the element. They are always name="value":

<a href="/contact" title="Get in touch">Contact us</a>
<img src="logo.png" alt="Yanjye logo" width="120">

Some attributes work on almost any element:

  • id — a unique name for one element on the page. Only one element may have a given id.
  • class — a label you can reuse on many elements. This is what CSS usually targets.
  • style — inline CSS. Useful for a quick test, but keep real styling in a stylesheet.

Nesting

Elements go inside other elements, and they must close in the reverse order they opened — like closing brackets in maths.

<!-- Correct -->
<p>Yanjye is <strong>free</strong> to join.</p>

<!-- Wrong: the tags cross over -->
<p>Yanjye is <strong>free</p></strong>
Indent as you nest. Two spaces per level. Badly indented HTML is where nesting bugs hide, and every editor will do it for you.

Block and inline

Two broad behaviours are worth knowing from the start:

  • Block elements (<div>, <p>, <h1>, <section>) start on a new line and take the full width available.
  • Inline elements (<span>, <a>, <strong>, <em>) sit inside a line of text and are only as wide as their content.

You can change this with CSS later, but the default explains most surprises beginners hit.

Create a free account to save progress

All lessons in this track

  1. 1
  2. 2
  3. 3
  4. 4
    Links and images ~20 min account needed
  5. 5
    Lists and tables ~20 min account needed
  6. 6
    Forms and input types ~30 min account needed
  7. 7
    Introduction to CSS ~15 min account needed
  8. 8
    Selectors: how to target elements ~25 min account needed
  9. 9
  10. 10
    Flexbox layout ~30 min account needed
  11. 11
    Responsive design and media queries ~30 min account needed
Advertisement Yanjye Learn a new digital skill this week ICT, programming and professional courses with graded weekly assignments. Start free