Understanding the Sec-CH-UA-Mobile Header

A privacy-friendly HTTP header for mobile device detection in cross-platform web development

What Is Sec-CH-UA-Mobile?

The Sec-CH-UA-Mobile HTTP request header is a user agent client hint that indicates whether the browser is running on a mobile device. It can also communicate a user preference for a "mobile" user experience, even when accessed from a desktop browser. This header is part of a broader effort to replace the information-heavy User-Agent string with a more privacy-respecting system of structured hints that give servers exactly the information they need for content negotiation.

The header operates on a simple boolean principle: a value of ?1 indicates that the user agent prefers or is running on a mobile device, while ?0 indicates a non-mobile context. This straightforward approach eliminates the need for servers to parse and interpret complex User-Agent strings, which historically have varied significantly between browsers and devices. The structured nature of the header, defined using RFC 9651 (Structured Field Values for HTTP), ensures consistent parsing across different server implementations.

For developers building cross-platform mobile applications using React Native, iOS, or Android, understanding this header is essential for creating responsive web experiences that adapt seamlessly to different device types. Whether your app uses web views, embedded browsers, or Progressive Web App (PWA) technologies, the Sec-CH-UA-Mobile header provides a reliable signal for content adaptation without compromising user privacy. When implementing these mobile detection strategies as part of a broader web development approach, you can create seamless experiences across all device types.

Key Characteristics

  • Low entropy hint: Sent by default with every request
  • Boolean values: ?1 for mobile, ?0 for non-mobile
  • Privacy-friendly: Minimal information exposure
  • Server-side detection: Simple, reliable mobile context detection

What makes Sec-CH-UA-Mobile particularly valuable for mobile development is its classification as a "low entropy" hint. Low entropy hints are sent by default with every request, without requiring servers to explicitly opt-in through Accept-CH headers. This means servers can immediately determine mobile context without any additional negotiation, enabling instant content adaptation for mobile users. The header is also classified as a "forbidden request header," meaning it cannot be modified by JavaScript or set by non-browser clients, ensuring the value's authenticity and preventing spoofing.

Syntax and Values

The Sec-CH-UA-Mobile header follows a strict syntax defined by the Structured Field Values for HTTP specification (RFC 9651). As a structured boolean header, it accepts only two possible values: ?1 for true and ?0 for false. This binary approach might seem limiting, but it perfectly serves the primary use case of mobile detection while minimizing the information exposed to servers.

The header's ABNF (Augmented Backus-Naur Form) definition is straightforward: Sec-CH-UA-Mobile = sf-boolean. This means the header value must be either ?1 or ?0 with no additional characters, whitespace, or variations. This rigid specification ensures that all implementations, regardless of programming language or server framework, interpret the header identically.

Server-Side Detection in Different Languages

Node.js/Express:

function isMobileRequest(headers) {
 const mobileHeader = headers['sec-ch-ua-mobile'];
 return mobileHeader === '?1';
}

app.get('/', (req, res) => {
 if (isMobileRequest(req.headers)) {
 res.render('mobile-index');
 } else {
 res.render('desktop-index');
 }
});

Python/Flask:

def is_mobile_request(headers):
 mobile_header = headers.get('sec-ch-ua-mobile', '')
 return mobile_header == '?1'

@app.route('/')
def index():
 if is_mobile_request(request.headers):
 return render_template('mobile-index.html')
 else:
 return render_template('desktop-index.html')

PHP:

function isMobileRequest($headers) {
 $mobileHeader = $headers['sec-ch-ua-mobile'] ?? '';
 return $mobileHeader === '?1';
}

if (isMobileRequest(getallheaders())) {
 include 'mobile-index.php';
} else {
 include 'desktop-index.php';
}

For mobile developers working with web views in React Native, iOS, or Android applications, understanding how these headers are generated is important. Native web views generally respect the same client hint mechanisms as mobile browsers, meaning that hybrid applications can rely on Sec-CH-UA-Mobile for mobile detection just as they would with standalone mobile browsers. However, developers should test their specific web view implementations, as some embedded browsers may have different behaviors depending on the underlying platform and web view engine. When building comprehensive web development solutions that span multiple platforms, proper header handling becomes essential for consistent user experiences.

Server-Side Mobile Detection
1function isMobileRequest(headers) {2 const mobileHeader = headers['sec-ch-ua-mobile'];3 return mobileHeader === '?1';4}5 6// Example usage in Express.js7app.get('/', (req, res) => {8 if (isMobileRequest(req.headers)) {9 res.render('mobile-index');10 } else {11 res.render('desktop-index');12 }13});

Low Entropy Hints and Privacy

The classification of Sec-CH-UA-Mobile as a "low entropy" hint is fundamental to understanding its privacy benefits and behavior. In the context of client hints, "entropy" refers to the amount of identifying information a hint reveals about a user. Low entropy hints provide minimal, non-identifying information that is broadly useful without enabling user tracking. High entropy hints, in contrast, provide detailed information that could be combined to create unique user fingerprints.

Sec-CH-UA-Mobile is considered low entropy because it conveys only a single bit of information: whether the client is mobile or not. This information is obvious from other request characteristics (such as screen size or viewport dimensions) and cannot be used to identify individual users across requests. The header's binary nature means it provides no information that could be used for tracking or fingerprinting beyond the immediate context of the current request.

Default Availability

One of the key characteristics of low entropy hints is their default availability. Unlike high entropy hints, which require servers to explicitly request them through Accept-CH headers, low entropy hints like Sec-CH-UA-Mobile are sent with every request by default. This means servers can immediately determine mobile context without any prior negotiation or user interaction.

This default availability is particularly valuable for mobile detection because it eliminates the round-trip delay that would otherwise occur if servers needed to request the hint. When a user visits a website from a mobile device, the first request already includes Sec-CH-UA-Mobile, allowing servers to serve mobile-optimized content immediately rather than requiring a redirect or subsequent request.

Security Implications of the Sec- Prefix

The Sec-CH-UA-Mobile header uses the Sec- prefix, which designates it as a "forbidden request header." This prefix indicates that the header can only be set by the browser or user agent itself--it cannot be modified, added, or removed by JavaScript or other client-side code. This security measure ensures the authenticity of the header value, preventing malicious websites from spoofing mobile indicators to receive mobile-optimized content.

For mobile developers, this security feature provides assurance that the mobile detection they implement cannot be easily bypassed or manipulated. Unlike User-Agent strings, which can be modified through browser extensions or developer tools, Sec-CH-UA-Mobile provides a trustworthy signal that reflects the actual device characteristics. The forbidden header mechanism also protects users from potential abuse. If websites could freely set mobile indicators, it could enable various forms of fingerprinting or tracking that the Client Hints infrastructure aims to prevent. By restricting header modification to the browser itself, the specification maintains the privacy benefits of the client hints approach. For organizations prioritizing both user privacy and technical excellence, implementing these privacy-first SEO services ensures sustainable organic growth.

Server-Side Implementation Benefits

Instant Detection

Low entropy hints are sent by default, enabling immediate mobile detection without additional negotiation or round-trips.

Simple Logic

Boolean values enable straightforward detection logic that is easy to implement, test, and maintain.

Cross-Platform Support

Works consistently across Chromium-based browsers and web views in React Native, iOS, and Android applications.

Future-Proof

Standardized specification ensures reliable behavior as browsers evolve and privacy features mature.

Frequently Asked Questions

Build Better Mobile Experiences

Our team specializes in cross-platform mobile development using React Native, iOS, and Android. Learn how we can help you create mobile-optimized web experiences.