HTML tag attributes

describing the objects of a web page

// updated 2025-09-10 18:25

Earlier we describe how an HTML tag follows the basic structure of definition, attributes and content. On this page we will look at the attributes portion of a tag in greater depth with:

  • universal HTML attributes
  • tag-specific HTML attributes
  • data-* attributes

Universal HTML attributes

Most, if not all, tags can have the following HTML attributes:

  • id whose value can appear only once per page
    • of course, to identify the element uniquely
  • class whose value can appear many times per page
    • to identify the element's membership in a group of related elements
    • this attribute will come handy later when we work with CSS styles (i.e. to format many different elements with a single line of code)

For example:

1<section id="section-7g">
2
3  <div class="container-sized">
4    
5      <h1>Row 1</h1>
6      
7  </div>
8  
9  <div class="full-width">
10  
11      <h1>Row 2</h1>
12  
13  </div>
14  
15  <div class="container-sized">
16  
17      <h1>Row 3</h1>
18      
19  </div>
20    
21</section>

Tag-specific HTML attributes

Other tags have very specific attributes:

For links

  • href for "hypertext reference"
    • usually appears in an <a> tag and accepts a URL
    • the URL could be an
      • absolute HTTP/HTTPS link (e.g. https://google.com)
      • relative link (e.g. /code/textbook)
      • e-mail address (e.g. mailto:me@me.com)
      • telephone number (e.g. tel:18001234567)
  • target complements the href attribute and specifies whether clicking the link will open a new window (or a tab)
    • _blank opens the link in a new window (or tab in modern browsers)
    • other values include _self, _parent and _top but deal with the outdated web development concept called frames
1<a href="https://www.google.com">Google.com</a> 
2
3<a href="https://www.canada.ca" target="_blank">Canada.ca</a> 

For images

  • src for "source"
    • usually appears in an <img> tag and accepts a URL
    • the URL is an image file but can sometimes be an animated GIF
  • alt for "alternative text"
    • usually appears in an <img> tag and accepts plain text
    • used to describe an image to a screen reader user
1<img src="https://www.placehold.it/300x300.jpg" alt="300x300 placeholder" />
⬅️ older (in textbook-html)
🛡️ HTML tags
newer (in textbook-html) ➡️
HTML <div> and semantic HTML tags 🛡️
⬅️ older (in code)
🛡️ HTML tags
newer (in code) ➡️
HTML <div> and semantic HTML tags 🛡️
⬅️ older (posts)
🛡️ HTML tags
newer (posts) ➡️
HTML <div> and semantic HTML tags 🛡️