HTML Attributes

Extra information inside the start tag.

✍️ 3 exercises + code challenge in this lesson

Attributes give extra information about an element. They are always written in the start tag as name="value".

Common attributes

  • href on <a>: the link destination.
  • src on <img>: the image file.
  • alt on <img>: alternative text for the image.
  • width / height: the size of images and other media.
  • style: inline CSS styling.
  • title: a tooltip shown on hover.
  • lang on <html>: the language of the page.
Always put attribute values in double quotes. Lowercase attribute names are the convention.

Key Takeaways: HTML Attributes

Mastering HTML Attributes helps you write clean and reliable HTML code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.

HTML Attributes Code Example

HTML
<html lang="en">
<body>
  <a href="https://codesintech.com" title="Opens CodesInTech">Hover over this link</a>
  <p style="color: #2563EB;">A paragraph with a style attribute.</p>
  <img src="https://picsum.photos/200/100" alt="Landscape" width="200" height="100">
</body>
</html>
Free sign-in required · Google login available

HTML Attributes Practice Exercises

Check what you learned in “HTML Attributes”.

/ 3 solved
Fill in the blank

Add the attribute that gives an image its alternative text.

<img src="cat.jpg" ="A sleeping cat">
✓ Correct! Not quite. Try again.
Multiple choice

Which attribute specifies the URL of a link?

✓ Correct! Not quite. Try again.
Code challenge

Give the link a title attribute with the value "Go home".

Write the code in the live editor. Your answer is checked automatically.

Free sign-in required · Google login available

to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.

Stuck on something?

Ask the community in the CodesInTech forum.

Need a developer?

Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.

Explore Our Services