Quotes in HTML


In HTML, quotes are used to enclose attribute values and text content to ensure they are properly parsed by the browser.

There are two types of quotes used in HTML: double quotes ("") and single quotes ('').


Quote in Attribute Values

Double Quotes

<a href="https://example.com">Visit Example</a>

Single Quotes

<a href='https://example.com'>Visit Example</a>


Text Content

Double Quotes in Text

<p title="He said, 'Hello!'">He said, "Hello!"</p>

Single Quotes in Text

<p title='She said, "Hi!"'>She said, 'Hi!'</p>


Important Points

  • Consistency: It's good practice to be consistent with the type of quotes you use within a single document.
  • Escape Sequences: If you need to use the same type of quote within the quoted text, you should use the corresponding escape sequence (e.g., &quot; for " and &#39; for ').

Example with Escape Sequences

<p title="He said, &quot;Hello!&quot;">He said, "Hello!"</p>

Using quotes correctly ensures that your HTML is valid and properly interpreted by web browsers.