Brad
Brad

Reputation: 12272

For images, what is the benefit of using the name element? name="...."

I want to know what the difference is between alt="" and name=""

Would it be better to put the filename within the alt tag, or the description of the photo?

What makes better sense, both from SEO and validation stand-point?

Upvotes: 0

Views: 155

Answers (6)

Aron Rotteveel
Aron Rotteveel

Reputation: 83223

Using the ALT attribute is more useful in terms of search engine optimalisation. Using the NAME attribute is mainly useful for internal page anchors.

The ALT attribute is intended to provide an alternate text that describes the image for people who use screen-readers, or search engines, for example.

The name attribute is mainly used for internal anchoring, which allows you to navigate within a page using anchors.

Example usage of the name attribute:

<!-- following ancor can be referenced as http://<your_url>#post-123 -->
<a name="post-123">permanent link to some post</a>

Example usage of alt attribute:

<!-- following image shows "FooBar Company Logo" when images can't be shown -->
<img src="logo.jpg" alt="FooBar Company logo" />

Upvotes: 5

Michael Borgwardt
Michael Borgwardt

Reputation: 346546

  • The name attribute exists only to provide a name to refer to in JavaScript.
  • The alt attribute provides an alternate description for search engines, blind people, when the image could not be loaded, etc.
  • The title attribute provides a description which will be shown when the user hovers over the image with his mouse - some (but not all) browsers will use the alt attribute for this purpose when there is no title

Upvotes: 2

ISW
ISW

Reputation: 11350

You definitly want to use the ALT tag - for all the reasons mentioned above, and: this tag is mandatory according to W3C so you need it if you want to create "compliant code" (see e.g. w3schools).

Upvotes: 1

Gumbo
Gumbo

Reputation: 655825

The alt attribute is intendet to supply an descriptive alternative in text form for the image. So if you have an image that shows a sunflower, you could use:

<img src="sunflower.jpg" alt="image of a sunflower on a sunny day">

The name attribute in intended to name the image for scripting so you can access it using images["sunflower"]. But nowadays you should use the id attribute instead.

Upvotes: 1

Brian Fisher
Brian Fisher

Reputation: 24009

Yeah, definitely put a description in the alt tag. It is really important for the visually impaired as this is what the screen readers will read when they come across an image. The only potential catch with this is that the alt tag is treated as tool tip text by some browsers, however, you can override that behavior with setting title="".

Upvotes: 1

Dillie-O
Dillie-O

Reputation: 29755

I'd be a little wary of putting the file name in the ALT tag, since it would be displayed if images are turned off. Typically you set the ALT tag to server as a place holder with something like "Site Logo" or something else to indicate what the image is.

The NAME tag is used for anchoring and the like. If you wanted to create a link that scrolled a long page to your image, you would reference it through this.

Upvotes: 1

Related Questions