Skip to content

Accept-Language

Description

The Accept-Language request header is an HTTP header used by clients (such as web browsers) to specify the preferred languages for the response content. This helps servers provide localized content based on user preferences.

The header contains a list of language codes, optionally accompanied by a quality value (q-factor) that indicates preference weight. The server selects the most appropriate language based on this list and serves content accordingly.

Syntax

The Accept-Language header follows this syntax:

Accept-Language: <language1>[;q=<weight1>], <language2>[;q=<weight2>], ...

Where:

  • <language> is a language tag (e.g., en, fr, es-ES).
  • q=<weight> is an optional quality factor (ranging from 0.0 to 1.0), where higher values indicate higher preference.

Examples

Basic Usage in HTTP Requests

A client specifying English as the preferred language:

GET /resource HTTP/2
Host: example.com
Accept-Language: en

A client requesting multiple languages with preferences:

GET /resource HTTP/2
Host: example.com
Accept-Language: en-US, fr-CA;q=0.8, es;q=0.6

Server Response Example

The server inspects the Accept-Language header and responds with content in the most suitable language:

HTTP/2 200 OK
Content-Language: en-US

Summary

The Accept-Language request header is an essential tool for web localization, allowing clients to request content in preferred languages. By properly handling this header, servers can enhance user experience by serving content in the most suitable language, improving accessibility and usability for international audiences.