223
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?

3 Answers 3

288

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."

17
  • 45
    Very nice, thanks! But why not just list them in the order of preference?
    – kolypto
    Dec 18, 2011 at 16:12
  • 12
    So what exactly does it mean to accept 80% qualitied en-gb?
    – Pacerier
    Jan 18, 2012 at 7:08
  • 10
    @TimCooper Why not just have the languages in order or preference? The value doesn't seem to matter, other than it being larger than others.
    – Rob
    May 18, 2016 at 0:29
  • 7
    to @kolypto, parameter lists, whether in a URL or in a header doen't have an implicit order. Jan 24, 2017 at 19:58
  • 4
    @kolypto I think the reason is for more flexibility (your client script can just append desired types, instead of making sure entire list is always sorted). But even more fascinating reason is that it makes your client allow the server to decide which type is better! Look: if the standard was just an ordered list, you could say that for example you prefer HTML over PDF. But what if you are totally fine with both equally? And my website sends awesome PDFs and just good HTML. If you are indifferent, I prefer to send a PDF for you to make you happier!
    – Robo Robok
    Nov 11, 2017 at 11:00
43

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

5
  • 2
    I'm really late to the party - but what do you mean "after an 80% mark-down in quality"? It's the degree of preference, not the quality of the audio file, right? Or am I misreading this?
    – Mave
    Apr 21, 2015 at 14:08
  • 11
    @Mave: Well, in practice it's probably mostly used as a measure of preference. However, in its original formulation, I do believe it's meant to be based on the quality of the encoding. Consider, for instance, FLAC vs MP3. You could say something like: "Send me the MP3 version if it at worst is 50% of the quality of the lossless version. If it isn't, send me the FLAC version." How to quantify such quality, and whether that is used in practice, I do not know, but I do believe that to be the original intention. Apr 21, 2015 at 14:47
  • 1
    @SebastianPaaskeTørholm I came here looking for more info on this. There are only two places in RFC 7231 that seem to hint at this secondary meaning, but it’s not very clear to me how it was intended to work, since the two meanings could conflict with each other — for example it seems like it would be impossible to express a preference for a lossier type over a less lossy type if qvalue is overloaded this way.
    – Semicolon
    Apr 28, 2018 at 17:38
  • is the most preferred language always the first parameter in the header?
    – oldboy
    Jul 31, 2019 at 4:29
  • @BugWhisperer The linked standard has a more elaborate example, where it isn't first. Please consult that. :) Aug 2, 2019 at 11:21
16

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)

3
  • is the most preferred language always the first parameter in the header?
    – oldboy
    Jul 31, 2019 at 4:29
  • @BugWhisperer yes, but if you want to be really strict to the standard and if your translation is pretty simple or weak - you might want to skip the first value
    – test30
    Aug 8, 2019 at 15:23
  • why would using the second value be more strict?
    – oldboy
    Aug 8, 2019 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.