Skip to main content

HTML Attributes

Awesome! Now let’s make your elements more powerful with attributes. Attributes add extra information to elements—like giving your car a color or your phone a ringtone.

What is an Attribute?

Attributes go inside the opening tag and usually come in name="value" pairs.

Example:

<a href="https://example.com">Visit Example</a>
  • href is the attribute name
  • https://example.com is the value

Common Attributes

  • href (for links)
  • src (for images)
  • alt (alternative text for images)
  • id and class (for styling and scripting)
  • style (inline CSS)

Example:

<img src="cat.jpg" alt="A cute cat" width="200" />
<p id="intro" class="highlight">Welcome!</p>
tip

Always use alt for images—it's good for accessibility!

What's Next?

Let’s build interactive pages! Next: HTML Forms to collect user input.