Communities

(DEV) Codidact Meta
(DEV) Codidact Meta
(DEV) Writing
(DEV) Writing
Proposals
Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Alt text containing double quotes

+0
−0

An image with alt text text with "quote" inside:

![text with "quote" inside](https://a.dev.codidact.org/assets/logo.png)

text with "quote" inside

An image with alt text unmatched " inside:

![unmatched " inside](https://a.dev.codidact.org/assets/logo.png)

unmatched " inside

The same images with broken links to show the alt text

An image with alt text text with "quote" inside:

![text with "quote" inside](https://a.dev.codidact.org/assets/logo.pngx)

text with "quote" inside

An image with alt text unmatched " inside:

![unmatched " inside](https://a.dev.codidact.org/assets/logo.pngx)

unmatched " inside

History

0 comment threads

1 answer

+0
−0

It turns out the alt text is enclosed in single quotes if the alt text contains double quotes. What happens if the alt text contains both single and double quotes?

![both ' and " inside](https://a.dev.codidact.org/assets/logo.png)

both ' and " inside

The same image with a broken link to show the alt text

![both ' and " inside](https://a.dev.codidact.org/assets/logo.pngx)

both ' and " inside

How this still works

When the alt text contains both single and double quotes, double quotes are used to contain the alt text, and the contained double quote is represented as &quot;, which the browser renders as " as required:

<img alt="both ' and &quot; inside" src="https://a.dev.codidact.org/assets/logo.png">
History

0 comment threads

Sign up to answer this question »