Accept-Language Header — HTTP Content Negotiation
How the Accept-Language HTTP header works for content negotiation, including quality values, parsing, and server-side implementation.
Detailed Explanation
What Is Accept-Language?
The Accept-Language request header tells the server which languages the client prefers. It is sent automatically by browsers based on the user's OS and browser language settings.
Header Syntax
Accept-Language: <language-tag>[;q=<quality>], ...
The quality value (q) ranges from 0 to 1, with 1 being the highest preference (default when omitted).
Examples
Accept-Language: en-US
Accept-Language: en-US,en;q=0.9,ja;q=0.8
Accept-Language: fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5
How Quality Values Work
| Tag | Quality | Meaning |
|---|---|---|
fr-CH |
1.0 (default) | Most preferred: Swiss French |
fr |
0.9 | Then any French |
en |
0.8 | Then English |
de |
0.7 | Then German |
* |
0.5 | Then any language |
Server-Side Handling
When a server receives this header, it should:
- Parse the header into a sorted list of preferences
- Match against available content languages
- Return the best match with a
Content-Languageresponse header - Include a
Vary: Accept-Languageheader for caching
// Node.js example
const acceptLanguage = req.headers["accept-language"];
// "en-US,en;q=0.9,ja;q=0.8"
// Parse and match against available locales
Relationship to BCP 47
Accept-Language values are BCP 47 language tags. The matching follows RFC 4647 "Matching of Language Tags," which defines both basic and extended filtering algorithms.
Privacy Considerations
The Accept-Language header can be used as a fingerprinting vector because it reveals the user's language preferences. Some privacy-focused browsers limit the information sent in this header.
Use Case
Server-side content negotiation uses Accept-Language to automatically serve pages in the user's preferred language. It is critical for building multilingual APIs, CDN-based language routing, and locale-aware middleware in frameworks like Express.js, Django, or Next.js.
Try It — Language Code Reference
Related Topics
BCP 47 Language Tags — The Web Standard for Locale Identifiers
Standards
Locale Negotiation in Web Apps — Choosing the Right Language
Web Development
Language Tags in HTML — The lang Attribute Guide
Web Development
Language Codes in SEO (hreflang) — Multilingual SEO Guide
SEO
Intl API Locale Codes — JavaScript Internationalization
Web Development