CSS Quotes

CSS is a powerful tool that allows developers to style and design web pages with ease. One of the many properties available in CSS is the quotes property. In this article, we will explore what the quotes property does and provide some examples to help you understand its usage.

What is the CSS Quotes Property?

The quotes property is used to specify the quotation marks or symbols that should be used when quoting content in a document. By default, most browsers use double quotation marks for quotes. However, with the quotes property, you have the ability to change the quotation marks to suit your design preferences or language requirements.

How to Use the CSS Quotes Property

The quotes property is applied to the ::before and ::after pseudo-elements of the content property. It accepts a list of values, where each value consists of two quotation marks or symbols enclosed in double quotation marks. The first value represents the opening quotation mark, while the second value represents the closing quotation mark.

Here’s an example of how you can use the quotes property:


blockquote::before {
  content: open-quote;
}

blockquote::after {
  content: close-quote;
}

q::before {
  content: open-quote;
}

q::after {
  content: close-quote;
}

q.en::before {
  content: "“";
}

q.en::after {
  content: "”";
}

q.fr::before {
  content: "«";
}

q.fr::after {
  content: "»";
}

In the example above, we first set the default quotation marks for blockquote elements using the ::before and ::after pseudo-elements. The open-quote and close-quote values are used to display the default quotation marks defined by the browser.

Next, we set the default quotation marks for q elements. The ::before and ::after pseudo-elements are used again, but this time we use the open-quote and close-quote values to display the default quotation marks.

Finally, we specify custom quotation marks for q elements with the class en and fr. In this case, we use the actual quotation marks ““” and “”” for English quotes and “«” and “»” for French quotes.

Example Usage

Let’s take a look at how the quotes property can be applied to a real-world scenario:


q::before {
  content: open-quote;
}

q::after {
  content: close-quote;
}

q.en::before {
  content: "“";
}

q.en::after {
  content: "”";
}

q.fr::before {
  content: "«";
}

q.fr::after {
  content: "»";
}

<p>In English, we say <q class="en">Hello</q> when we greet someone.</p>

<p>In French, we say <q class="fr">Bonjour</q> when we greet someone.</p>

In the example above, we have two paragraphs. The first paragraph uses English quotes, while the second paragraph uses French quotes. By applying the appropriate class to the q element, we can easily switch between different quotation marks.

Using the quotes property allows you to maintain consistency in your quotes throughout your website or application, while also giving you the flexibility to use different quotation marks for different languages or design purposes.

Conclusion

The CSS quotes property is a useful tool for customizing the quotation marks used in your web pages. By understanding how to use this property, you can easily style your quotes to match your design preferences or language requirements. Whether you want to use default browser quotation marks or define your own custom symbols, the quotes property provides the flexibility you need.

Scroll to Top