Skip to content
BENIBIX Learn

HTML Attribute

Development🌐 Web DevelopmentBrowser Code

Also known as Attribute (HTML), HTML Attributes

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

Think of it like

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

Example

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

Why it matters

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

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 code

html
<img src="cat.jpg" alt="A ginger cat asleep">
Two attributes: src says which picture, alt says what it shows.
This link carries two attributes. href says where it goes, class gives it a label.

Common mistake

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

Key takeaways

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

Learn it properly