# Generating 'alt' text for images

**URL:** <https://www.ruby-forum.com/t/generating-alt-text-for-images/140677>\
**Category:** Rails\
**Created:** [June 17, 2008, 12:40pm UTC](https://www.ruby-forum.com/t/generating-alt-text-for-images/140677 "2008-06-17T12:40:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sjmadsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@sjmadsen](https://www.ruby-forum.com/u/sjmadsen)\
**Post date:** [June 17, 2008, 12:40pm UTC](https://www.ruby-forum.com/t/generating-alt-text-for-images/140677/1 "2008-06-17T12:40:00Z")

</div>

I have a link on my page that lets me delete items from my database -

I currently use CSS to insert a background image of a cross (an X).

I want to display ‘alt’ text explaining that the button deletes items  
from the db but I know this can’t be done with CSS.

What is the rails code for doing this?

Currently I have  
\<%= link\_to ‘del’, :action=\>:destroy %\>

The reason I need the alt text is becuase I have set the word ‘del’ to  
be 0px so that it doesn’t appear on scree. I just want to have the  
button.

Is there a way to make the image show ‘alt’ txt when someone rolls  
over it?

---

<div class="post-metadata">

**Author:** ![sjmadsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@sjmadsen](https://www.ruby-forum.com/u/sjmadsen)\
**Post date:** [June 17, 2008, 1:54pm UTC](https://www.ruby-forum.com/t/generating-alt-text-for-images/140677/2 "2008-06-17T13:54:10Z")

</div>

> \<%= link\_to ‘del’, :action=\>:destroy %\>

just use it the normal way instead:

\<%= link\_to(image\_tag("/images/icons/delete.png", :alt =\>  
“delete”, :title =\> “delete”), :action =\> :destroy) %\>

---

<div class="post-metadata">

**Author:** ![sjmadsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@sjmadsen](https://www.ruby-forum.com/u/sjmadsen)\
**Post date:** [June 18, 2008, 1:38am UTC](https://www.ruby-forum.com/t/generating-alt-text-for-images/140677/3 "2008-06-18T01:38:57Z")

</div>

Also as an FYI: The “alt” attribute is used to provide alternate text  
for non-graphical clients and for screen readers. The correct  
attribute for tool tips is “title.” Yes I realize that IE will display  
alt text as a tool tip, but IE is stupid and broken. Don’t beleive me?  
Then read the w3c specs on the two attributes and see for yourself. 🙂

---

<div class="post-metadata">

**Author:** ![sjmadsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@sjmadsen](https://www.ruby-forum.com/u/sjmadsen)\
**Post date:** [June 19, 2008, 11:41am UTC](https://www.ruby-forum.com/t/generating-alt-text-for-images/140677/4 "2008-06-19T11:41:02Z")

</div>

Thank you very much both of you!

I will start using Title from now.

Regds  
steve
