Keva161
Keva161

Reputation: 2693

Quotation marks in HTML attribute values?

This may seem like a realy basic question but...

How do you use double speech marks in HTML code (alt tags and the such)?

For example..

I'm trying to set a tag in my webpage to Opening Credits for "It's Liverpool" but it's limiting it to Opening Credits for.

Upvotes: 16

Views: 16021

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201876

You can normally avoid the issue by using appropriate language-dependent quotation marks, instead of Ascii quotation marks, which should be confined to use as delimiters in computer code. Example:

alt="Opening Credits for “It’s Liverpool”"

or (in British English)

alt="Opening Credits for ‘It’s Liverpool’"

Should you really need to use Ascii quotation marks inside an attribute value, use Ascii apostrophes as delimiters:

alt='The statement foo = "bar" is an assignment.'

In the extremely rare case where an attribute value really needs to contain both an Ascii quotation mark and an Ascii apostrophe, you need to escape either of them (namely the one you decide to use as attribute value delimiter):

alt="The Ascii characters " and ' should not be used in natural languages."

or

alt='The Ascii characters " and ' should not be used in natural languages.'

Note that these considerations are relevant only inside attribute values. In element content, both " and ' can be used freely:

<strong>The Ascii characters " and ' should not be used in natural languages.</strong>

Upvotes: 9

rjz
rjz

Reputation: 16510

You'll want to use the corresponding HTML entity in place of the quotes:

<span alt="Opening Credits for &quot;It's Liverpool&quot;">A span</span>

Upvotes: 29

Related Questions