User agent

Also known as: user-agent string

On this page 7

A user agent is the software that acts on behalf of a user when accessing the web, most often a browser, but also crawlers, command-line clients, feed readers and assistive tools. Among browser technologies, the term has two closely related meanings: the client program itself and the user-agent string, the text identifier that the program sends to servers in the User-Agent HTTP request header.

Web standards use the term deliberately. HTML and CSS specifications describe what a conforming user agent must do, which places responsibility for parsing, rendering and security on the client. Servers, analytics tools and scripts read the identifier to adapt responses, collect statistics and detect automated traffic, although modern practice discourages relying on it.

How the user-agent string is built and sent

Every HTTP request from a typical client carries a User-Agent header, defined in the HTTP semantics specification as a list of product tokens with optional comments. A browser string usually contains a legacy Mozilla/5.0 prefix, platform details in parentheses, the rendering engine token and the browser name with its version.

The odd structure is historical baggage. Early servers sent advanced pages only to clients that claimed to be Mozilla, so competitors copied the token, and later browsers appended like Gecko or Safari for the same reason. The table breaks down a representative desktop string.

ComponentExample valueWhat it signals
Compatibility prefixMozilla/5.0Legacy token kept for old server checks
Platform comment(Windows NT 10.0; Win64; x64)Operating system and architecture
Engine tokenAppleWebKit/537.36 (KHTML, like Gecko)Rendering engine family
Browser tokenChrome/131.0.0.0Browser name and major version
Trailing tokenSafari/537.36Further compatibility claim
Components of a typical browser user-agent string

Scripts can read the same value through navigator.userAgent. Because both the header and the property are controlled entirely by the client, any program can send any string, which is why the value is a hint rather than proof of identity.

Kinds of user agents on the web

Browsers produce most human traffic, but a large share of requests comes from non-browser user agents. Recognizing the category helps when reading server logs and configuring access rules.

CategoryExamples of behaviorIdentifies itself by
Desktop and mobile browsersRender pages, run JavaScript, store cookiesEngine and browser tokens
Search engine crawlersFetch and index pages at scaleBot name and verification address
HTTP libraries and CLI toolsFetch resources without renderingLibrary name and version
Headless browsersAutomated testing and scrapingOften a modified browser token
Assistive technology hostsExpose content to screen readersUsually the underlying browser
Embedded webviewsShow web content inside native appsBrowser token plus app marker
Common categories of user agents

Legitimate crawlers can usually be verified through reverse DNS lookup of the requesting address, because the user-agent string alone is trivially copied by scrapers that impersonate well-known bots.

User-agent reduction and client hints

Detailed strings expose information that helps passive fingerprinting, the tracking of users without cookies by combining many small signals. Chromium-based browsers therefore froze and reduced the string: minor version numbers, detailed operating system versions and device models are replaced by fixed placeholder values.

The replacement mechanism is User-Agent Client Hints. The browser sends a small set of low-entropy headers by default, such as Sec-CH-UA and Sec-CH-UA-Mobile, and a server must explicitly request high-entropy hints like the full version or device model with the Accept-CH response header. Gecko-based and WebKit-based browsers apply their own forms of reduction and have not adopted every client hint.

AspectUser-agent stringClient hints
DeliverySent on every requestLow-entropy by default, rest on request
FormatOne free-form text valueStructured header fields
Privacy impactExposes details passivelyDetailed data only when asked
Script accessnavigator.userAgentnavigator.userAgentData
Engine supportUniversalMainly Chromium-based browsers
Classic string versus client hints

Sniffing versus feature detection

User-agent sniffing means choosing behavior by parsing the identifier. It is fragile because strings change with every release, browsers impersonate one another and new browsers inherit wrong assumptions. The recommended alternative is feature detection: testing whether an API or CSS feature exists before using it, often combined with a polyfill.

SituationRecommended approachReason
Using a new JavaScript APIFeature detectionTests real capability, not a claim
Serving responsive layoutsCSS media queriesAdapts to screen, not device name
Traffic statisticsParse the string or hintsAggregate trends tolerate errors
Working around a known engine bugNarrow, documented sniffingNo feature test can detect the bug
Blocking abusive botsCombine with rate limits and verificationStrings are easily forged
When the identifier is a reasonable input

When a server varies its response by user agent, it should send a Vary: User-Agent header so that shared caches do not serve the wrong variant. This header greatly fragments cache keys, which is another reason to avoid server-side sniffing where possible.

Pitfalls and misconceptions

  • Treating the string as authentication: any client can send any value, so it must never grant access.
  • Assuming one string per device: the same phone produces different values in a browser, a webview and an app.
  • Parsing with brittle patterns: a check for Chrome also matches Edge, Opera and many other Chromium browsers.
  • Ignoring reduced values: frozen version numbers make fine-grained version targeting unreliable.

Changing the identifier in browser developer tools is useful for testing mobile layouts and server branches, but it does not emulate the engine itself. A desktop browser that claims to be a phone still renders with its own engine and supports its own feature set.

Explained without jargon

When your browser asks a website for a page, it introduces itself with a short note that says roughly which program it is and which system it runs on. That program is the user agent, and the note is the user-agent string. Think of it as a name badge that the visitor writes for itself.

Websites read the badge to count visitors or adjust a page, but because anyone can write any badge, it is a hint, not a proof. Modern browsers now share fewer details on that badge to protect privacy.

A typical use case

An online shop notices a sudden rise in traffic to its product search pages, all from requests whose user-agent string claims to be a major search engine crawler. Server load climbs and search results slow down for real customers.

The operations team performs a reverse DNS check on the requesting addresses and finds that most of them do not belong to the search engine at all. They add a rule that verifies crawler claims before granting higher rate limits and keeps strict limits for unverified clients, regardless of the identifier they send.

At the same time, the developers remove an old script that redirected visitors to a mobile site by searching the string for the word Mobile. They replace it with responsive CSS and feature detection, which ends complaints from tablet users who had been sent to the wrong version.