Media Queries
Media queries are one of the cornerstones of Responsive Web Design. By adding some filter criteria around CSS definitions, we can control under which conditions those rules are applied to web pages. There are two places to define these criteria: using the media attribute of a link tag that references a CSS file or inline on a CSS file.
The inline definition of a CSS media query looks like a block of code, with a syntax similar to:
@media only screen and (max-width:400px) {
#navbar {
float: none;
width: 400px;
}
}
Anything inside of the @media block will only be formatted when the conditions defined next to the @media keyword are met by the browser. The same criteria can be used on the media attribute of a link tag, with syntax similar to the following:
<link href="css/phone.css" rel="stylesheet"
type="text/css"
media="only screen and (max-width: 400px)">
The difference between these two techniques is that the browser may elect to skip loading a stylesheet referenced with a media attribute that it cannot satisfy. With inline media queries on a CSS stylesheet, the styles for all media types are always transmitted to the web site visitor.
For more information on media query support and features, the W3C has a great article that defines the media capabilities browsers should have.