0

Is this the right way to use escape characters in alt attributes for alt text of an img element?

I have the below code:

<h3>Option 1</h3>
<img src="image.jpg" 
     alt='Version of "Whistler\'s Mother" in cubist style'>

<br><br>

<h3>Option 2</h3>
<img src="image.jpg" 
     alt="Version of \"Whistler's Mother\" in cubist style">

Either of the two options above do not work properly as the alt text. The alt text that I wanted to display is:

Version of "Whistler's Mother" in cubist style

myverdict
  • 412
  • 5
  • 17
  • Does this answer your question? [How can I escape a single quote?](https://stackoverflow.com/questions/2428572/how-can-i-escape-a-single-quote) – WOUNDEDStevenJones Jan 26 '22 at 16:33

1 Answers1

1

No, use the HTML entity instead. E.g. &apos; or &quot;:

<h3>Option 1</h3>
<img src="image.jpg" 
     alt='Version of "Whistler&apos;s Mother" in cubist style'>

<br><br>

<h3>Option 2</h3>
<img src="image.jpg" 
     alt="Version of &quot;Whistler's Mother&quot; in cubist style">
j08691
  • 197,815
  • 30
  • 248
  • 265