HTML5
HTML5

HTML Attributes

Attributes give extra information to an HTML element. They are written inside the opening tag. For example: <a href="about.html">About</a>. The href attribute tells the link where to go. Another example is <img src="cat.jpg" alt="A cat">. Here, src and alt are attributes of the image. Many attributes use a name and a value: name="value". Some attributes are boolean, which means their presence is enough, such as required on a form field. Attributes do not replace the element. They add useful details to it.

Why this matters

  • ·Attributes make elements more useful.
  • ·They let one element carry extra information.
  • ·Many HTML features are controlled by attributes.

Common mistakes

  • ·Misspelled attributes may simply be ignored.
  • ·Wrong attribute values can create broken behavior.
  • ·Putting attributes outside the opening tag is invalid HTML.
Your codeHTML
Live preview

Frequently asked questions

Inside the opening tag.

Practice questions

Question 1

Add href to a link.

Your codeHTML
Live preview

Question 2

Add src and alt to an image.

Your codeHTML
Live preview

Quick check

Just for this topic answer honestly, then check yourself.

1 / 3

Where is href written?