🎉 Requestly joins BrowserStack to build the future of application testing. Read more

HTTP Headers

Accept Language

HTTP Header

The HTTP Accept-Language request header specifies the natural language and locale preferred by the client. The server interprets this information through content negotiation, selecting an appropriate content version and informing the client with the Content-Language response header. Browsers automatically set values for this header based on their active user interface language settings, and users can manually adjust additional preferred languages through browser options.

The Accept-Language header usually lists the same locales as the navigator.languages property, with decreasing q values indicating preference quality. Some browsers, such as Chrome and Safari, include fallback tags that specify language-only preferences. For example, the header might read en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7 when navigator.languages contains ["en-US", "zh-CN"]. For privacy considerations, to reduce fingerprinting, both the header and navigator property may omit parts of the full list of user preferences, especially in privacy-sensitive modes like Safari or Chrome’s incognito mode. Consequently, only one language may be listed in such cases.

This header acts as a hint for the server when it cannot determine the desired content language through other means, such as specific URLs based on explicit user decisions. Servers should not override explicit user language choices, which can be outside of user control, such as during travel. Users might also want to view a website in a language different from their interface language.

The server might return a 406 Not Acceptable status if it cannot serve content in a language matching the request, but this response is uncommon. More often, servers ignore the header and respond successfully with the most suitable resource to enhance user experience.

The header is not a forbidden request header but is considered a CORS-safelisted request header. When used in cross-origin requests, its values are limited to characters 0-9, A-Z, a-z, spaces, or special characters like *, -, .;=.

Syntax

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

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

Directives

<language>

A language tag, also known as a “locale identifier”, specifies a language in a concise format.
This tag usually consists of a two or three-letter base language code, like en for English or fr for French, and may include optional subtags separated by a hyphen (-).
The additional parts typically indicate regional variants, such as en-US for American English or fr-CA for Canadian French, or scripts and orthographies like sr-Latn for Latin script Serbian.
Other variants, like specific orthography versions (de-DE-1996), are generally less common and usually not used in this context.

* (wildcard)

This symbol matches any language not specified elsewhere in the Accept-Language list.

;q= (q-factor weighting)

This parameter indicates a preference level for a language or variant, using a quality or weight value.
The default quality value is 1, meaning highest preference.

Example

The following requests demonstrate how to specify language preferences using HTTP headers:

To indicate a preference for German, the Accept-Language header can be set to de:

http
Accept-Language: de

Alternatively, to convey a Hierarchy of language preferences, you can use quality values to prioritize certain languages over others. For example, to prefer Danish but accept British English and other English variants at lower priority:

http
Accept-Language: da, en-gb;q=0.8, en;q=0.7

How to Modify Header using Requestly

Requestly is a powerful Chrome extension that allows you to modify HTTP headers, including the Accept header. This is especially useful for testing how your application responds to different media types during development or debugging. Steps to Modify the Accept Header:

  1. Install and open the Requestly Chrome extension. You can find it on the Chrome Web Store.
  2. Create a new rule: Click on “Create Rule” and choose “Modify Headers” from the list of available rule types.
  3. Add a new header modification:
    • Under “Action”, select “Add” or “Override”.
    • In the “Header Name” field, enter Accept.
    • In the “Header Value” field, enter your preferred media type (e.g., text/html).
  4. Set the URL condition: Specify the URL or pattern where this header change should apply (e.g., https://your-api.com/*).
  5. Save the rule.

Once set up, Requestly will inject the Accept: text/html header into all matching requests, allowing you to simulate different client behaviors and test content negotiation on your server.

Modifying the Accept header is useful because it helps you see how a website or API responds to different types of data, like HTML, JSON, or XML. This can be important to ensure your application handles various formats correctly.