Is it possible to hide the alt text using CSS in all the browsers,
I tried with color:transparent, it is working in all browsers except IE.
Is it possible to do it in IE using CSS?. Thanks in advance for any help.
How about using font-size: 0? It works in hiding alt text before image loads or if image src URL is not available.
The kellum method:
.hide-text {
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}
Also don't have the performance drawback of -9999px method where browser draw a box with size of 9999px.
Further explanation: replacing-the-9999px-hack-new-image-replacement
You can use text-indent:-9999px
HTML
<img src="images/test.jpg" alt="alternative">
CSS
img{
text-indent:-9999px
}
line-height then text-indent will work in all browsers...its better to use line-height:1em;text-indent: -9999px will make browser draws unnecessary 9999 empty space. Use the kellum methodYou could also use the onerror callback to set the display property to none:
<img src="images/test.txt" onerror="this.style.display='none';">
Instead of using color:transparent; use display:none;.
But you should not use this technique.
As @Quentin said in the comment:
If the text isn't good enough for humans then it isn't good enough for search engines.
You should not hide the alt text. Google knows this only used for SEO purpose and nothing important and will penalize for such. And you may be blacklisted on Google Search Engine.
So, don't use them just for SEO purpose.
Use text-indent: -9999px; and display: none.
HTML
<h1 class="technique-four">
<a href="#">
<img src="images/header-image.jpg" alt="CSS-Tricks" />
</a>
</h1>
CSS:
h1.technique-four {
width: 350px; height: 75px;
background: url("images/header-image.jpg");
text-indent: -9999px;
display: none;
}
text-indent: -9999px;