Imagine telling someone "Make me a sandwich" vs "Make me a turkey sandwich with mayo, no tomatoes, and cut diagonally."
Tags are "make me a sandwich." Attributes are the specific instructions. Browsers are hungry. Be specific.
Without Attributes = Generic
<img> says "show an image." Cool. Which image? Where is it? How big? The browser shrugs and shows nothing.
With Attributes = Specific
<img src="cat.jpg" alt="A fluffy cat" width="300"> says "show cat.jpg, describe it as fluffy, make it 300px wide." Browser: "Got it, boss."
Attributes = Extra Info
They go inside the opening tag. Always. They're like secret notes you pass to the browser while the tag is introducing itself.
The Configuration
src="..." tells images where to look. href="..." tells links where to go. id="..." gives elements a name tag.
The Accessibility
alt="..." describes images for screen readers. title="..." shows tooltips. These make your site human-friendly.
The Styling
class="..." and style="..." control appearance. Yes, CSS is better for this, but sometimes you need quick fixes.
Attribute Anatomy 101
name="value" - That's the formula. Always.
Name: What you're setting (href, src, alt).
Value: What you're setting it to (URL, description, size).
Quotes: Use them. Even when you think you don't need to.
<!-- Link with multiple attributes -->
<a href="https://google.com"
target="_blank"
title="Search for answers (or cats)"
class="big-button">
Google It (Opens in new tab)
</a>
<!-- Image with essential attributes -->
<img src="party-cat.gif"
alt="Cat wearing party hat and dancing"
width="400"
height="300"
class="rounded-image">
<!-- Input with type attribute (changes everything!) -->
<input type="password"
placeholder="Enter secret password"
required
maxlength="20">
Boolean Attributes: The Lazy Ones
Some attributes don't need values. They're either there or not. Like disabled, required, or readonly. They just exist and say "Yep, I'm doing my thing."
<input type="checkbox" checked>
<button disabled>Can't Click Me</button>
<video controls autoplay></video>