Search code examples
htmlescapinghtml-entitiesquotations

How I can put " within an HTML attribute value


I wish to have the following:

<span title="This is a "good" title.">Catch me in the rice.</span>

It is obvious that this is not rendered well by the browsers. Please provide me with information of what escape sequence or encoding like " I must use?


Solution

  • Either replace the quotation mark with its corresponding HTML entity — e.g. &quot; or &#34;) — like this:

    <span title="This is a &quot;good&quot; title.">Catch me in the rice.</span>
    <span title="This is a &#34;good&#34; title.">Catch me in the rice.</span>
    

    Alternatively you can use single quotes in your HTML in cases where you need double quotes in attribute values:

    <span title='This is a "good" title.'>Catch me in the rice.</span>