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:
Where:
<language>
is a language tag (e.g.,en
,fr
,es-ES
).q=<weight>
is an optional quality factor (ranging from0.0
to1.0
), where higher values indicate higher preference.
Examples
Basic Usage in HTTP Requests
A client specifying English as the preferred language:
A client requesting multiple languages with preferences:
Server Response Example
The server inspects the Accept-Language
header and responds with content in
the most suitable language:
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.