:lang

  • Revision slug: CSS/:lang
  • Revision title: :lang
  • Revision id: 297006
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{ CSSRef() }}

Summary

The :lang CSS pseudo-class matches elements based on the langauge the element is determined to be in. In HTML, the language is determined by a combination of the lang attribute, the {{ HTMLElement("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.

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

Syntax

element:lang(language-code) { style properties }

Examples

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

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

...where...

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

... should look like ...
«This French quote has a «nested» quote.»
»This German quote has a ‹nested› quote.«
“This English quote has a ‘nested’ quote.”

Specifications

Specification Status Comment
{{ SpecName('CSS4 Selectors', '#lang-pseudo', ':lang()') }} {{ Spec2('CSS4 Selectors') }} No change.
{{ SpecName('CSS3 Selectors', '#lang-pseudo', ':lang()') }} {{ Spec2('CSS3 Selectors') }} No significant change.
{{ SpecName('CSS2.1', 'selector.html#lang', ':lang()') }} {{ Spec2('CSS2.1') }} Initial definition.

Browser compatibility

{{ CompatibilityTable() }}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 {{ CompatGeckoDesktop("1") }} 8.0 8.0 3.1
Feature Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support 1.0 {{ CompatGeckoMobile("1") }} 8.0 8.0 3.1

Revision Source

<p>{{ CSSRef() }}</p>
<h2 id="Summary">Summary</h2>
<p>The <code>:lang</code> CSS <a href="/en/CSS/Pseudo-classes" title="Pseudo-classes">pseudo-class</a> matches elements based on the langauge the element is determined to be in. In HTML, the language is determined by a combination of the <code>lang</code> attribute, the {{ HTMLElement("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.</p>
<p>Acceptable <code>language-code</code> strings are specified in the <a href="/en/HTML" title="en/HTML">HTML 4.0</a> specification.</p>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="eval">
element:lang(language-code) { <em>style properties</em> }
</pre>
<h2 id="Examples" name="Examples">Examples</h2>
<p>In this example, the <code>lang</code> selector is used to match on the parent of a quote element using <a href="/en/CSS/Child_selectors" title="en/CSS/Child_selectors">child selectors</a>. Its not meant to demonstrate the only way to do this, or even the correct way (which would depend on the type of document). Note, Unicode values are used to specify special quote characters.</p>
<pre class="brush: css">
:lang(en) &gt; Q { quotes: '\201C' '\201D' '\2018' '\2019'; }
:lang(fr) &gt; Q { quotes: '«&nbsp;' '&nbsp;»'; }
:lang(de) &gt; Q { quotes: '»' '«' '\2039' '\203A'; }
</pre>
<p>...where...</p>
<pre class="brush: html">
  &lt;div lang="fr"&gt;&lt;q&gt;This French quote has a &lt;q&gt;nested&lt;/q&gt; quote.&lt;/q&gt;&lt;/div&gt;
  &lt;div lang="de"&gt;&lt;q&gt;This German quote has a &lt;q&gt;nested&lt;/q&gt; quote.&lt;/q&gt;&lt;/div&gt;
  &lt;div lang="en"&gt;&lt;q&gt;This English quote has a &lt;q&gt;nested&lt;/q&gt; quote.&lt;/q&gt;&lt;/div&gt;
</pre>
<p>... should look like ...<br />
  «This French quote has a «nested» quote.»<br />
  »This German quote has a ‹nested› quote.«<br />
  “This English quote has a ‘nested’ quote.”</p>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>{{ SpecName('CSS4 Selectors', '#lang-pseudo', ':lang()') }}</td>
      <td>{{ Spec2('CSS4 Selectors') }}</td>
      <td>No change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS3 Selectors', '#lang-pseudo', ':lang()') }}</td>
      <td>{{ Spec2('CSS3 Selectors') }}</td>
      <td>No significant change.</td>
    </tr>
    <tr>
      <td>{{ SpecName('CSS2.1', 'selector.html#lang', ':lang()') }}</td>
      <td>{{ Spec2('CSS2.1') }}</td>
      <td>Initial definition.</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{ CompatibilityTable() }}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{ CompatGeckoDesktop("1") }}</td>
        <td>8.0</td>
        <td>8.0</td>
        <td>3.1</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Mobile</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{ CompatGeckoMobile("1") }}</td>
        <td>8.0</td>
        <td>8.0</td>
        <td>3.1</td>
      </tr>
    </tbody>
  </table>
</div>
<h2 id="Related_Pages" name="Related_Pages">See also</h2>
<ul>
  <li><a href="/en/DOM/element.lang" title="en/DOM/element.lang">Language Property</a></li>
  <li><a class="external" href="http://www.w3.org/TR/REC-html40/struct/dirlang.html#h-8.1.1">W3C HTML4: Language codes</a></li>
  <li><a class="external" href="http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-59132807">W3C DOM Level 2 HTML: lang</a></li>
</ul>
Revert to this revision