How to display language-specific quotes in CSS (#tilPost)

Will Boyd’s excellent article Diving into the ::before and ::after Pseudo-Elements includes a nifty detail about CSS and quotes that was complete news to me. It’s a great read, and you should check it out.
If you’re maintaining a mu…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

Will Boyd's excellent article Diving into the ::before and ::after Pseudo-Elements includes a nifty detail about CSS and quotes that was complete news to me. It's a great read, and you should check it out.

If you're maintaining a multi-lingual site that includes quotes in different languages, you might use the following HTML.

<blockquote lang="en">
  That's cool!
</blockquote>

<blockquote lang="de">
  Das ist super!
</blockquote>

<blockquote lang="fr">
  C'est super!
</blockquote>

You see that the browser's default user agent stylesheets don't include any styling for the blockquote element.

Three sentences unstyled

How to display quotes using the pseudo-elements ::before and ::after

To display big and bold quotes wrapping the blockquote element, you can use CSS and leverage pseudo-elements to display a quote character before and after the blockquote.

blockquote::before {
  content: '"';
}

blockquote::after {
  content: '"';
}

blockquote::before, blockquote::after {
  opacity: 0.25;
  padding: 0 10px;
  font-size: 3em;
}

blockquote {
  display: flex;
  justify-content: space-between;
  align-items: center;
  /* more styles */
}

And that works all fine, but...

Quote in three language wrapped in double quotes

... unfortunately, this approach will always display " as quotation characters. It's not considering language-specific quotation. For example, French uses « and » as quotes.

Let's change the CSS to use the correct quote characters automatically.

TIL – CSS supports language-dependent quotation

Use open-quote and close-quote as values for the content property.

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

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

These two values take localisation and language-specific quotation into consideration. ?

Edit: correct quotes using the q element

Edit: Nate Weaver pointed out that that the q element comes with accurate browser default styles for language-specific quotation characters. Great tip, thanks Nate!

<q lang="en">That's cool!</q>
<q lang="de">Das ist super!</q>
<q lang="fr">C'est super!</q>

The above markup displays the correct quotes using pseudo-elements defined in the browser default styles.

CSS is incredibly powerful! ? If you liked this post, have a look at all things CSS on my blog or subscribe to my newsletter below.


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2021-02-27T23:00:00+00:00) How to display language-specific quotes in CSS (#tilPost). Retrieved from https://www.scien.cx/2021/02/27/how-to-display-language-specific-quotes-in-css-tilpost/

MLA
" » How to display language-specific quotes in CSS (#tilPost)." Stefan Judis | Sciencx - Saturday February 27, 2021, https://www.scien.cx/2021/02/27/how-to-display-language-specific-quotes-in-css-tilpost/
HARVARD
Stefan Judis | Sciencx Saturday February 27, 2021 » How to display language-specific quotes in CSS (#tilPost)., viewed ,<https://www.scien.cx/2021/02/27/how-to-display-language-specific-quotes-in-css-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » How to display language-specific quotes in CSS (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/27/how-to-display-language-specific-quotes-in-css-tilpost/
CHICAGO
" » How to display language-specific quotes in CSS (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2021/02/27/how-to-display-language-specific-quotes-in-css-tilpost/
IEEE
" » How to display language-specific quotes in CSS (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2021/02/27/how-to-display-language-specific-quotes-in-css-tilpost/. [Accessed: ]
rf:citation
» How to display language-specific quotes in CSS (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2021/02/27/how-to-display-language-specific-quotes-in-css-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.