Accept header
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The HTTPAcceptrequest andresponse header indicates which content types, expressed asMIME types, the sender is able to understand.In requests, the server usescontent negotiation to select one of the proposals and informs the client of the choice with theContent-Type response header.In responses, it provides information about which content types the server can understand in messages to the requested resource, so that the content type can be used in subsequent requests to the resource.
Browsers set required values for this header based on the context of the request.For example, a browser uses different values in a request when fetching a CSS stylesheet, image, video, or a script.
| Header type | Request header,Response header |
|---|---|
| Forbidden request header | No |
| CORS-safelisted request header | Yes* |
* Values can't containCORS-unsafe request header bytes, including"():<>?@[\]{},, Delete0x7F, and control characters0x00 to0x19, except for Tab0x09.
In this article
Syntax
Accept: <media-type>/<MIME_subtype>Accept: <media-type>/*Accept: */*// Multiple types, weighted with the quality value syntaxAccept: text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8Directives
<media-type>/<subtype>A single, precisemedia type, like
text/html.<media-type>/*A media type without a subtype.For example,
image/*corresponds toimage/png,image/svg,image/gif, and other image types.*/*Any media type.
;q=(q-factor weighting)A value in order of preference expressed using a relativequality value called theweight.
Examples
>Using default Accept request headers
HTTP requests made using command line tools such ascurl andwget use*/* as the defaultAccept value:
GET / HTTP/1.1Host: example.comUser-Agent: curl/8.7.1Accept: */*Browser navigation typically has the followingAccept request header value:
GET /en-US/ HTTP/2Host: developer.mozilla.orgAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8…After receiving the document, the defaultAccept values in requests for images on thedeveloper.mozilla.org example look like this:
Accept: image/avif,image/webp,image/png,image/svg+xml,image/*;q=0.8,*/*;q=0.5Configuring Accept request headers for JSON responses
Systems that involve API interaction commonly requestapplication/json responses.Here's an example of aGET request where the client specifically requests a JSON response:
GET /users/123 HTTP/1.1Host: example.comAuthorization: Bearer abcd123Accept: application/jsonSpecifications
| Specification |
|---|
| HTTP Semantics> # field.accept> |
Browser compatibility
See also
- HTTPcontent negotiation
- List of default Accept values
- CORS safelist request header restrictions
- A header with the result of the content negotiation:
Content-Type - Other similar headers:
TE,Accept-Encoding,Accept-Language