Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Newline in alt text

Tags:

html

xhtml

Can I use some sort of line break in the alt text for an image while still adhering to the XHTML 1.0 Strict standard?

Something like this...

<img src="foo.jpg" alt="Line 1\nLine 2" />

I'm asking because I want to post the following screenshot on my site, but I want to include the text-only version in the alt text for SEO reasons and for the visually impaired.

http://i.stack.imgur.com/563df.png

I prefer the screenshot over the plain text version because it looks more visually appealing.

like image 394
Pieter Avatar asked Apr 24 '11 10:04

Pieter


People also ask

How do you put a line break in text?

To add spacing between lines or paragraphs of text in a cell, use a keyboard shortcut to add a new line. Click the location where you want to break the line. Press ALT+ENTER to insert the line break.

How do you break to the next line in HTML?

To do a line break in HTML, use the <br> tag. Simply place the tag wherever you want to force a line break. Since an HTML line break is an empty element, there's no closing tag.

What is alt text for images?

Alternative (Alt) Text is meant to convey the “why” of the image as it relates to the content of a document or webpage. It is read aloud to users by screen reader software, and it is indexed by search engines. It also displays on the page if the image fails to load, as in this example of a missing image.


2 Answers

Just use a normal line break.

<img src="foo.jpg" alt="Line 1
Line 2" />

Stack Overflow does this in their titles :)

Then add this CSS:

img{white-space:pre}

Demo: http://jsfiddle.net/Madmartigan/S8SXP/

like image 108
Wesley Murch Avatar answered Oct 11 '22 20:10

Wesley Murch


A better way is to just add the HTML character code for line feed or carriage return.

 line feed is &#10
 carriage return &#13
like image 27
James Williams Avatar answered Oct 11 '22 20:10

James Williams