What is the pseudo-class :lang for?

Asked

Viewed 173 times

5

I’ve already turned the internet upside down and always find the same thing as on the site w3schools saying it is to set special rules for languages. I know it has to put characters around the element for example

q:lang(p1)
{
    quotes: "+" "+";
}

More after all what is its functionality? the attribute for example lang="en" defines the language of the document more if I were to use the pseudo-element :lang in html it would be like for example

html:lang(p1)
{
    quotes: "pt" "br";
}

1 answer

4

Let’s make some things clear to facilitate understanding. Basically the :lang() is just a selector. It serves nothing but to indicate the element to which the CSS should be applied.

For example:

p:lang(it) {
    color:red;
}

That means only that the element <p> that has the attribute lang="it" shall be red in colour

p:lang(it) {
    color:red;
}
<p lang="it">Cosa nostra!</p>


Now the HTML attribute lang="" goes far beyond just being used as a selector in CSS, it determines the language with is contained in the element, and it can be very useful in accessibility issues, semantics, and even as a reference for indexing in search engines and for automatic translators and screen readers.

Indicated is to determine the language of the document content in the tag html, guy: <html lang="en">. This will indicate to search engines, or screen readers or translators that the language of the document is in English, however if within this document you have a quote in Italian vc can put a <p lang="it">Cosa nostra!</p> this will make the element more semantic and accessible to screen readrs and translators.

Interesting article from W3C about lang

How should I set the language of the content in my HTML page?
"How to set the content language in my HTML page?"

Always use a language attribute on the html tag to declare the default language of the text in the page. When the page contains content in Another language, add a language attribute to an element surrounding that content.

PORTUGUÊS: "Always use a language attribute in the html tag to declare the default language of the text on the page. When the page contains content in another language, add a language attribute to an element around that content."

https://www.w3.org/International/questions/qa-html-language-declarations

  • Thanks again man, if it’s fucking

  • @Leandronascimento not so much young rss! The question was interesting, the examples they use around for lang is that they leave things confusing, but basically it’s an HTML attribute like another qq, which you can use in CSS to define where you will apply the style. Not much... []s

Browser other questions tagged

You are not signed in. Login or sign up in order to post.