Tagging Your Content Lesson 4 of 7

Attributes add meaning and behavior to elements β€” from links to images to accessibility labels.

HTML 101   DESN 368

What Attributes Do

  • A <a> tag creates a link β€” but to where? An <img> tag shows an image β€” but which image?
  • Elements tell the browser what type of content you have
  • Attributes tell the browser more about that specific instance of it
  • Attributes are name-value pairs written inside the opening tag:
<tagname attribute-name="attribute-value">content</tagname>

The Most Important Attributes

<!-- External link -->
<a href="https://developer.mozilla.org">MDN Web Docs</a>

<!-- Internal link (same site) -->
<a href="/about">About Us</a>

<!-- Anchor link (jumps to a section on the same page) -->
<a href="#contact">Jump to Contact</a>
  • Without href, an <a> has no destination and won’t navigate anywhere

src β€” Where an Image Comes From

<!-- Image from the same folder -->
<img src="headshot.jpg" alt="Portrait of Maya Chen, lead designer">

<!-- Image from a subfolder -->
<img src="images/logo.png" alt="Studio logo">

<!-- Image from an external URL -->
<img src="https://example.com/banner.jpg" alt="Conference banner">

alt β€” What an Image Means

  • Read aloud by screen readers for blind and low-vision users
  • Displayed when the image fails to load
  • Indexed by search engines β€” affects SEO
<!-- Descriptive: explains what the image communicates -->
<img src="chart.png" alt="Bar chart showing sales growth of 42% from Q1 to Q4">

<!-- Decorative: alt="" tells screen readers to skip it entirely -->
<img src="decorative-swirl.png" alt="">

<!-- WRONG: missing alt attribute entirely β€” fails WCAG accessibility -->
<img src="photo.jpg">
  • Empty alt="" is correct for purely decorative images
  • Missing alt is always wrong β€” it’s an accessibility failure

class and id

  • These give elements names so CSS can target them β€” covered in depth in the next lesson
  • class β€” can be shared by multiple elements
  • id β€” unique; only one element per page can have a given ID
<p class="intro-text">Welcome to the site.</p>
<p class="intro-text">This paragraph also uses that class.</p>

<section id="contact-form">
  ...
</section>

Putting It Together

  • Multiple attributes can stack on a single element
  • Each attribute on its own line improves readability β€” the browser doesn’t care about whitespace between attributes
<div id="profile-card" class="card">
  <img
    src="avatar.jpg"
    alt="Photo of Jordan Wells"
    class="avatar"
  >
  <h2 class="profile-name">Jordan Wells</h2>
  <p class="profile-bio">UX designer based in Seattle.</p>
  <a href="https://jordanwells.design" class="profile-link">View Portfolio</a>
</div>

Designer Note

  • Alt text is one of the most skipped parts of web design β€” and one of the most important
  • Screen readers depend on it; search engines index it; failed images display only it
  • Writing good alt text is a design skill β€” it requires understanding what the image communicates, not just what it shows