SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 70
-
Apr 27, 2009, 14:24 #1
Can the alt attribute for an img tag be empty?
I believe the img tag requires the alt attribute to validate the markup, but is alt allowed to be an empty string?
My validation tool seems to think it's ok, but I always thought it was required incase the image was missing
-
Apr 27, 2009, 14:31 #2
- Join Date
- Feb 2009
- Location
- England, UK
- Posts
- 8,111
- Mentioned
- 0 Post(s)
- Tagged
- 1 Thread(s)
It can be empty, but you should always try to provide alternative text unless you have a seriously good reason not to do so. Be warned that by excluding a complete alt tag, visually impaired users will be unable to know that you have a picture in that placement.
-
Apr 27, 2009, 18:36 #3
ok then fair enough
cheers
-
Apr 27, 2009, 19:06 #4
- Join Date
- Sep 2005
- Location
- Sydney, NSW, Australia
- Posts
- 16,875
- Mentioned
- 25 Post(s)
- Tagged
- 1 Thread(s)
Usually an emtyp alt attribute indicates that the image is purely decorative and ought to be added by the CSS rather than the HTML. Those in the HTML are usually there to convey some information and that information would need to go in the alt attribute for those who don't see the image.
Stephen J Chapman
javascriptexample.net, Book Reviews, follow me on Twitter
HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
<input name="html5" type="text" required pattern="^$">
-
Apr 27, 2009, 22:47 #5
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The alt attribute provides the text equivalent (alternative) for an image. In other words, it should convey the same information as the image does (in that context).
If an image doesn't convey any relevant information in a particular context, the text equivalent should be empty. Thus, alt="".Birnam wood is come to Dunsinane
-
Apr 28, 2009, 01:58 #6
- Join Date
- Aug 2007
- Location
- Netherlands
- Posts
- 10,287
- Mentioned
- 51 Post(s)
- Tagged
- 2 Thread(s)
Be warned that by excluding a complete alt tag, visually impaired users will be unable to know that you have a picture in that placement
On a current site I've found myself using alt="" quite a lot. The reason being, background images can't be floated, where the text wraps around it, but the images are definitely decoration. Are there any good tricks for moving these things into the CSS?
-
Apr 28, 2009, 03:52 #7
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Apr 28, 2009, 04:09 #8
- Join Date
- Apr 2009
- Posts
- 6
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
In a nutshell, alt tags are not important for validation, however, they are very important for both accessibilty and SEO.
-
Apr 28, 2009, 04:21 #9
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Please, people, it's an alt attribute, not an <alt> tag.
Birnam wood is come to Dunsinane
-
Apr 28, 2009, 04:27 #10
- Join Date
- Apr 2009
- Posts
- 6
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Apr 28, 2009, 04:30 #11
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
My comment wasn't directed to you personally, Simon. Too many people use the same misnomer, even people who allegedly are professionals. It's as if a medical doctor would refer to the heart as a gland.
Birnam wood is come to Dunsinane
-
Apr 28, 2009, 07:59 #12
-
Apr 28, 2009, 10:59 #13
- Join Date
- May 2006
- Location
- Aurora, Illinois
- Posts
- 15,476
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Save the Internet - Use Opera | May my mother rest in peace: 1943-2009
Dan Schulz - Design Team Advisor | Follow me on Twitter
SitePoint References: HTML CSS JavaScript | Become A Guru
WordPress SEO Checklist | What WordPress Plugins Do You Use?
Web Standards Curriculum | Image Free Equal Height Columns
-
May 2, 2009, 06:28 #14
- Join Date
- Jun 2008
- Location
- Cuyahoga Falls, Ohio.
- Posts
- 1,511
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hahaha, I swear it gets better everyday tommy.
Examples of Attributes -
Code HTML4Strict:Alt,align,abbr,cellpadding,cellspacing,height,id,label,href,onblur,onclick,onload,onmousedown,onmousemove,
Good point though. It really is important to learn the differences because if we didn't what would be though point right?Blake Tallos - Software Engineer for Sanctuary
Software Studio, Inc. C# - Fanatic!
http://www.sancsoft.com/
-
May 2, 2009, 06:43 #15
- Join Date
- Apr 2006
- Location
- Pennsylvania
- Posts
- 1,736
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
May 2, 2009, 09:40 #16
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
May 2, 2009, 09:57 #17
- Join Date
- Apr 2006
- Location
- Pennsylvania
- Posts
- 1,736
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
May 3, 2009, 09:23 #18
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I've heard a screen reader (may have been Window-Eyes, not sure) that would spell out the image URL (after saying the word 'image') in the absence of an alt attribute. That was a few years ago, though, so perhaps newer versions ignore it.
Birnam wood is come to Dunsinane
-
May 3, 2009, 10:08 #19
- Join Date
- Apr 2006
- Location
- Pennsylvania
- Posts
- 1,736
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
In JAWS (which is what I use), it has an option to do that, but by default it reads the alt attribute and ignores it otherwise.
The only time it'll read the URL is if the image is within a link. But if someone neglected to put in an alt attribute, it is often the case that the image has a cryptic name as well, so it reveals no more information about the target of the link.
For instance, on this page, the five links after the logo have no alt attributes, so I hear something like this:
Link graphic ss/sapphiresteel_pagegfx_r2_c4 On mouse over
Link graphic ss/sapphiresteel_pagegfx_r2_c5 On mouse over
Link graphic ss/sapphiresteel_pagegfx_r2_c7 On mouse over
Link graphic ss/sapphiresteel_pagegfx_r2_c9 On mouse over
Link graphic ss/sapphiresteel_pagegfx_r2_c11 On mouse over
-
May 5, 2009, 02:52 #20
- Join Date
- Oct 2008
- Posts
- 175
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I think you should not empty
-
May 5, 2009, 03:52 #21
- Join Date
- May 2006
- Posts
- 399
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
is important for seo as well i believe
-
May 5, 2009, 04:43 #22
- Join Date
- Sep 2006
- Location
- Nottingham, UK
- Posts
- 3,133
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Personally, I think the majority of alt attributes should end up being empty. Depends on the type of site you have, but a LOT of images are only used for decoration, even if they are related to the content, it's often just a photo to spice up the look of a page. It's actually fairly rare (again, depending on the site) for a photo to be a part of the content, I find. Even then, a lot of diagrams have a caption, which negates the use of alt text anyway (you wouldn't want a screen reader to read the same thing out twice...)
A lot of people get 'text alternative' mixed up with 'description', and they are not the same thing.
I would argue that the majority of alt attributes should be empty if they are being used properly.
-
May 5, 2009, 04:58 #23
- Join Date
- Mar 2006
- Location
- Yorkshire, UK
- Posts
- 5,893
- Mentioned
- 123 Post(s)
- Tagged
- 1 Thread(s)
Yes, that is all absolutely true. Any <img> element must have an alt attribute, but it can be empty (ie alt="") if that's appropriate.
If the image contains information that people would benefit from seeing, you need to put some meaningful text in - but if the image is purely decorative, or is simply an icon illustrating the adjacent text, it's best to leave it empty.
What you have to ask yourself is - if you were browsing the page without images (whether because you can't see them, you have images turned off, or the image just doesn't load properly), would you want to know (a) that there was an image there, and (b) what was in the image? If not, it's fine to leave the attribute empty.
http://reference.sitepoint.com/html/img/alt
-
May 5, 2009, 04:59 #24
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I agree.
Exactly!
I would recommend those of you who are unsure about how to use the alt attribute to read Must I have an ALT attribute for every image? in the HTML FAQ. Compare the four different scenarios where a particular image is used, and note how very different the text equivalent is in each case.Birnam wood is come to Dunsinane
-
May 5, 2009, 08:57 #25
Bookmarks