Course contentsShow
← Web Development
Lesson 2497 of 2,98245. InternationalizationFree lesson

The Accept-Language Header

Understand how browsers send language preferences via HTTP headers and how servers use them for detection.

The Accept-Language Header

What you'll learn: How browsers automatically tell servers which languages users prefer, enabling automatic content localization.

What Is Accept-Language?

Whenever your browser requests a webpage, it sends invisible metadata called HTTP headers. One of these is Accept-Language, which communicates your language preferences to the server. Think of it like walking into an international hotel and the concierge asking, "Which language would you prefer?" — except this happens automatically with every web request.

The browser determines this preference from your operating system or browser language settings. It doesn't require any JavaScript; it's built into the HTTP protocol itself.

The Header Format

The Accept-Language header uses language tags (like en-US, fr, es-MX) combined with optional quality values (weights) that indicate preference strength:

Accept-Language: en-US,en;q=0.9,fr;q=0.8,es;q=0.7

This example says: "I prefer U.S. English most, then any English, then French, then Spanish." The q values range from 0 to 1, with 1 (or omitted) being highest priority.

Server-Side Detection

Servers read this header to decide which language version of content to serve. If you request a page and the server sees Accept-Language: ja,en;q=0.5, it might return Japanese content if available, falling back to English.

This mechanism enables content negotiation — the server adapting responses based on client preferences without the user clicking language selectors.

Limitations to Know

The Accept-Language header represents browser/OS settings, not necessarily the user's actual preference. Users might be on a shared computer or simply haven't configured settings. It's a helpful hint, but shouldn't be the only way to determine language—always provide manual language selection too.

Key Takeaway: The Accept-Language header automatically communicates user language preferences from browser to server with every HTTP request, enabling servers to deliver localized content without user intervention.