What is q=0.5 in Accept* HTTP headers?

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

What do these 'q=%f' mean?


Solution 1:

This is called a relative quality factor. It specifies what language the user would prefer, on a scale of 0 to 1, as can be seen from the HTTP/1.1 Specification, §14.4:

Each language-range MAY be given an associated quality value which represents an estimate of the user's preference for the languages specified by that range. The quality value defaults to "q=1". For example,

  Accept-Language: da, en-gb;q=0.8, en;q=0.7

would mean: "I prefer Danish, but will accept British English and other types of English."

Solution 2:

It is called the relative quality factor in the specification:

Each media-range MAY be followed by one or more accept-params, beginning with the "q" parameter for indicating a relative quality factor. The first "q" parameter (if any) separates the media-range parameter(s) from the accept-params. Quality factors allow the user or user agent to indicate the relative degree of preference for that media-range, using the qvalue scale from 0 to 1 (section 3.9). The default value is q=1.

...

The example

Accept: audio/*; q=0.2, audio/basic

SHOULD be interpreted as "I prefer audio/basic, but send me any audio type if it is the best available after an 80% mark-down in quality."

See also:

  • HTTP/1.1: Header Field Definitions

Solution 3:

Accept-languages quality parameter can be understood like this:

by attaching Accept-Language: pl_PL;q=0.8, en_US;q=0.2, header to the request we communicate to the server following message

Server, please provide me Polish translation of this website, but please do that only if its quality is >= %80% of related-quality-factor. In case quality is <80% - I do not mind getting the English version, because it is irrelevant for me since I speak English anyway.

So for example, as a web page content provider we might introduce Accept-Language header parsing in such a way, that our website is suitable for foreigners speaking no English at all (then even translated navigation would be helpful (pages having translated only the navigation, lets say, have q=0.1), where fully translated content has q=0.9 and fully translated content and verified by native speakers speaking both original language and translated language content might have q=0.99 - because this is the only possible situation when meaning of the content is fully transduced)