MDN will be in maintenance mode on Wednesday September 20th, starting at 10 AM Pacific / 5 PM UTC, for about 1 hour.

The :lang CSS pseudo-class matches elements based on the language the element is determined to be in. In HTML, the language is determined by a combination of the lang attribute, the <meta> element, and possibly by information from the protocol (such as HTTP headers). For other document types there may be other document methods for determining the language.

/* Matches paragraphs, but only if they are specified
   as being en (English language)  */
p:lang(en) {
  quotes: '\201C' '\201D' '\2018' '\2019';
}

Acceptable language-code strings are specified in the HTML 4.0 specification.

Syntax

Formal syntax

:lang( <language-code> )

Parameter

language-code
The language-code string that you want to select for.

Example

In this example, the :lang pseudo-class is used to match the parent of a quote element using child selectors. It's not meant to demonstrate the only way to do this, or even the correct way (which would depend on the type of document). Note that Unicode values are used to specify special quote characters.

HTML

:lang(en) > q { quotes: '\201C' '\201D' '\2018' '\2019'; }
:lang(fr) > q { quotes: '« ' ' »'; }
:lang(de) > q { quotes: '»' '«' '\2039' '\203A'; }

CSS

<div lang="en"><q>This English quote has a <q>nested</q> quote inside.</q></div>
<div lang="fr"><q>This French quote has a <q>nested</q> quote inside.</q></div>
<div lang="de"><q>This German quote has a <q>nested</q> quote inside.</q></div>

Result

Specifications

Specification Status Comment
Selectors Level 4
The definition of ':lang()' in that specification.
Working Draft No change.
Selectors Level 3
The definition of ':lang()' in that specification.
Recommendation No significant change.
CSS Level 2 (Revision 1)
The definition of ':lang()' in that specification.
Recommendation Initial definition.

Browser compatibility

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 (Yes) 1.0 (1.7 or earlier) 8.0 8.0 3.1
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 1.0 (Yes) 1.0 (1) 8.0 8.0 3.1

See also

Document Tags and Contributors

 Last updated by: mfluehr,