<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">

<channel>
	<title>CSS-Tricks</title>
	
	<link>http://css-tricks.com</link>
	<description>Tips, Tricks, and Techniques on using Cascading Style Sheets.</description>
	<lastBuildDate>Mon, 21 May 2012 17:01:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/CssTricks" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="csstricks" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">CssTricks</feedburner:emailServiceId><feedburner:feedburnerHostname xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>SASS vs. LESS</title>
		<link>http://css-tricks.com/sass-vs-less/</link>
		<comments>http://css-tricks.com/sass-vs-less/#comments</comments>
		<pubDate>Thu, 17 May 2012 03:23:52 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Article]]></category>

		<guid isPermaLink="false">http://css-tricks.com/?p=16922</guid>
		<description><![CDATA[<p><p><em>"Which CSS preprocessor language should I choose?"</em> is a hot topic lately. I've been asked in person several times and an online debate has been popping up every few days it seems. It's nice that the conversation has largely turned from whether or not preprocessing is a good idea to which one language is best. Let's do this thing.</p>
<p>Really short answer: SASS</p>
<p>Slightly longer answer: SASS is better on a whole bunch of different fronts, but if you are &#8230;</p></p><p><a href="http://css-tricks.com/sass-vs-less/">SASS vs. LESS</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></description>
			<content:encoded><![CDATA[<p><em>"Which CSS preprocessor language should I choose?"</em> is a hot topic lately. I've been asked in person several times and an online debate has been popping up every few days it seems. It's nice that the conversation has largely turned from whether or not preprocessing is a good idea to which one language is best. Let's do this thing.</p>
<p>Really short answer: SASS</p>
<p>Slightly longer answer: SASS is better on a whole bunch of different fronts, but if you are already happy in LESS, that's cool, at least you are doing yourself a favor by preprocessing.</p>
<p>Much longer answer: Read on.</p>
<p><span id="more-16922"></span></p>
<h3>The Much Longer Answer</h3>
<h4>The Learning Curve with Ruby and Command Line and Whatever</h4>
<p>The only learning curve is the syntax. You should use an app like <a href="http://incident57.com/codekit/">CodeKit</a> to watch and compile your authored files. You need to know jack squat about Ruby or the Command Line or whatever else. Maybe you should, but you don't have to, so it's not a factor here. </p>
<p>Winner: Nobody</p>
<h4>Helping with CSS3</h4>
<p>With either language, you can write your own mixins to help with vendor prefixes. No winner there. But you know how you don't go back and update the prefixes you use on all your projects? (You don't.) You also won't update your handcrafted mixins file. (Probably.) In SASS you can use <a href="http://compass-style.org/">Compass</a>, and Compass <strong>will</strong> keep itself updated, and thus the prefix situation is handled for you. Yes you'll have to keep your local preprocessor software updated and compile/push once in a while, but that's trivial and thinking-free.</p>
<p>So what this comes down to is: <strong>SASS has Compass and LESS does not.</strong> But it goes deeper than that. The attempts at creating a real robust project like Compass for LESS haven't succeeded because the LESS language isn't robust enough to do it properly. More on that next.</p>
<p>Winner: SASS</p>
<h4>Language Ability: Logic / Loops</h4>
<p>LESS has an ability to do "guarded mixins." These are mixins that only take affect <code>when</code> a certain condition is true. Perhaps you want to set a background color based on the current text color in a module. If the text color is "pretty light" you'll probably want a dark background. If it's "pretty dark" you'll want a light background. So you have a single mixin broke into two parts with these guards that ensure that only one of them takes effect.</p>
<pre rel="LESS"><code>.set-bg-color (@text-color) when (lightness(@text-color) &gt;= 50%) {
  background: black;
}
.set-bg-color (@text-color) when (lightness(@text-color) &lt; 50%) {
  background: #ccc;
}</code></pre>
<p>So then when you use it, you'll get the correct background:</p>
<pre rel="LESS"><code>.box-1 {
  color: #BADA55;
  .set-bg-color(#BADA55);
}</code></pre>
<p>That is overly simplified, but you likely get the idea. You can do some fancy stuff with it. LESS can also do self-referencing recursion where a mixin can call itself with an updated value creating a loop. </p>
<pre rel="LESS"><code>.loop (@index) when (@index &gt; 0) {
  .myclass {
    z-index: @index;
  }
  // Call itself
  .loopingClass(@index - 1);
}
// Stop loop
.loopingClass (0) {}

// Outputs stuff
.loopingClass (10);</code></pre>
<p>But thats where the logic/looping abilities of LESS end. SASS has actual logical and looping operators in the language. if/then/else statements, for loops, while loops, and each loops. No tricks, just proper programming. While guarded mixins are a pretty cool, natural concept, language robustness goes to SASS. This language robustness is what makes Compass possible. </p>
<p>For example, Compass has a mixin called <code>background</code>. It's so robust, that you can pass just about whatever you want to that thing that it will output what you need. Images, gradients, and any combination of them comma-separated, and you'll get what you need (vendor prefixes and all). </p>
<p>This succinct and intelligible code:</p>
<pre rel="SCSS"><code>.bam {
  @include background(
    image-url("foo.png"),
    linear-gradient(top left, #333, #0c0),
    radial-gradient(#c00, #fff 100px)
  );
}</code></pre>
<p>Turns into this monster (which is unfortunately what we need for it to work with as good of browser support as we can get):</p>
<pre rel="CSS"><code>.bam {
  background: url('/foo.png'), -webkit-gradient(linear, 0% 0%, 100% 100%, color-stop(0%, #333333), color-stop(100%, #00cc00)), -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 100, color-stop(0%, #cc0000), color-stop(100%, #ffffff));
  background: url('/foo.png'), -webkit-linear-gradient(top left, #333333, #00cc00), -webkit-radial-gradient(#cc0000, #ffffff 100px);
  background: url('/foo.png'), -moz-linear-gradient(top left, #333333, #00cc00), -moz-radial-gradient(#cc0000, #ffffff 100px);
  background: url('/foo.png'), -o-linear-gradient(top left, #333333, #00cc00), -o-radial-gradient(#cc0000, #ffffff 100px);
  background: url('/foo.png'), -ms-linear-gradient(top left, #333333, #00cc00), -ms-radial-gradient(#cc0000, #ffffff 100px);
  background: url('/foo.png'), linear-gradient(top left, #333333, #00cc00), radial-gradient(#cc0000, #ffffff 100px);
}</code></pre>
<p>Winner: SASS</p>
<h4>Website Niceitude</h4>
<p>LESS has a nicer, <a href="http://lesscss.org/">more usable website</a>. The <a href="http://sass-lang.com/docs/yardoc/file.SASS_REFERENCE.html">SASS documentation</a> isn't awful. It's complete and you can find what you need. But when competing for attention from front end people, LESS has the edge. I don't doubt this plays a large role in LESS currently winning the popularity race. <a href="http://twitter.com/TeamSassDesign">Things may be changing though.</a></p>
<p>Winner: LESS</p>
<h4>The @extend Concept</h4>
<p>Say you declare a class which has a bit of styling. Then you want another class which you want to do just about the same thing, only a few additional things. In LESS you'd likely:</p>
<pre rel="LESS"><code>.module-b {
   .module-a(); /* Copies everything from .module-a down here */
   border: 1px solid red;
}</code></pre>
<p>That's an "include" essentially. A mixin, in both languages. You could use an include to do that SASS as well, but you're better off using <code>@extend</code>. With <code>@extend</code>, the styles from <code>.module-a</code> aren't just duplicated down in .mobule-b (what could be considered bloat), the selector for .module-a is altered to <code>.module-a, .module-b</code> in the compiled CSS (which is more efficient).</p>
<pre rel="SCSS"><code>.module-a {
   /* A bunch of stuff */
}
.module-b {
   /* Some unique styling */
   @extend .module-a;
}</code></pre>
<p>Compiles into</p>
<pre rel="SCSS"><code>.module-a, .module-b {
  /* A bunch of stuff */
}
.module-b {
  /* Some unique styling */
}</code></pre>
<p>See that? It rewrites selectors, which is way more efficient.</p>
<p>Winner: SASS</p>
<h4>Variable Handling</h4>
<p>LESS uses @, SASS uses $. The dollar sign has no inherit meaning in CSS, while the @ sign does. It's for things like declaring @keyframes or blocks of @media queries. You could chalk this one up to personal preference and not a big deal, but I think the edge here is for SASS which doesn't confuse standing concepts.</p>
<p>SASS has some weirdness with scope in variables though. If you overwrite a "global" variable "locally", the global variable takes on the local value. This just feels kind of weird.</p>
<pre rel="CSS"><code>$color: black;
.scoped {
  $color: white;
  color: $color;
}
.unscoped {
  // LESS = black (global)
  // SASS = white (overwritten by local)
  color: $color;
}</code></pre>
<p>I've heard it can be useful but it's not intuitive, especially if you write JavaScript.</p>
<p>Winner: Tossup</p>
<h4>Working with Media Queries</h4>
<p>The way most of us started working with <code>@media</code> queries was adding blocks of them at the bottom of your main stylesheet. That works, but it leads to mental disconnect between the original styling and the responsive styles. Like:</p>
<pre rel="CSS"><code>.some-class {
   /* Default styling */
}

/* Hundreds of lines of CSS */

@media (max-width: 800px) {
  .some-class {
    /* Responsive styles */
  }
}</code></pre>
<p>With SASS or LESS, we can bring those styles together through nesting.</p>
<pre rel="SCSS"><code>.some-class {
  /* Default styling */
  @media (max-width: 800px) {
    /* Responsive styles */
  }
}</code></pre>
<p>You can get even sexier with SASS. There is a really cool "respond-to" technique (see code by <a href="https://gist.github.com/1215856">Chris Eppstein</a>, <a href="http://theint.ro/blogs/outro/4686992-responsive-design-with-sass">Ben Schwarz</a>, and <a href="http://jeffcroft.com/blog/2012/mar/02/implementing-responsive-design/">Jeff Croft</a>) for naming/using breakpoints.</p>
<pre rel="SASS"><code>=respond-to($name)

  @if $name == small-screen
    @media only screen and (min-width: 320px)
      @content

  @if $name == large-screen
    @media only screen and (min-width: 800px)
      @content</code></pre>
<p>The you can use them succinctly and semantically:</p>
<pre rel="SASS"><code>.column
    width: 25%
    +respond-to(small-screen)
      width: 100%</code></pre>
<p>Note: requires SASS 3.2, which is in alpha, which you can install with <code>gem install sass --pre</code>. I don't think there is any doubt this is a very nice way to work.</p>
<p>Winner: SASS</p>
<h4>Math</h4>
<p>For the most part, the math is similar, but there are some weirdnesses with how units are handled. For instance, LESS will assume the first unit you use is what you want out, ignoring further units.</p>
<pre rel="LESS"><code>div {
   width: 100px + 2em; // == 102px (weird)
}</code></pre>
<p>In SASS, you get a clear error: Incompatible units: 'em' and 'px'. I guess it's debatable if it's better to error or be wrong, but I'd personally rather have the error. Especially if you're dealing with variables rather than straight units and it's harder to track down.</p>
<p>SASS will also let you perform math on "unknown" units, making it a bit more futureproof should some new unit come along before they are able to update. LESS does not. There is some more weird differences like how SASS handles multiplying values that both have units, but it's esoteric enough to not be worth mentioning.</p>
<p>Winner: Narrowly SASS</p>
<h4>Active Development</h4>
<p>At the time of this writing...</p>
<p><a href="https://github.com/cloudhead/less.js/issues">Number of open issues</a> on LESS: 392<br />
<a href="https://github.com/nex3/sass/issues">Number of open issues</a> on SASS: 84</p>
<p><a href="https://github.com/cloudhead/less.js/pulls">Pending pull requests</a> on LESS: 86<br />
<a href="https://github.com/nex3/sass/pulls">Pending pull requests</a> on SASS: 3</p>
<p><a href="https://github.com/cloudhead/less.js/commits/master/">Number of commits</a> in the last month in LESS: 11<br />
<a href="https://github.com/nex3/sass/commits/stable/">Number of commits</a> in the last month in SASS: 35</p>
<p>None of that stuff is any definitive proof that one project is more active than the other, but the numbers do seem to always leans toward SASS. As I understand it, both of the leads work on the languages in whatever little free time they have, as they both have other major new projects they are working on. </p>
<p>Winner: Probably SASS</p>
<h3>More Reading</h3>
<ul>
<li>Chris Eppstein: <a href="https://gist.github.com/674726">SASS/LESS Comparison</a></li>
<li>Jeremy Hixon: <a href="http://coding.smashingmagazine.com/2011/09/09/an-introduction-to-less-and-comparison-to-sass/">An Introduction To LESS, And Comparison To Sass</a></li>
<li>Ken Collins: <a href="http://metaskills.net/2012/02/27/too-less-should-you-be-using-sass/">Too LESS? Should You Be Using Sass?</a></li>
<li>Johnathan Croom: <a href="http://net.tutsplus.com/tutorials/html-css-techniques/sass-vs-less-vs-stylus-a-preprocessor-shootout/">Sass vs. LESS vs. Stylus: Preprocessor Shootout</a></li>
</ul>
<p><a href="http://css-tricks.com/sass-vs-less/">SASS vs. LESS</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></content:encoded>
			<wfw:commentRss>http://css-tricks.com/sass-vs-less/feed/</wfw:commentRss>
		<slash:comments>183</slash:comments>
		</item>
		<item>
		<title>Responsive Images and Web Standards at the Turning Point</title>
		<link>http://www.alistapart.com/articles/responsive-images-and-web-standards-at-the-turning-point/</link>
		<comments>http://css-tricks.com/responsive-images-and-web-standards-at-the-turning-point/#comments</comments>
		<pubDate>Wed, 16 May 2012 04:04:17 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Link]]></category>

		<guid isPermaLink="false">http://css-tricks.com/?p=17013</guid>
		<description><![CDATA[<p><p>Mat Marquis keeping us up to date on the responsive images hot drama. Good reminder at the end about not picking sides. </p>
<p><a href="http://www.alistapart.com/articles/responsive-images-and-web-standards-at-the-turning-point/" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://css-tricks.com/responsive-images-and-web-standards-at-the-turning-point/">Permalink</a>&#8230;</p></p><p><a href="http://css-tricks.com/responsive-images-and-web-standards-at-the-turning-point/">Responsive Images and Web Standards at the Turning Point</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></description>
			<content:encoded><![CDATA[<p>Mat Marquis keeping us up to date on the responsive images hot drama. Good reminder at the end about not picking sides. </p>
<p><a href="http://www.alistapart.com/articles/responsive-images-and-web-standards-at-the-turning-point/" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://css-tricks.com/responsive-images-and-web-standards-at-the-turning-point/">Permalink</a></p><p><a href="http://css-tricks.com/responsive-images-and-web-standards-at-the-turning-point/">Responsive Images and Web Standards at the Turning Point</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></content:encoded>
			<wfw:commentRss>http://css-tricks.com/responsive-images-and-web-standards-at-the-turning-point/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ShopTalk Episode 18</title>
		<link>http://shoptalkshow.com/episodes/018-with-gene-crawford/</link>
		<comments>http://css-tricks.com/shoptalk-episode-18/#comments</comments>
		<pubDate>Wed, 16 May 2012 00:11:46 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Link]]></category>
		<category><![CDATA[ShopTalk]]></category>

		<guid isPermaLink="false">http://css-tricks.com/?p=17010</guid>
		<description><![CDATA[<p><p>With ol' Mean Gene Crawford! We talk about crazy clients, responsive images, health, and all kinds of other shoptalk. Thanks to <a href="http://mijingo.com/">Mijingo</a> for sponsoring this episode.</p>
<p><a href="http://shoptalkshow.com/episodes/018-with-gene-crawford/" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://css-tricks.com/shoptalk-episode-18/">Permalink</a>&#8230;</p></p><p><a href="http://css-tricks.com/shoptalk-episode-18/">ShopTalk Episode 18</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></description>
			<content:encoded><![CDATA[<p>With ol' Mean Gene Crawford! We talk about crazy clients, responsive images, health, and all kinds of other shoptalk. Thanks to <a href="http://mijingo.com/">Mijingo</a> for sponsoring this episode.</p>
<p><a href="http://shoptalkshow.com/episodes/018-with-gene-crawford/" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://css-tricks.com/shoptalk-episode-18/">Permalink</a></p><p><a href="http://css-tricks.com/shoptalk-episode-18/">ShopTalk Episode 18</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></content:encoded>
			<wfw:commentRss>http://css-tricks.com/shoptalk-episode-18/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Which responsive images solution should you use?</title>
		<link>http://css-tricks.com/which-responsive-images-solution-should-you-use/</link>
		<comments>http://css-tricks.com/which-responsive-images-solution-should-you-use/#comments</comments>
		<pubDate>Fri, 11 May 2012 14:39:32 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Article]]></category>

		<guid isPermaLink="false">http://css-tricks.com/?p=16932</guid>
		<description><![CDATA[<p><p>There are a bunch of techniques going around for dealing with <strong>responsive images</strong> lately. That is, solutions to help us serve the right image for the occasion (e.g. size of screen and bandwidth available). They all do things a bit differently. To keep track, Christopher Schmitt and I have created <a href="https://docs.google.com/spreadsheet/ccc?key=0Al0lI17fOl9DdDgxTFVoRzFpV3VCdHk2NTBmdVI2OXc">this spreadsheet of techniques</a>.</p>
<p>The spreadsheet has the data, but let's digest it through thinking about it through the lens of practical questions.</p>
<p></p>
<p>To choose which technique is right &#8230;</p></p><p><a href="http://css-tricks.com/which-responsive-images-solution-should-you-use/">Which responsive images solution should you use?</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></description>
			<content:encoded><![CDATA[<p>There are a bunch of techniques going around for dealing with <strong>responsive images</strong> lately. That is, solutions to help us serve the right image for the occasion (e.g. size of screen and bandwidth available). They all do things a bit differently. To keep track, Christopher Schmitt and I have created <a href="https://docs.google.com/spreadsheet/ccc?key=0Al0lI17fOl9DdDgxTFVoRzFpV3VCdHk2NTBmdVI2OXc">this spreadsheet of techniques</a>.</p>
<p>The spreadsheet has the data, but let's digest it through thinking about it through the lens of practical questions.</p>
<p><span id="more-16932"></span></p>
<p>To choose which technique is right for you and your project these questions may help as a guide. Many of the questions may apply to your project, so you'll have to sort out which techniques fit what scenarios and find the overlap.</p>
<h3>Do I have legacy content?</h3>
<p>Which really means... <strong>do I have legacy content that is impractical to update?</strong> For instance, I have thousands of pages of content on CSS-Tricks and a writing staff of one. </p>
<figure><img src="http://cdn.css-tricks.com/wp-content/uploads/2012/05/legacycontent.png" alt="" title="legacycontent" width="148" height="147" class="alignnone size-full wp-image-16972" /></p>
<figcaption>Yeahhhh... I'm not going to go back and update every <code>&lt;img&gt;</code> on the site, so I need a technique that will allow me to leave those alone.</figcaption>
</figure>
<p>The only technique I know of that works with absolutely no markup changes is <a href="http://adaptive-images.com/">Adaptive Images</a>. It works by routing requests for images through a PHP file which intelligently serves (and creates if need be) images of the appropriate size for the screen width.</p>
<p>Another question to ask yourself is if you care about legacy content. Perhaps the vast majority of traffic to your site is for newer content in which you <strong>can</strong> make markup changes and thus take advantage of other techniques. If that's the case, read on to discover those other techniques.</p>
<p>If you have a small project, a brand new project, or a project with legacy content that you are able go back and update, you are also able to choose a technique which does require special markup, so also read on.</p>
<h4>Do I care about special markup?</h4>
<p>This is really a sub-question of the above. Many of the techniques require you to use special HTML. For example, <a href="https://github.com/teleject/hisrc">HiSRC</a> has you put higher resolution images as data-attributes:</p>
<pre rel="HTML"><code>&lt;img src="200x100.png" data-1x="400x200.png" data-2x="800x400.png"&gt;</code></pre>
<p>I'd say this is a clean, valid, semantic technique, but it also means that you need these attributes on every <code>&lt;img&gt;</code> on your site, which may not be possible on sites with loads of legacy content.</p>
<p>If you know that special markup (or specialized CSS) is not an option for you, really the only option is <a href="http://adaptive-images.com/">Adaptive Images</a>. Even <a href="http://www.sencha.com/products/io/">Sencha.IO</a> requires prefixing the src attribute which may not be possible with legacy content.</p>
<h3>Do I care about semantics?</h3>
<p>Some responsive images techniques involve markup which isn't strictly semantic. Ultimately, there is only one way an image can be semantic. That is if the <code>src</code> of it points to a real image and it has <code>alt</code> text describing that image. Brad Frost sums it up nicely:</p>
<blockquote class="twitter-tweet" data-in-reply-to="188023663029796866"><p>@<a href="https://twitter.com/stowball">stowball</a> Unfortunately its not that simple. A picture of a horse needs to be a picture of a horse or else its not a picture of a horse. :)</p>
<p>&mdash; Brad Frost (@brad_frost) <a href="https://twitter.com/brad_frost/status/188024708866912257" data-datetime="2012-04-05T22:05:58+00:00">April 5, 2012</a></p></blockquote>
<p><script src="//platform.twitter.com/widgets.js" charset="utf-8"></script></p>
<p>In other words, if the technique requires at any point the <code>src</code> of the image to be missing or link to a transparent GIF (or the like), that's not semantic. </p>
<p>So why do some responsive images techniques do this? Because having an image with a <code>src</code> that points to that image of a horse means that that image will start downloading as soon as that image gets parsed by the browser. There is no practical way to prevent this. Even if you <em>super quickly</em> swap out that <code>src</code> with a more appropriate version, now you're downloading two images instead of one which is a performance hit instead of a performance gain. You may decide that's acceptable (e.g. "desktop" environments typically have more bandwidth). Usually if this technique is employed, the image in the <code>src</code> is the smallest possible image.</p>
<p>If semantics is important to you, you should look at <a href="http://adaptive-images.com/">Adaptive Images</a> (covered above) or <a href="https://github.com/teleject/hisrc">HiSRC</a>, a plugin by Christopher Schmitt which you can use with a semantic <code>src</code> attribute. </p>
<p>A few of the techniques use <code>&lt;noscript&gt;</code> tags in which to place a fallback <code>&lt;img&gt;</code> in the case of no JavaScript being available. I'll let you decide if that's semantic or not.</p>
<h3>Do I care about validity?</h3>
<p>Validity as in "Does it validate?" according to the <a href="http://validator.w3.org/">W3C Markup Validation Service</a>. Validation is a tool to help you find problems and write better markup. But just because something doesn't validate doesn't make it bad or wrong. If invalid code works wonderfully in all browsers, you nor anyone else should care.</p>
<p>If you do care about validity (perhaps a client irrationally requires it from you and is holding your paycheck randsom) then there are a few techniques that you can't use. The <a href="https://github.com/scottjehl/picturefill">picturefill</a> technique, for instance, uses the <code>&lt;picture&gt;</code> element to work its magic. This may ultimately be standarized, but it isn't yet, so it's technically invalid syntax. It's also required that <code>&lt;img&gt;</code> elements have a <code>src</code> attribute, so techniques that remove that to get around the double-image-request problem are invalid.</p>
<p>I'd recommend these techniques if validity is a requirement for you: <a href="http://adaptive-images.com/">Adaptive Images</a>, <a href="https://github.com/teleject/hisrc">HiSRC</a>, or <a href="https://github.com/joshje/Responsive-Enhance">Responsive Enhance</a>. All of which use simple, valid <code>&lt;img&gt;</code> syntax that include a <code>src</code>.</p>
<h3>Do I care about art direction?</h3>
<p>Some responsive images techniques serve different resolution versions of the exact same image. While that makes things easier (i.e. less work) it may not acceptable. Here's a visual example:</p>
<figure><img src="http://cdn.css-tricks.com/wp-content/uploads/2012/05/difimages.jpg" alt="" title="difimages" width="922" height="360" class="alignnone size-full wp-image-16963" /></p>
<figcaption>On the left, the "mobile" and default <code>src</code>. In the middle, a slightly larger image that could be used on (ahem) "tablets". On the right, the largest of the images.<a href="http://www.flickr.com/photos/whitehouse/7136874959/sizes/l/in/photostream/">(credit)</a></figcaption>
</figure>
<p>These images are hand-crafted by a designer, cropped to retain meaning and impact. If you took the image on the right and just scaled it down, the people in the image would be very small and the feel of the image my be lost. </p>
<p>If this idea of art direction is important to your project, you'll need a technique that will allow you to specify exactly which src to serve under which circumstances. This is picture perfect (GET IT?) for <a href="https://github.com/scottjehl/picturefill">picturefill</a> which allows you to be very specific about sources and what circumstances get what.</p>
<pre rel="HTML"><code>&lt;picture alt="description"&gt;
  &lt;source src="small.jpg"&gt;
  &lt;source src="medium.jpg" media="(min-width: 400px)"&gt;
  &lt;source src="large.jpg" media="(min-width: 800px)"&gt;
&lt;/picture&gt;</code></pre>
<p>JavaScript takes it from there. </p>
<h3>Do I care about JavaScript?</h3>
<p>Most of these responsive image techniques utilize JavaScript to work their magic. <a href="http://adaptive-images.com/">Some</a> only a tiny bit to set a cookie, but JavaScript none the less. Some of them have you put an <code>&lt;img&gt;</code> in a <code>&lt;noscript&gt;</code> tag so that there is a fallback image in the case that the user has JavaScript turned off. If you don't like that, and you need to make absolutely sure that your images work without JavaScript, <a href="http://www.sencha.com/products/io">Sencha.IO</a> is your best bet. This service works by identifying your device through it's <a href="http://en.wikipedia.org/wiki/User_agent">User Agent</a> string and serving an appropriately sized image. So you link to the largest (reasonable) version you have of it and Sencha will squeeze it down and server smaller versions if need be (it doesn't scale up, for obvious reasons). </p>
<h4>What about JavaScript *library* dependency?</h4>
<p><a href="https://github.com/teleject/hisrc">HiSRC</a> and <a href="https://github.com/stowball/jQuery-rwdImages">rwdImages</a> are both jQuery dependent. If your project is using a different library, these probably aren't for you. But hey, you could port it and open source that! If you aren't using a library, well, you probably should be but let's not get into that.</p>
<h3>Do I care about Server Side Components?</h3>
<p>Some of these techniques aren't solely JavaScript dependent. <a href="http://adaptive-images.com/">Adaptive Images</a> works it's magic primarily through .htaccess and PHP. Well, .htaccess presupposes an Apache server. And, while of course we all know and love PHP (ahem), many websites run on technologies like Ruby or Python. </p>
<p><a href="https://github.com/filamentgroup/Responsive-Images">Responsive Images</a> (the original Filament Group technique) also uses .htaccess. So if you're using something like <a href="http://wiki.nginx.org/Main">Nginx</a> as web server, this is either out or you'll have to port over the .htaccess component to Nginx's similar-but-different syntax.  </p>
<h3>Do I care about bandwidth testing?</h3>
<p>Testing the browser window width and making decisions on what image to serve based on that is pretty cool and fundamental to the concept of responsive images. But it's really only half of what the decision of what image should be served should be based on. The other half is available bandwidth. If the user has a very fast internet connection speed, serving large images is OK. If the user has a very slow internet connection speed, they should get smaller images (regardless of screens size). Unfortunately native <a href="http://css-tricks.com/bandwidth-media-queries/">bandwidth media queries</a> don't exist. </p>
<p>Two of the current techniques do bandwidth testing as part of their decision making: <a href="https://github.com/adamdbradley/foresight.js">Foresight.js</a> and <a href="https://github.com/teleject/hisrc">HiSRC</a> (both are based on the technique in Foresight.js). It works by downloading a test file and measuring how long it took (configurable). The test itself is a slight performance hit, but theoretically the savings gained by serving images based on knowing the current bandwidth is a net (GET IT?) gain. </p>
<h3>Do I care about relying on third parties?</h3>
<p><a href="http://www.sencha.com/products/io/">Sencha.IO</a> is a completely third-party way of handling responsive images. As far as I know, it works great and hasn't been inflicted with any major downtime, but of course you always run that risk.</p>
<p>You might be thinking: <em>Wow, the Sencha.IO technique is really cool but I worry about the third-party dependency. I wish I could run that on my own server.</em> If you want to go down that road, there is the public <a href="http://wurfl.sourceforge.net/">WURFL database</a> and this <a href="https://github.com/carsonmcdonald/ServerSideResponsiveImageExample">Server Side Responsive Images technique</a> which puts that to work locally.</p>
<p>There are also third-party services like <a href="http://deviceatlas.com/products/cloud">Device Atlas Cloud</a> which does device detection for you. It's also a third-party dependency for your app. No doubt their goal and focus is staying up and fast at all times, but you have to be very careful about who and what you rely on for your business.</p>
<h3>Is there a specific CMS with specific CMS powers involved?</h3>
<p>Say your project is in WordPress. WordPress has a media uploader built in. When you upload an image with it, it can create multiple versions (scaling down) of that image for you. That's pretty cool and powerful and you could/should take advantage of that. Keir Whitaker talks about using that ability in his article <a href="http://viewportindustries.com/blog/automatic-responsive-images-in-wordpress/">Automatic Responsive Images in WordPress</a>.</p>
<p>This isn't just a WordPress thing though. I'm sure the concepts at work here could be done (or made to be done) in any Content Management System.</p>
<h3>Can I wait for the future?</h3>
<p>The release of the "new iPad" (the third one, for longevity) is what sparked a lot of these techniques and conversations. Its high pixel density is great for vectors and big photos, but actually not great for things like small icons that need to be scaled up to be the correct size and can be blurry. But serving higher resolution icons means larger file sizes and slower websites. Hence, the need to only serve them in situations/environments that need them. </p>
<p>The world of web standards is aware of this problem. There is a <a href="http://www.w3.org/community/respimg/">whole group</a> dedicated to talking about it. In time, they may solve it and then we can start using whatever way they come up with (assuming its awesome and better than what we have now).</p>
<p>It may be flipping out the src of images <a href="http://nicolasgallagher.com/responsive-images-using-css3/">through CSS content</a> like Nicolas Gallagher suggested. It might be the <code>&lt;picture&gt;</code> element. It might be a <a href="http://robertnyman.com/2011/05/30/discussing-alternatives-for-various-sizes-of-the-same-image-introducing-src-property-in-css-as-an-option/">srclist attribute in HTML or src property in CSS</a>. It might be a <a href="http://blog.yoav.ws/2011/05/My-take-on-adaptive-images">prefix</a>.</p>
<p>&nbsp;</p>
<h3>More resources</h3>
<ul>
<li>Jason Grigsby has an epic three-part series on responsive images <a href="http://blog.cloudfour.com/responsive-imgs/">starting here</a>.</li>
<li>Christopher Schmitt's <a href="http://www.slideshare.net/teleject/convergese-adaptiveimagesconverge-se">slides on a whole talk</a> about responsive images.</li>
<li>Mat Marquis on <a href="http://www.alistapart.com/articles/responsive-images-how-they-almost-worked-and-what-we-need/">Responsive Images: How they Almost Worked and What We Need</a></li>
</ul>
<p><a href="http://css-tricks.com/which-responsive-images-solution-should-you-use/">Which responsive images solution should you use?</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></content:encoded>
			<wfw:commentRss>http://css-tricks.com/which-responsive-images-solution-should-you-use/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>Opt-in Typography</title>
		<link>http://css-tricks.com/opt-in-typography/</link>
		<comments>http://css-tricks.com/opt-in-typography/#comments</comments>
		<pubDate>Mon, 07 May 2012 15:19:59 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Article]]></category>

		<guid isPermaLink="false">http://css-tricks.com/?p=16941</guid>
		<description><![CDATA[<p><p>I recently heard <a href="http://chriseppstein.github.com/">Chris Eppstein</a> give a talk (<a href="http://speakerdeck.com/u/chriseppstein/p/help-my-stylesheets-are-a-mess">slides</a>) about creating better stylesheets and using <a href="http://sass-lang.com/">SASS</a> to do it. There were a couple of surprising bits in there, one of which was about "opt-in typography." The idea was that instead of setting global styles for typographic elements like <code>p</code>, <code>ul</code>, <code>ol</code>, <code>h1</code>, <code>h2</code>, etc that you would instead apply those styles as a class, perhaps <code>.text</code>. </p>
<p>The idea is that there is &#8230;</p></p><p><a href="http://css-tricks.com/opt-in-typography/">Opt-in Typography</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></description>
			<content:encoded><![CDATA[<p>I recently heard <a href="http://chriseppstein.github.com/">Chris Eppstein</a> give a talk (<a href="http://speakerdeck.com/u/chriseppstein/p/help-my-stylesheets-are-a-mess">slides</a>) about creating better stylesheets and using <a href="http://sass-lang.com/">SASS</a> to do it. There were a couple of surprising bits in there, one of which was about "opt-in typography." The idea was that instead of setting global styles for typographic elements like <code>p</code>, <code>ul</code>, <code>ol</code>, <code>h1</code>, <code>h2</code>, etc that you would instead apply those styles as a class, perhaps <code>.text</code>. <span id="more-16941"></span></p>
<p>The idea is that there is a lot of places on a website where you want a clean slate to work from and not be worried about what global styles are doing. The classic example is lists, where when using them for things like navigation you likely don't want the same margin/padding/list-style as you would within an article.</p>
<p>Further, you might have different sets of typographic styles you may want to apply at will. So, instead of global styles like this:</p>
<pre rel="CSS"><code>p  {    }
ul {    }
ol {    }
h1 {    }
h2 {    }
/* etc */</code></pre>
<p>You would scope them to a class instead (using SCSS here):</p>
<pre rel="SCSS"><code>.text-article {
  p  {    }
  ul {    }
  ol {    }
  h1 {    }
  h2 {    }
  /* etc */
}

.text-module {
  p  {    }
  ul {    }
  ol {    }
  h1 {    }
  h2 {    }
  /* etc */
}</code></pre>
<p>In an area of the site that's a blog post, you can snag your article typography, and in a sidebar module, you can grab the typography for that:</p>
<pre rel="HTML"><code>&lt;section class="main-content"&gt;
  &lt;article class="text-article"&gt;
    ...
  &lt;/article&gt;
&lt;/section&gt;
&lt;aside&gt;
  &lt;div class="module text-module"&gt;
     Texty module
  &lt;/div&gt;
  &lt;div class="module"&gt;
     Module in which typography isn't needed
  &lt;/div&gt;
&lt;/aside&gt;</code></pre>
<p>Anthony Short <a href="http://anthonyshort.me/2012/05/global-typographic-styles-suck">feels the same way</a>. </p>
<p>Of course, the effectiveness of this depends on the website. What kind of site it is and what stage in it's evolution it's in. I suspect it would work better on websites that have a more "modular" architecture and that don't have a huge set of legacy content. I'd be interested in trying it on a fresh project.</p>
<p><a href="http://css-tricks.com/opt-in-typography/">Opt-in Typography</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></content:encoded>
			<wfw:commentRss>http://css-tricks.com/opt-in-typography/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>ShopTalk Episode 17</title>
		<link>http://shoptalkshow.com/episodes/017-rapidfire-4/</link>
		<comments>http://css-tricks.com/shoptalk-show-17/#comments</comments>
		<pubDate>Sun, 06 May 2012 15:01:22 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Link]]></category>

		<guid isPermaLink="false">http://css-tricks.com/?p=16928</guid>
		<description><![CDATA[<p><p>Another RAPIDFIRE show where Dave and I answer as many listener questions as we possibly can. </p>
<p><a href="http://shoptalkshow.com/episodes/017-rapidfire-4/" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://css-tricks.com/shoptalk-show-17/">Permalink</a>&#8230;</p></p><p><a href="http://css-tricks.com/shoptalk-show-17/">ShopTalk Episode 17</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></description>
			<content:encoded><![CDATA[<p>Another RAPIDFIRE show where Dave and I answer as many listener questions as we possibly can. </p>
<p><a href="http://shoptalkshow.com/episodes/017-rapidfire-4/" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://css-tricks.com/shoptalk-show-17/">Permalink</a></p><p><a href="http://css-tricks.com/shoptalk-show-17/">ShopTalk Episode 17</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></content:encoded>
			<wfw:commentRss>http://css-tricks.com/shoptalk-show-17/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autofill City &amp; State from Zip Code with Ziptastic</title>
		<link>http://css-tricks.com/using-ziptastic/</link>
		<comments>http://css-tricks.com/using-ziptastic/#comments</comments>
		<pubDate>Thu, 03 May 2012 17:42:41 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Article]]></category>

		<guid isPermaLink="false">http://css-tricks.com/?p=16909</guid>
		<description><![CDATA[<p><p>Most address fields on web forms ask for city, state, and zip code (or city and post code, outside of the US). But as us nerds often lament, city and state are redundant with zip code. Or at least they can be inferred from a correctly entered zip code. That's the kind of thing computers are good at. What we need is a proper API to cough up that information for us on demand. </p>
<p></p>
<p>Enter <a href="http://daspecster.github.com/ziptastic/index.html">Ziptastic</a>, a free (&#8230;</p></p><p><a href="http://css-tricks.com/using-ziptastic/">Autofill City &#038; State from Zip Code with Ziptastic</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></description>
			<content:encoded><![CDATA[<p>Most address fields on web forms ask for city, state, and zip code (or city and post code, outside of the US). But as us nerds often lament, city and state are redundant with zip code. Or at least they can be inferred from a correctly entered zip code. That's the kind of thing computers are good at. What we need is a proper API to cough up that information for us on demand. </p>
<p><span id="more-16909"></span></p>
<p>Enter <a href="http://daspecster.github.com/ziptastic/index.html">Ziptastic</a>, a free (<a href="https://elevenbasetwo.com/donations/">donations</a> welcome) API for just that.</p>
<p>Let's use it.</p>
<h3>Form Markup</h3>
<p>Five fields. Two for street then city, state, and zip. All wrapped up in a form and fieldset. Nothing special.</p>
<pre rel="HTML"><code>&lt;form action="#" method="post" class="fancy-form"&gt;

  &lt;fieldset&gt;
    &lt;legend&gt;Address&lt;/legend&gt;

    &lt;div&gt;
      &lt;div&gt;
        &lt;input type="text" name="address-line-1" id="address-line-1"&gt;
        &lt;label for="address-line-1"&gt;Street #1&lt;/label&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div&gt;
      &lt;div&gt;
        &lt;input type="text" name="address-line-2" id="address-line-2"&gt;
        &lt;label for="address-line-2"&gt;Street #2&lt;/label&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div&gt;
      &lt;div class="city-wrap"&gt;
        &lt;input type="text" name="city" id="city"&gt;
        &lt;label for="city"&gt;City&lt;/label&gt;
      &lt;/div&gt;
       &lt;div class="state-wrap"&gt;
        &lt;input type="text" name="state" id="state"&gt;
        &lt;label for="state"&gt;State&lt;/label&gt;
      &lt;/div&gt;
       &lt;div class="zip-wrap"&gt;
        &lt;input type="text" pattern="[0-9]*" name="zip" id="zip"&gt;
        &lt;label for="zip"&gt;Zip&lt;/label&gt;
        &lt;p class="zip-error"&gt;Not a real zip code.&lt;/p&gt;
      &lt;/div&gt;
    &lt;/div&gt;

    &lt;div&gt;
      &lt;input type="submit" value="Submit"&gt;
    &lt;/div&gt;

  &lt;/fieldset&gt;

&lt;/form&gt;</code></pre>
<h3>Only show the zip at first</h3>
<p>We'll hide all the divs that wrap each row of form elements. We'll use JavaScript, so that in case the user has JavaScript turned off, the form is still usable.</p>
<pre rel="jQuery"><code>$(".fancy-form div &gt; div").hide();</code></pre>
<p>Then reveal just the zip code.</p>
<pre rel="CSS"><code>form .zip-wrap {
  display: block !important;
}</code></pre>
<h3>Front end validation</h3>
<p>On the front end, we're already doing the best we can to help the proper entry of a zip code through HTML5 input attributes <a href="http://wufoo.com/html5/attributes/10-pattern.html">pattern</a>, <a href="http://wufoo.com/html5/attributes/03-maxlength.html">maxlength</a>, and <a href="http://wufoo.com/html5/attributes/09-required.html">required</a>.</p>
<pre rel="HTML"><code>&lt;input type="text" pattern="[0-9]*" maxlength="5" required name="zip" id="zip"&gt;</code></pre>
<p>Notice it's not of type <code>number</code>. Whenever considering <code>type=number</code>, consider "would I be cool with the browser adding commas inside of this number?" and if it's no, don't use it, because some do.</p>
<h3>jQuery: Watch for entry of valid zip code</h3>
<p>We're going to watch the zip input for keystrokes. Should the final value after a keystroke be a valid zipcode, we'll attempt to get the city and state through Ziptastic and reveal the other fields. </p>
<pre rel="jQuery"><code>$("#zip").keyup(function() {
  var el = $(this);

  if ((el.val().length == 5) &amp;&amp; (is_int(el.val()))) {

    // Make Ajax call, etc

  }

}</code></pre>
<p>The is_int function is just some extra protection that the number is an integer (like all zip codes) in case the current browser doesn't support the necessary HTML5.</p>
<pre rel="JavaScript"><code>function is_int(value){
  if ((parseFloat(value) == parseInt(value)) &amp;&amp; !isNaN(value)) {
      return true;
  } else {
      return false;
  }
}</code></pre>
<h3>jQuery: Ajax the data</h3>
<p>Yeah so jQuery. We used it above to make event handling on the input easier, but it's really need here because of its ability to make ajax calls with error handling sixty two times easier than doing it with vanilla JavaScript.</p>
<p>After the passed validation, we can make the Ajax call. All we give it for data is the zip code we've collected and we get some JSON back which is trivially easy to access the city and state and apply them as values to the appropriate inputs.</p>
<pre rel="jQuery"><code>$.ajax({
  url: "http://zip.elevenbasetwo.com",
  cache: false,
  dataType: "json",
  type: "GET",
  data: "zip=" + el.val(),
  success: function(result, success) {

    $(".fancy-form div &gt; div").slideDown(); /* Show the fields */

    $("#city").val(result.city); /* Fill the data */
    $("#state").val(result.state);

    $(".zip-error").hide(); /* In case they failed once before */

    $("#address-line-1").focus(); /* Put cursor where they need it */

  },
  error: function(result, success) {

    $(".zip-error").show(); /* Ruh row */

  }

});</code></pre>
<p>Of course we can validate all day long for the valid format of zip codes, but not <em>every</em> 5 digit integer is a zip code. Should we ask Ziptastic for a zip code that doesn't exist, it will return an error. In that case we just show an error message. </p>
<h3>Demo and Download</h3>
<p><a href="http://css-tricks.com/examples/Zip/" class="button">View Demo</a> &nbsp; <a href="http://css-tricks.com/examples/Zip.zip" class="button">Download Files</a></p>
<p>Snag the ZIP. GET IT?! <del>Also, if someone wants to apply some actually nice UX and design to this, I'd be happy to update the demo with credit.</del> <ins>Andru Stoicescu at <a href="http://betterhtml.com/">Better &lt;html></a> submitted a bit of a fancier design so I updated to that.</ins></p>
<h3>Notes</h3>
<ul>
<li>I'm not going to tell you this is bulletproof. Addresses are hard. I heard some zip codes cross state lines. </li>
<li><del>Ziptastic is US only.</del> <ins>Just days after publishing this, Ziptastic starts supporting postal codes internationally.</ins> <a href="http://www.zippopotam.us/">Zippopotamus</a> is similar and supports 60 counties.</li>
</ul>
<p><a href="http://css-tricks.com/using-ziptastic/">Autofill City &#038; State from Zip Code with Ziptastic</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></content:encoded>
			<wfw:commentRss>http://css-tricks.com/using-ziptastic/feed/</wfw:commentRss>
		<slash:comments>60</slash:comments>
		</item>
		<item>
		<title>Viewport Sized Typography</title>
		<link>http://css-tricks.com/viewport-sized-typography/</link>
		<comments>http://css-tricks.com/viewport-sized-typography/#comments</comments>
		<pubDate>Tue, 01 May 2012 00:15:31 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Article]]></category>

		<guid isPermaLink="false">http://css-tricks.com/?p=16888</guid>
		<description><![CDATA[<p><p><a href="http://dev.w3.org/csswg/css3-values/#viewport-relative-lengths">CSS3 has some new values</a> for sizing things relative to the current viewport size: <code>vw</code>, <code>vh</code>, and <code>vmin</code>. It is relevant to bring up now, because it's shipping in Chrome 20 (<a href="http://tools.google.com/dlpage/chromesxs">canary</a> at the time of this writing). And not behind a flag, it just works. Production usage isn't quite there, but it will be soon enough.</p>
<p></p>
Why is this awesome?
<p>There are many reasons. Here are two:</p>
<ol>
<li>There is a such thing as a comfortable </li>&#8230;</ol></p><p><a href="http://css-tricks.com/viewport-sized-typography/">Viewport Sized Typography</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://dev.w3.org/csswg/css3-values/#viewport-relative-lengths">CSS3 has some new values</a> for sizing things relative to the current viewport size: <code>vw</code>, <code>vh</code>, and <code>vmin</code>. It is relevant to bring up now, because it's shipping in Chrome 20 (<a href="http://tools.google.com/dlpage/chromesxs">canary</a> at the time of this writing). And not behind a flag, it just works. Production usage isn't quite there, but it will be soon enough.</p>
<p><span id="more-16888"></span></p>
<h3>Why is this awesome?</h3>
<p>There are many reasons. Here are two:</p>
<ol>
<li>There is a such thing as a comfortable line length for reading text on screens. I don't want to kick a hornet's nest, but let's say its around 80 characters. These units allow you to get it feeling perfect and then have that experience scale to any size screen.</li>
<li>They allow you to tightly couple the size relationship of, say, a typographic header and the content it goes with. Like your <a href="http://trentwalton.com/2011/05/10/fit-to-scale/">classic Trent Walton style blog post</a>.</li>
</ol>
<h3>How they work</h3>
<p>One unit on any of the three values is 1% of the viewport axis. "Viewport" == browser window size == window object. If the viewport is 40cm wide, 1vw == 0.4cm. </p>
<p>For use with <code>font-size</code>, I guess it's one "letter" that takes on that size, but as we know, in non-mono-spaced fonts the width of a letter is rather arbitrary. I find you just need to tweak around with the values to get it how you want it. Which is basically what we do anyway, right?</p>
<p>1vw = 1% of viewport width<br />
1vh = 1% of viewport height<br />
1vmin = 1vw or 1vh, whichever is smaller</p>
<h3>Using them</h3>
<p>Easy cheezy:</p>
<pre rel="CSS"><code>h1 {
  font-size: 5.9vw;
}
h2 {
  font-size: 3.0vh;
}
p {
  font-size: 2vmin;
}</code></pre>
<h3>Demo</h3>
<p>Here's a video of <a href="http://css-tricks.com/examples/ViewportTypography/">a simple layout</a> using vw units so the typography.</p>
<p><iframe width="640" height="360" src="http://www.youtube.com/embed/AUiVLIDoGuc" frameborder="0" allowfullscreen></iframe></p>
<p>Check out <a href="http://css-tricks.com/examples/ViewportTypography/">the demo</a> yourself (see browser support).</p>
<h3>Bugs!</h3>
<p>The support is there in Chrome 20, but it fails in one rather significant way. When the browser window is resized, the font doesn't adjust itself according to the new viewport size. The spec says:</p>
<blockquote><p>When the height or width of the viewport is changed, they are scaled accordingly.</p></blockquote>
<p>I <a href="http://code.google.com/p/chromium/issues/detail?id=124331">bugged it</a>. Perhaps not a huge disaster as it's pretty much just us design nerds that go around adjusting browser windows, but still. The font does adjust on a fresh page load. </p>
<p>To fix this issue (allow resizing without page refresh) you need to cause a "repaint" on the element. I used <a href="http://jquery.com/">jQuery</a> and just fiddled with each elements (irrelevant, in this case) <code>z-index</code> value, which triggers the repaint.</p>
<pre rel="jQuery"><code>causeRepaintsOn = $("h1, h2, h3, p");

$(window).resize(function() {
	causeRepaintsOn.css("z-index", 1);
});</code></pre>
<h3>Browser Support</h3>
<p>Chrome 20+ &#038; IE 10+ </p>
<p>I tried Opera Next (12), Safari 5.2, and Firefox Beta (13) and no dice. </p>
<h3>Not just font-size</h3>
<p>For the record, these are just units. Just like <code>em</code>, <code>px</code>, whatever. You can use them on anything, not just <code>font-size</code>.</p>
<p>I think <code>font-size</code> is the most compelling use case, since things like margin, padding, and width can already essentially react to browser window size by using % units. There is the case where perhaps a more deeply-nested element needs to react to the browser window size instead of its direct parent size.</p>
<h3>Using it now</h3>
<h4>Native usage</h4>
<p>You'll at least want to provide a fallback:</p>
<pre rel="CSS"><code>h1 {
  font-size: 36px; /* Some tweener fallback that doesn't look awful */
  font-size: 5.4vw;
}</code></pre>
<h4>Testing for support</h4>
<p><a href="http://modernizr.com/">Modernizr</a> doesn't have a test for it <a href="https://github.com/Modernizr/Modernizr/issues/572">yet</a>, but you can test for it yourself by using some throw-away element that you see to some narrow width in CSS but then re-set to 100vw in JavaScript, then measure to see if the width of it is equal to window.width. Something like:</p>
<pre rel="jQuery"><code>var testEl = $("#vw-test");

var viewport = $(window);

testEl.css({
  width: "100vw"
});

if (testEl.width() == viewport.width()) {
   $("html").addClass("vw-support");
} else {
   $("html").append("vw-unsupported");
};</code></pre>
<h4>Mimic the functionality with FitText.js</h4>
<p>This idea of binding the overall width of a header with the width of its parent element is exactly what <a href="http://fittextjs.com/">FitText.js</a> does. Only it does it through fancy JavaScript and math and spans and stuff. Theoretically, you could run the test and use <a href="http://modernizr.com/docs/#load">Modernizr.load</a> to load up FitText.js if no support is detected.</p>
<h3>So yeah</h3>
<p>What do you think? Are you into it? Got some ideas on how to use it?</p>
<p><a href="http://css-tricks.com/viewport-sized-typography/">Viewport Sized Typography</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></content:encoded>
			<wfw:commentRss>http://css-tricks.com/viewport-sized-typography/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>ShopTalk Episode 16</title>
		<link>http://shoptalkshow.com/episodes/016-with-ian-stewart/</link>
		<comments>http://css-tricks.com/shoptalk-episode-16/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 00:06:59 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Link]]></category>

		<guid isPermaLink="false">http://css-tricks.com/?p=16884</guid>
		<description><![CDATA[<p><p>Dave and I were joined by Ian Stewart, a Theme Wrangler at Automattic for WordPress.com (he's probably thinking about WordPress themes right this very minute). We talked about WordPress multisite, training clients in WordPress, database syncing, team productivity, and more.</p>
<p><a href="http://shoptalkshow.com/episodes/016-with-ian-stewart/" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://css-tricks.com/shoptalk-episode-16/">Permalink</a>&#8230;</p></p><p><a href="http://css-tricks.com/shoptalk-episode-16/">ShopTalk Episode 16</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></description>
			<content:encoded><![CDATA[<p>Dave and I were joined by Ian Stewart, a Theme Wrangler at Automattic for WordPress.com (he's probably thinking about WordPress themes right this very minute). We talked about WordPress multisite, training clients in WordPress, database syncing, team productivity, and more.</p>
<p><a href="http://shoptalkshow.com/episodes/016-with-ian-stewart/" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://css-tricks.com/shoptalk-episode-16/">Permalink</a></p><p><a href="http://css-tricks.com/shoptalk-episode-16/">ShopTalk Episode 16</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></content:encoded>
			<wfw:commentRss>http://css-tricks.com/shoptalk-episode-16/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conditional Content via CSS Media Queries</title>
		<link>http://adactio.com/journal/5429/</link>
		<comments>http://css-tricks.com/conditional-content-via-css-media-queries/#comments</comments>
		<pubDate>Sun, 29 Apr 2012 19:48:25 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Link]]></category>

		<guid isPermaLink="false">http://css-tricks.com/?p=16872</guid>
		<description><![CDATA[<p><p>Jeremy Keith has a great article on his journey to allowing JavaScript to load in content based on the currently active media query. This allows you to keep media queries only in the CSS (DRY!). </p>
<p>The article was sans-demo, so <a href="http://css-tricks.com/examples/ConditionalCSS/">I made one</a>.</p>
<p><a href="http://adactio.com/journal/5429/" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://css-tricks.com/conditional-content-via-css-media-queries/">Permalink</a>&#8230;</p></p><p><a href="http://css-tricks.com/conditional-content-via-css-media-queries/">Conditional Content via CSS Media Queries</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></description>
			<content:encoded><![CDATA[<p>Jeremy Keith has a great article on his journey to allowing JavaScript to load in content based on the currently active media query. This allows you to keep media queries only in the CSS (DRY!). </p>
<p>The article was sans-demo, so <a href="http://css-tricks.com/examples/ConditionalCSS/">I made one</a>.</p>
<p><a href="http://adactio.com/journal/5429/" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://css-tricks.com/conditional-content-via-css-media-queries/">Permalink</a></p><p><a href="http://css-tricks.com/conditional-content-via-css-media-queries/">Conditional Content via CSS Media Queries</a> is a post from <a href="http://css-tricks.com">CSS-Tricks</a></p>]]></content:encoded>
			<wfw:commentRss>http://css-tricks.com/conditional-content-via-css-media-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss><!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced
Database Caching 1/45 queries in 0.040 seconds using apc
Object Caching 1537/1630 objects using apc
Content Delivery Network via cdn.css-tricks.com

Served from: css-tricks.com @ 2012-05-21 10:12:52 -->

