MapCSS/0.2/Proposal media query

From OpenStreetMap Wiki
< MapCSS‎ | 0.2
Jump to: navigation, search


Media queries are used to skip a section of the style under certain conditions. Typically you want to use a feature which is not available in all renderers. Depending on the renderer there might also be queries depending on the version of the renderer. The syntax closely matches the official ​css syntax.

Media queries consist of expressions of media types and/or media features, which resolve to either true or false. When a media query is true, the corresponding style rules are applied.

The and operator is used for combining multiple media features/types together into a single media query, requiring each chained feature to return true in order for the query to be true. The not operator is used to negate an entire media query.

You can also combine multiple media queries in a comma-separated list; if any of the media queries in the list is true, the entire media statement returns true. This is equivalent to an or operator.

Media types

A list of possible media types can be found here. The default media type is all.

Example: @media all { }

Media features

Media features are put into parenthesis. Most media features can be prefixed with "min-" or "max-" to express "greater or equal to" or "less than or equal to" constraints. This avoids using the "<" and ">" symbols, which would conflict with HTML and XML. If you use a media feature without specifying a value, the expression resolves to true if the feature's value is non-zero.

Supported media features:

media feature description
user-agent Only include @media section when the name of the editor / renderer matches the given string. No min-/max- prefixes.
mapcss-version program implements given mapcss version (current: 0.2). min-/max-prefixes supported, whereas value is interpreted as version, not floating point (e.g. 0.12 > 0.9)


  • An unknown query should always evaluate to false and not raise a warning, e.g. @media (min-josm-version: 7000) { ... }.
  • The content in a failed media query should be ignored, so that it might not be syntactically correct (new syntaxes, ...).


Example (all highways will be colored red in JOSM and pgmapcss and blue in all other renderers):

@media (user-agent: josm), (user-agent: pgmapcss) {
  way[highway] {
    color: red;
    width: 2;
@media not (user-agent: josm) and (user-agent: pgmapcss) {
  way[highway] {
    color: blue;
    width: 2;

Current/Planned support in libraries

Function JOSM pgm
@media, general support + +[1]
user agent name "josm" "pgmapcss"
@media all + -
@media (user-agent: xxx) + +
@media (mapcss-version: 0.2) - -
  1. (as of June 2014) current development branch, upcoming version 0.8


  • It would be interesting to specify queries depending on a feature, e.g. if the renderer supports shields. @media (feature: shield) { ... }. I suggest to create a follow-up proposal after media queries are introduced initially. -- Skunk (talk) 15:49, 22 June 2014 (UTC)
    • CSS has the @supports syntax.--Zuse (talk) 10:42, 3 July 2014 (UTC)
      • Interesting! Thanks for pointing out ... -- Skunk (talk) 15:45, 19 July 2014 (UTC)
      • I didn't know the @supports syntax, thanks! I would consider to dropping @media completely and using @support instead. It is the "proper" CSS feature, i.e. it matches what we are trying to do here in MapCSS. Another advantage is the clearer and more flexible syntax for connecting elements with and, or and not. The only disadvantage I see, is that the original CSS feature isn't intended to support something like @supports (user-agent: pgmapcss) { }. However, that would be a straightforward extension. --Bk (talk) 22:11, 23 July 2014 (UTC)