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

Post History

50%
+0 −0
Q&A Alt text containing double quotes

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...

posted 1d ago by trichoplax‭  ·  edited 1d ago by trichoplax‭

Answer
#2: Post edited by user avatar trichoplax‭ · 2026-02-03T11:50:49Z (1 day ago)
Add explanation
  • 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?
  • ```text
  • ![both ' and " inside](https://a.dev.codidact.org/assets/logo.png)
  • ```
  • > ![both ' and " inside](https://a.dev.codidact.org/assets/logo.png)
  • ## The same image with a broken link to show the alt text
  • ```text
  • ![both ' and " inside](https://a.dev.codidact.org/assets/logo.pngx)
  • ```
  • > ![both ' and " inside](https://a.dev.codidact.org/assets/logo.pngx)
  • 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?
  • ```text
  • ![both ' and " inside](https://a.dev.codidact.org/assets/logo.png)
  • ```
  • > ![both ' and " inside](https://a.dev.codidact.org/assets/logo.png)
  • ## The same image with a broken link to show the alt text
  • ```text
  • ![both ' and " inside](https://a.dev.codidact.org/assets/logo.pngx)
  • ```
  • > ![both ' and " inside](https://a.dev.codidact.org/assets/logo.pngx)
  • ## 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:
  • ```text
  • <img alt="both ' and &quot; inside" src="https://a.dev.codidact.org/assets/logo.png">
  • ```
#1: Initial revision by user avatar trichoplax‭ · 2026-02-03T11:48:00Z (1 day ago)
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?

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

## The same image with a broken link to show the alt text
```text
![both ' and " inside](https://a.dev.codidact.org/assets/logo.pngx)
```
> ![both ' and " inside](https://a.dev.codidact.org/assets/logo.pngx)