CSS Treehouse Club: CSS My First Web Page Changing Your HTML

Importance of the name of the 'alt' attribute?

Per the instructions in the Challenge Task 3 of 3, which states to "change [the] picture, joy.jpg, to sam.jpg. You will also need to change the alt attribute to say Sam, instead of Joy," what importance does the name of the 'alt attribute' hold?

index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>All About Joy's Page</title>
    <link href='http://fonts.googleapis.com/css?family=Open+Sans' rel="stylesheet" type="text/css">
    <link href="style.css" rel="stylesheet">
  </head>   
  <body> 
    <img src="sam.jpg" alt="Sam">

    <h1>MONICA</h1>

    <h2>CONSULTANT</h2>

    <h3>SF, CA</h3>

    <h4>What I do:</h4>
       <p>I'm a teacher at Treehouse, but you should write in what you do here!</p>

    <h4>What I enjoy doing:</h4>  
      <p>When I'm not writing code, I like to surf and play music. Your turn, write in something that makes you happy, or things you like to do in your free time.</p>

  </body>
</html>
style.css
/***********************************************
Top bar color 
***********************************************/
html {
  border-top: 20px solid #8A85A5;
}

/***********************************************
Body styling 
***********************************************/
body {
  max-width: 600px;
  margin: 0 auto;
  padding: 20px 20px;
  font-size: 1.3em;
  line-height: 1.6em;
  font-family: Helvetica Neue, Helvetica, Arial, serif;
  color: #777;
  font-weight: 300;
}

.centered {
  text-align: right;
}

/***********************************************
Image styling 
***********************************************/
img {
  border-radius: 100%;
  max-width: 340px;
}

/***********************************************
Headline styling 
***********************************************/
h1 {
  font-size: 1.5em;
  line-height: .5em;
  color: #564581;
}

h2 {
  font-size: 1em;
  line-height: 1em;
  font-style: oblique;
  color: #aaa;
}

h3 {
  font-size: .875em;
  line-height: 1em;
  font-weight: normal;
}

h4 {
  margin-top: 60px;
  font-weight: 500;
  color: #564581;
}

2 Answers

If a browser has restrictions that doesn't allow a user to see images then text will appear in its place. This helps those that are impaired too.

Austin Whipple
Austin Whipple
27,491 Points

Definitely this. Here's a link to w3schools' take on the matter: http://www.w3schools.com/tags/att_img_alt.asp

Codin - Codesmite
Codin - Codesmite
8,595 Points

Image alt tag also helps search engine crawlers understand your content as they do not look at images but instead your html markup.

For example if you have a picture of a badger surfing on your website you are going to want the alt tag to be something a long the lines of "Image of a badger on a surfboard".

This will:

  1. Allow search engine crawlers such as googlebot to know what the content of the image relates to for SEO purposes.
  2. Allow screen readers to describe the content for visually impaired users. (It is actually discrimination and breach of the Disbility Discrimination Act 1995 to not provide this for visually impaired users of your website).

It is a fairly important tag to stay complaint with legal web practices and for search engine optimization of your website content.