<htmlstart/>

HTML Attributes

Attributes provide extra information about HTML elements.

What are Attributes?

Attributes are placed inside the opening tag and give elements extra properties:

<tagname attribute="value">Content</tagname>

Common Attributes

<!-- id — unique identifier -->
<p id="intro">Welcome</p>

<!-- class — for CSS styling -->
<p class="highlight">Important text</p>

<!-- style — inline CSS -->
<p style="color: red;">Red text</p>

<!-- href — link destination -->
<a href="https://example.com">Visit</a>

<!-- src + alt — image source and fallback text -->
<img src="photo.jpg" alt="A sunset photo">
Always quote attribute values with double quotes. Always include alt on images for accessibility.
🧩

Test Yourself

4 questions
Q1.Where do HTML attributes go?
Q2.What is the correct format for an attribute?
Q3.Which attribute opens a link in a new browser tab?
Q4.Which attribute provides alternative text for images?