Click here to Skip to main content
Licence CPOL
First Posted 18 Jan 2007
Views 32,146
Bookmarked 7 times

How to create an ALT text with multiple lines and line breaks

By | 18 Jan 2007 | Article
Ever wondered if you can use the ALT tag in HTML for more that just a vague description?

Introduction

This is just a quick tutorial on how to create multiple lines in an ALT text field. I had the issue of a client wanting to show a biography page with loads of images, and when a user hovers over an image, the ALT tag must show the name, occupation, and company name.

Of course, the nice way of doing this is with a DHTML popup or something similar, but due to time and budget restrictions, a differrnt method had to be found.....step forward the alt text.

Remember!!!!

The alternative text field is not there for this use actually!! The two main uses are to first show some text if the image couldn't load so the visitor can at least know what the image was about, and secondly for Google search engines, of course!!

Don't over estimate the value of the ALT text field as it is not a really big thing, and try to avoid it than use it for the use I am showing here.

Downside

As always, there is a downside. I haven't had too much time to test everything about this, and couldn't find much information on the internet about this (although a thorough search might prove me wrong), but from my testing, this only works in IE version 5 and higher and some versions of Mozilla. Couldn't get it to work on Netscape and didn't have time to test in Opera, but if I had to take a guess, it doesn't work there!! So be careful.

Code

As always, you can do it in a programming language like C#, I am only going to explain the HTML version. Adjust the code to fit your style:

We want an image to have multiple ALT text. The ALT text should contain the name, company, and date for illustration purposes. Remember that the ALT text field doesn't take any HTML code!! So no use trying to input <br> tags in there. Trust me in that /n will not work either!! The only thing that I can find that works in this case is HTML character codes. I know, I know, I can hear you say duh... well, I wasn't sure about it, so I thought I'll just say it!!

The HTML character code for line feed is &#10 but carriage return &#13 will also work, so we input that in the text we want in the ALT.

And there we go, a quick simple example of how to increase the use of the ALT tag!!

Conclusion

I can't overstate that this is not the ideal way, but it can serve as an extra way to save some time or even cut down on budget prices!! Also, all other HTML character codes should work, but again, I haven't tested this, so go ahead and play around!!

Let me know what you think.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Miela_SA

Web Developer

South Africa South Africa

Member

I have been programming for 5 years, and doing web and software design for 7 years. I worked for a blue chip company in the UK working with the web interface of Software Security.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
General'Page Breaks' PinmemberAshaman7:18 18 Jan '07  
GeneralRe: 'Page Breaks' PinmemberMiela_SA20:35 18 Jan '07  
GeneralDoes not work in FireFox PinmemberShawn Poulson6:03 18 Jan '07  
GeneralRe: Does not work in FireFox PinmemberGabriel Topala6:32 18 Jan '07  
GeneralRe: Does not work in FireFox PinmemberMiela_SA20:34 18 Jan '07  
GeneralRe: Does not work in FireFox PinmemberShawn Poulson6:22 22 Jan '07  
QuestionRe: Does not work in FireFox PinmemberMatt Keeble2:39 1 Mar '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 18 Jan 2007
Article Copyright 2007 by Miela_SA
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid