Revision 1106837 of Accept-Language

  • Revision slug: Web/HTTP/Headers/Accept-Language
  • Revision title: Accept-Language
  • Revision id: 1106837
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{HTTPSidebar}}

The Accept-Language request HTTP header advertises which languages the client is able to understand, and which locale variant is preferred. Using content negotiation, the server then selects one of the proposal, use it and inform the client of its choice with the {{HTTPHeader("Content-Language")}} response header. Browsers set adequate values for this header according their user interface language and even if a user can change it, this happens rarely (and is frown upon as it leads to fingerprinting).

This header is a hint to be used when the server has no way of determining the language via another way, like a specific URL, that is controlled by an explicit user decision. It is recommended that the server never overrides an explicit decision. The content of the Accept-Language is often out of the control of the user (like when he is traveling and using an Internet Cafe); the user may also want to visit a page in another language than the locale of its user interface.

If the server cannot serve any matching language, it can theoretically send back a {{HTTPStatus("406")}} Not Acceptable error code. But, for UX reason, this is rarely done and the standard way is to ignore the Accept-Language header in this case.

Header type {{Glossary("Request header")}}
{{Glossary("Forbidden header name")}} no

Syntax

Accept-Language: <language>
Accept-Language: <locale>
Accept-Language: *

// Multiple types, weighted with the q-factor syntax:
Accept-Language: fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5

Directives

<language>
A language expressed as a 2 or 3-character string
<locale>
A full language tag. In addition to the language itself, it may contains additional information after a '-'. The most common extra information are the country variant (like 'en-US') or the type of alphabet to use (like 'sr-Lat'). Other variant like the type of orthography ('de-DE-1996') are normally never used in the context of this header
*
Any language, '*' being used as a wildcard.
;q= (q-factor weighting)
Any value used is placed in an order of preference expressed using relative quality factor called the weight.

Examples

Accept-Language: de

Accept-Language: de-CH

Accept-Language: en-US,en;q=0.5

Specifications

Specification Title
{{RFC("7232", "Accept-Language", "5.3.5")}} Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context

Browser compatibility

{{Compat}}

See also

  • HTTP content negotiation
  • Header with the result of the content negotiation: {{HTTPHeader("Content-Language")}}
  • Other similar headers: {{HTTPHeader("TE")}}, {{HTTPHeader("Accept-Encoding")}}, {{HTTPHeader("Accept-Charset")}}, {{HTTPHeader("Accept")}}

Revision Source

<div>{{HTTPSidebar}}</div>

<p>The <strong><code>Accept-Language</code></strong> request HTTP header advertises which languages the client is able to understand, and which locale variant is preferred. Using <a href="/en-US/docs/Web/HTTP/Content_negotiation">content negotiation</a>, the server then selects one of the proposal, use it and inform the client of its choice with the {{HTTPHeader("Content-Language")}} response header. Browsers set adequate values for this header according their user interface language and even if a user can change it, this happens rarely (and is frown upon as it leads to fingerprinting).</p>

<p>This header is a hint to be used when the server has no way of determining the language via another way, like a specific URL, that is controlled by an explicit user decision. It is recommended that the server never overrides an explicit decision. The content of the <code>Accept-Language</code> is often out of the control of the user (like when he is traveling and using an Internet Cafe); the user may also want to visit a page in another language than the locale of its user interface.</p>

<p>If the server cannot serve any matching language, it can theoretically send back a {{HTTPStatus("406")}} <code>Not Acceptable</code> error code. But, for UX reason, this is rarely done and the standard way is to ignore the <code>Accept-Language</code> header in this case.</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">Header type</th>
   <td>{{Glossary("Request header")}}</td>
  </tr>
  <tr>
   <th scope="row">{{Glossary("Forbidden header name")}}</th>
   <td>no</td>
  </tr>
 </tbody>
</table>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
Accept-Language: &lt;language&gt;
Accept-Language: &lt;locale&gt;
Accept-Language: *

// Multiple types, weighted with the q-factor syntax:
Accept-Language: fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5</pre>

<h2 id="Directives">Directives</h2>

<dl>
 <dt><code>&lt;language&gt;</code></dt>
 <dd>A language expressed as a 2 or 3-character string</dd>
 <dt><code>&lt;locale&gt;</code></dt>
 <dd>A full language tag. In addition to the language itself, it may contains additional information after a <code>'-'</code>. The most common extra information are the country variant (like <code>'en-US'</code>) or the type of alphabet to use (like <code>'sr-Lat'</code>). Other variant like the type of orthography (<code>'de-DE-1996'</code>) are normally never used in the context of this header</dd>
 <dt><code>*</code></dt>
 <dd>Any language, <code>'*'</code> being used as a wildcard.</dd>
 <dt><code>;q=</code> (q-factor weighting)</dt>
 <dd>Any value used is placed in an order of preference expressed using relative <a href="/en-US/docs/Glossary/Q-factor">quality factor</a> called the <em>weight</em>.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<pre>
Accept-Language: de

Accept-Language: de-CH

Accept-Language: en-US,en;q=0.5
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Title</th>
  </tr>
  <tr>
   <td>{{RFC("7232", "Accept-Language", "5.3.5")}}</td>
   <td>Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p class="hidden">The compatibility table in this page is generated from structured data. If you’d like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data/README.md">https://github.com/mdn/browser-compat-data/README.md</a> and send us a pull request.</p>

<p>{{Compat}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>HTTP <a href="/en-US/docs/Web/HTTP/Content_negotiation">content negotiation</a></li>
 <li>Header with the result of the content negotiation: {{HTTPHeader("Content-Language")}}</li>
 <li>Other similar headers: {{HTTPHeader("TE")}}, {{HTTPHeader("Accept-Encoding")}}, {{HTTPHeader("Accept-Charset")}}, {{HTTPHeader("Accept")}}</li>
</ul>
Revert to this revision