Skip to content
BENIBIX Learn

HTML Elements and Attributes

Level 2 · HTML

How HTML marks up a page with tags. What an element is, what an attribute adds to it, and how elements sit inside one another.

Course contentsLesson 4 of 14

After this lesson you can

  • Read an opening tag, content and closing tag
  • Add an attribute with a name and a value
  • Nest elements in the right order

11 mincovers 3 glossary entries

Worth reading first: Front End and Back End

How tags, elements and attributes fit together

HTML is the language that says what is on a web page. It marks each part with tags. An opening tag such as <p>, some content, and a closing tag such as </p> make one element. A page is just elements, from one heading to many thousands of them, inside one another.

The tag name says what the element is. The <h1> tag is the main heading, and <h2> to <h6> are smaller ones, so there are six levels. A <p> is a paragraph, an <a> is a link, and an <img> is a picture. The browser has a default look for each.

An attribute adds a fact to an element. It sits inside the opening tag as a name, an equals sign and a value in quotes. In <a href="/menu">, the href attribute says where the link goes. In <img src="cat.jpg" alt="A grey cat">, two attributes say which file to show and what it shows.

Some elements have no content, so they have no closing tag. An <img> is one, and so is <br> for a line break. Most others need their closing tag. If one is left out, the browser guesses where the element ends, and it does not always guess right.

Elements sit inside each other like boxes in boxes. A <ul> list holds <li> items, and an item can hold a link. The rule is that the last one opened is the first one closed. So <p><em>Hi</em></p> is right, and <p><em>Hi</p></em> is wrong.

Every page shares one outline. It starts with <!DOCTYPE html>. Then an <html> element holds two parts: the <head>, with facts about the page such as its title, and the <body>, with everything you see. The title in the head is what shows on the browser tab.

People often use HTML to make things look a certain way, such as picking <h3> because it is the right size. That is the job of CSS. Pick each tag for what the part is, and set the size later. The page then makes sense to search engines and screen readers too.

html
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Lucy's Bakery</title>
  </head>
  <body>
    <h1>Fresh bread every day</h1>
    <p>Open from <strong>7am</strong>.</p>
    <a href="/menu">See the menu</a>
    <img src="loaf.jpg" alt="A round loaf on a board">
  </body>
</html>
A whole page. The head holds the tab title, and the body holds what the visitor sees.
An opening tag, the content and a closing tag make one element. Extra facts go in the first tag.

Worked example

Jack's picture has no alt text

Jack's page shows 12 photos with <img src> and nothing else. A blind visitor's screen reader says only file names, like IMG 4031.

He adds an alt attribute to each one, such as alt="Our team at the 2024 fair". The same 12 photos now make sense read aloud.

The words for this lesson3

Check yourself

Where does an HTML attribute go?

Finished this lesson?

Marking it complete also marks its 3 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.