# HTML Attribute

> Extra facts put in a tag, as a name and a value.

**Field:** Software Development  
**Category:** Web Development  
**Also known as:** Attribute (HTML), HTML Attributes

## Think of it like

Think of it like a sticker on a box. It adds one more fact, like where to send it.

## Definition

An HTML attribute adds extra facts to an element. It sits inside the opening tag as a name and a value, like href="/about". Some attributes are needed for the element to work. A link needs href to know where to go, and an image needs src. Others are labels, like class and id, that CSS and JavaScript use to find the element.

## Example

Jack's photo did not show up. He had typed scr instead of src, so the image had no address.

## Example code

```html
<img src="cat.jpg" alt="A ginger cat asleep">
```

Two attributes: src says which picture, alt says what it shows.

## Why it matters

Links, images and forms do nothing without the right attributes. Labels like class let CSS style the right parts.

## Common mistake

Leaving out alt on an image. People using screen readers then get no idea what the picture shows.

## Three principles

- **Name and value.** Written as name="value" in the tag.
- **Some are needed.** A link needs href, an image needs src.
- **Some are labels.** class and id help code find it.

## Related terms

- [HTML Element](https://learn.benibix.com/term/development/html-element)
- [HyperText Markup Language (HTML)](https://learn.benibix.com/term/development/html)
- [CSS Selector](https://learn.benibix.com/term/development/css-selector)
- [Alt Text](https://learn.benibix.com/term/design/alt-text)
- [ARIA Attributes](https://learn.benibix.com/term/design/aria)

## Taught in

- [HTML Elements and Attributes](https://learn.benibix.com/learn/development-web/html-elements-and-attributes): HTML, CSS and JS, 4/14

![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 an attribute, name equals value, saying where the link goes. class="nav" is marked as a label that CSS can find. An arrow runs up to it from the CSS rule .nav { color: teal; }.](https://learn.benibix.com/diagrams/dev-html-anatomy.svg)

---

Source: https://learn.benibix.com/term/development/html-attribute
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-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
