The <q> tag is used in HTML to mark a short quotation, generally a passage taken directly from a text. It allows you to frame a quotation without the necessity of a block separation.
It is often used for quotations of one or two sentences extracted from a speech, a text, or a conversation.
It is different from the <cite> tag, which is used to indicate the source of a quotation. If you want to indicate a source in addition to the quotation, it is preferable to combine the two tags: <q> for the quotation and <cite> for the source.
Structure and syntax of the <q> tag
Basic structure and syntax
The <q> tag is an inline tag that has:
- An opening tag:
<q>; - A closing tag:
</q>.
It is used to frame a text that constitutes a short quotation.
Usage example
Here is a practical example:
<p>Albert Einstein said: <q>Imagination is more important than knowledge.</q></p>In this example, Einstein's quotation is framed by the <q> tag, which clearly marks it as a quotation.
Attributes
The <q> tag accepts the classic HTML attributes (style, class, etc.), but it does not have specific attributes related to its functionality.
Difference with other similar tags
<cite>: The<cite>tag is used to indicate the source of a quotation, whereas<q>simply marks the quoted text.<blockquote>: The<blockquote>tag is used for long or block quotations, often accompanied by a source attribute. It is generally more formal than<q>.
Browser compatibility
The <q> tag is supported by all modern browsers.
| Browser | Compatibility |
|---|---|
| Chrome | Yes |
| Firefox | Yes |
| Safari | Yes |
| Edge | Yes |
| Internet Explorer | Yes |