Skip to content

Instantly share code, notes, and snippets.

@bjankord
Created April 27, 2012 14:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bjankord/2509534 to your computer and use it in GitHub Desktop.
Save bjankord/2509534 to your computer and use it in GitHub Desktop.
Picture element markup for high-resolution devices with polyfill markup for older browsers
<picture alt="Alt tag describing the image represented">
<!--<source src="photo-s.jpg"/>-->
<source src="photo-s.jpg"/>
<source src="photo-s@2x.jpg" media="-webkit-min-device-pixel-ratio:2, min-resolution:192dpi"/>
<!--<source src="photo-m.jpg" media="min-width:321px"/>-->
<source src="photo-m.jpg" media="min-width:321px"/>
<source src="photo-m@2x.jpg" media="min-width:321px and -webkit-min-device-pixel-ratio:2, min-resolution:192dpi"/>
<!--<source src="photo-l.jpg" media="min-width:641px"/>-->
<source src="photo-l.jpg" media="min-width:641px"/>
<source src="photo-l@2x.jpg" media="min-width:641px and -webkit-min-device-pixel-ratio:2, min-resolution:192dpi"/>
<!--<source src="photo-xl.jpg" media="min-width:1281px" />-->
<source src="photo-xl.jpg" media="min-width:1281px" />
<source src="photo-xl@2x.jpg" media="min-width:1281px and -webkit-min-device-pixel-ratio:2, min-resolution:192dpi" />
<noscript><img src="photo-s.jpg" /></noscript>
</picture>
//Notes
//--------------------------------------------------
Markup based off of Scott Jehl's picturefill example.
Added commented source elements (needed for IE9, Android 2.1-2.3 and iOS 4.3 Safari)
to demonstrate how a real life cross-browser implementation might look like.
15 lines of code for "1" image :(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment