This demo is from Daniel Glazman who works actively on web standards and is a long-time mozilla contributor.

CSS Media Queries were originally a proposal submitted to the CSS Working Group by Opera Software and are now implemented in Firefox 3.5. In short, Media Queries extend the media declaration attached to a stylesheet to allow matching based on the rendering device’s intrinsic properties.

Let’s take a link element declaring a stylesheet inside an HTML document:

<link rel="stylesheet" type="text/css" href="style.css"
      media="screen">

Now imagine you want this stylesheet to apply to the document if and only if the width of the content window is less than 300 pixels… CSS Media Queries make it simple to declare:

<link rel="stylesheet" type="text/css" href="style.css"
      media="screen and (max-width: 300px)">

Available properties include viewport’s width and height, device’s width and height, orientation (portrait or landscape), viewport’s aspect ratio, device’s aspect ratio, colormap, resolution and type of device.

It’s then very easy to have one single web page ready for consumption on a wide variety of devices, ranging from mobile devices to monochrome tty displays.

When viewing the demo, please don’t forget to resize the window from large to very very small (less than 100px!) to see it in action.

View the Demo in Firefox 3.5

Loading via planet, RSS or a reader without JavaScript? Click here instead.

15 comments

Post a comment
  1. Yadu Rajiv wrote on July 1st, 2009 at 9:42 am:

    That was awesome!!111 way to go!!s

    Reply

  2. David Tran wrote on July 1st, 2009 at 9:54 am:

    That’s awesome! Very graceful transitions… seems like it mainly reacts to changes in the vertical space available in the viewport and not really to changes in horizontal space – was that just for this example?

    Reply

  3. Gaby wrote on July 1st, 2009 at 10:10 am:

    Wow, that’s a nice feature! The 2nd smallest version does have a lot more height than it needs though, lots of white space at the bottom. I’m not sure if that’s just my browser though, I have quite a few add-ons :D *tries in safe mode* Nope, sill there :(

    Regardless, this feature will certainly be popular for smaller screens.

    Reply

  4. Mario wrote on July 1st, 2009 at 10:28 am:

    I think there’s a bug in this demo.
    If my window has the exact with of 300 pixels then both stylesheets will be loaded. I think you should write max-width:300 and min-width:301 because min/max-width means “smaller/greater or equal than”.

    Reply

  5. meudah wrote on July 1st, 2009 at 11:06 am:

    Vive notre Glazou national & vive Firefox ! :)

    Reply

  6. Alexander Limi wrote on July 1st, 2009 at 2:05 pm:

    @media queries are great stuff, and it’s also supported by the iPhone. That’s how I get a dedicated mobile display format on http://limi.net :)

    Reply

  7. Daniel Glazman wrote on July 1st, 2009 at 2:07 pm:

    @Mario: good catch ! I’ll update the demo. Thanks!

    Reply

  8. thinsoldier wrote on July 1st, 2009 at 2:55 pm:

    Definite dual stylesheets at 300px wide.

    Reply

  9. Ken Saunders wrote on July 1st, 2009 at 5:34 pm:

    Sweeeet!

    Reply

  10. Pingback from CSS media query によるスタイル切り替え : Serendip - Webデザイン・プログラミング on July 1st, 2009 at 7:11 pm:

    [...] 参考:another great CSS media query demo at hacks.mozilla.org    CSSメモ: メディアクエリ    Media Queries [...]

    Reply

  11. Ryan wrote on July 1st, 2009 at 9:07 pm:

    Great to see it finally implemented into Firefox. I did a similar blog post on the iPhones support of media queries and how you can detect orientation with it. Determine iPhone orientation using CSS

    Reply

  12. Pingback from another great CSS media query demo « LocalLab : Foire aux Infos on July 2nd, 2009 at 2:30 am:

    [...] View the Demo in Firefox 3.5 Laisser un commentaire [...]

    Reply

  13. pd wrote on July 2nd, 2009 at 3:15 am:

    Does IE8 support this?

    Reply

  14. elzapp wrote on July 2nd, 2009 at 4:09 am:

    Doesn’t seem to work in my Firefox 3.5 on Ubuntu

    Reply

  15. elzapp wrote on July 2nd, 2009 at 5:19 am:

    Uh.. my bad *blush*, wrong binary

    Reply

Add your comment