16

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.

1
  • alt is an attribute, not a tag, of the image element. Commented Jan 29, 2014 at 2:30

2 Answers 2

29

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>
Sign up to request clarification or add additional context in comments.

Comments

9

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 &quot; and ' should not be used in natural languages."

or

alt='The Ascii characters " and &#39; 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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.