# HTML Elements and Attributes

> 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:** [HTML, CSS and JavaScript](https://learn.benibix.com/learn/development-web)  
**Time:** 11 min

**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

## 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.

![The line <a href="/about" class="nav">About us</a> with its parts marked: the opening tag with two attributes, the content About us, and the closing tag. Under it, href="/about" is marked as a name and a value saying where the link goes.](https://learn.benibix.com/diagrams/dev-html-anatomy.svg)

### 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.

**Words in this lesson:** [HyperText Markup Language (HTML)](https://learn.benibix.com/term/development/html), [HTML Element](https://learn.benibix.com/term/development/html-element), [HTML Attribute](https://learn.benibix.com/term/development/html-attribute)

**Question:** Where does an HTML attribute go?

**Answer:** Inside the opening tag, as a name and a value. An attribute sits inside the opening tag, like href="/menu". It adds a fact about the element, such as where a link goes.

---

Source: https://learn.benibix.com/learn/development-web/html-elements-and-attributes
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
