# How to use the 'alt' attribute with images

**URL:** <https://www.ruby-forum.com/t/how-to-use-the-alt-attribute-with-images/80260>\
**Category:** Rails\
**Created:** [December 22, 2006, 10:04pm UTC](https://www.ruby-forum.com/t/how-to-use-the-alt-attribute-with-images/80260 "2006-12-22T22:04:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeanluca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@jeanluca](https://www.ruby-forum.com/u/jeanluca)\
**Post date:** [December 22, 2006, 10:04pm UTC](https://www.ruby-forum.com/t/how-to-use-the-alt-attribute-with-images/80260/1 "2006-12-22T22:04:49Z")

</div>

Hi All

I would like to display images including the alt tag

So far this seems to come very close

\<%= link\_to( image\_tag(“myimg.png”, { :border =\> 0, :alt =\> “bla bla”  
}), :action =\> “config” ) %\>

I see the image and no border (which is what I want :), but no alt!!

Any suggestions why ?

Thnx a lot  
LuCa

ps Maybe important, I’m using firefox!

---

<div class="post-metadata">

**Author:** ![jeanluca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@jeanluca](https://www.ruby-forum.com/u/jeanluca)\
**Post date:** [December 22, 2006, 11:25pm UTC](https://www.ruby-forum.com/t/how-to-use-the-alt-attribute-with-images/80260/2 "2006-12-22T23:25:04Z")

</div>

According to the RDocs, it looks right to me, so I’ll defer that part to  
a more experienced user.

But I do want to ask why you are using curly braces between border and  
alt ?? Is there a benefit there that I’m unaware of?

Matt

---

<div class="post-metadata">

**Author:** ![jeanluca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@jeanluca](https://www.ruby-forum.com/u/jeanluca)\
**Post date:** [December 22, 2006, 11:45pm UTC](https://www.ruby-forum.com/t/how-to-use-the-alt-attribute-with-images/80260/3 "2006-12-22T23:45:01Z")

</div>

The curly braces is something I found on the internet. When I remove  
them I get the same result ( no alt )

LuCa

---

<div class="post-metadata">

**Author:** ![jeanluca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@jeanluca](https://www.ruby-forum.com/u/jeanluca)\
**Post date:** [December 23, 2006, 1:12am UTC](https://www.ruby-forum.com/t/how-to-use-the-alt-attribute-with-images/80260/4 "2006-12-23T01:12:03Z")

</div>

> So far this seems to come very close
> 
> \<%= link\_to( image\_tag(“myimg.png”, { :border =\> 0, :alt =\> “bla bla”  
> }), :action =\> “config” ) %\>
> 
> I see the image and no border (which is what I want :), but no alt!!

Works perfectly for me.

What do you mean by saying you see no alt? Did you look for it in  
generated HTML,  
or do you expect it to show up like little yellow popup(tool-tip) when  
hovering mouse  
cursor over image? In latter case only IE will show alt attribute as  
tool-tip and IE is wrong.  
If you still want this tool-tip you should use title attribute, not alt.

If tool-tip is not that you want, then check your code and generated  
HTML. With the code you’ve  
provided I get:  
[![bla bla](https://www.ruby-forum.com/images/myimg.png)](https://www.ruby-forum.com/test/config) - just how  
it is supposed to work.

## Regards, Rimantas

[http://rimantas.com/](http://rimantas.com/)

---

<div class="post-metadata">

**Author:** ![jeanluca](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@jeanluca](https://www.ruby-forum.com/u/jeanluca)\
**Post date:** [December 23, 2006, 11:45am UTC](https://www.ruby-forum.com/t/how-to-use-the-alt-attribute-with-images/80260/5 "2006-12-23T11:45:09Z")

</div>

yep, :title attribute is what I need!!

Thnx a lot  
LuCa
