Michael Flanakin's Web Log

Comments and complaints on software and technology in general

  Home  |   Contact  |   Syndication    |   Login
  159 Posts | 18 Stories | 95 Comments | 530 Trackbacks

News

This weblog is no longer being maintained. For the latest, check out www.michaelflanakin.com!

Article Categories

Archives

Post Categories

Image Galleries

Miscellaneous

As I'm sure you already know, one of the accessibility standards Section 508 covers is specifying alternate text for all images. Not a big deal, right? Well, what about images that are purely used for formatting, such as spacers? Well, just give it an empty string: <img src="spacer.gif" alt="" />. Ok, still not a big deal. Unfortunately, the Image control in ASP.NET 1.x only outputs alternate text if it contains a value. For instance, <asp:Image id="spacer1" ImageUrl="spacer.gif" AlternateText="" runat="server" /> does not render the alternate text. Instead, this is the output: <img src="spacer.gif" />. The only way to add an empty alternate text string is to do it programmatically: spacer1.Attributes.Add("alt", "").

ASP.NET 2.0 hit the streets with a new lease on life. The goal was to be more standards compliant. Every control has been changed to support XHTML standards in three modes: legacy (HTML 4.0), transitional (XHTML 1.0 Transitional), and strict (XHTML 1.0 Strict). Apparently, using legacy conformance will not render your tags in an XHTML-compliant manner, which I think is kind of stupid, but oh well. Anyway, back to the matter at hand... The new Image control adds a GenerateEmptyAlternateText property. As the name implies, this will give you the empty alternate text, but only if you set it to true. What's up with that!? Ok, I realize that this is kind of a small issue; but if you're so stuck on standards compliance - which I'm happy about, by the way - why not just automatically output empty alternate text if no alternate text is specified? I don't really have a problem with the GenerateEmptyAlternateText property, just give it a default of true. Heck, even if you only do it for transitional and strict modes, it'd still be nice - not that this has anything to do with XHTML conformance.

posted on Friday, January 06, 2006 7:45 AM

Feedback

# Image Control and Alt Tags 1/8/2006 9:39 AM Professional ASP.NET
ASP.NET 2.0 is making a big push to be more standards compliant. Just look in Visual Studio 2005 and you will see how to set the default compliancy to 3.02, 4.0, XHTML 4.01, etc. You can also set how your compliance will generate errors while you are working.

# re: Generating Empty Alternate Text for asp:Image Controls 3/4/2006 7:45 PM Robert Johnson
Why not just use css to position your images, instead of spacers? All of these ASP tags and such seems to be overkill. CSS is great for removing the formatting from the content.

# re: Generating Empty Alternate Text for asp:Image Controls 3/5/2006 10:07 AM Michael Flanakin
CSS is great, but getting it to render correctly in every browser can be a pain. I agree that CSS is probably the right option for spacer images, but sometimes it's not worth the time. Also, empty alt attribtutes aren't only for spacers.

# re: Generating Empty Alternate Text for asp:Image Controls 4/29/2007 7:48 PM Scott Mayo
Also, sometimes you may have an image that is purely visual and has no semantic meaning and thusly deserves no alt text. So many people seem to get on accessibility high horses (acessibility is after all, why we use alt tags, not just to satisfy the validator) that they seem to forget that sites are still allowed to look good!

# re: Generating Empty Alternate Text for asp:Image Controls 5/5/2007 11:21 AM Michael Flanakin
I'm somewhat of a purist, but I agree. Not everything needs alt text. If there can be some meaning derived from it, then it should have alt text, tho. I try to put purely visual elements in CSS, where they don't come into play as far as screen readers are concerned.

# re: Generating Empty Alternate Text for asp:Image Controls 2/15/2008 10:36 AM SelArom
thank you for this information! it's not just for spacers, there are also separator images for navigation, etc, so this information is good to know!

Post Feedback

Title:
Name:
Email: (never displayed)
Url:
Comments: 
Please add 3 and 4 and type the answer here: