Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Designing the Hi-DPI Web

David Demaree
October 06, 2012

Designing the Hi-DPI Web

On optimizing web sites and apps for next-generation displays and the post-pixel future. Presented at ChicagoWebConf 2012 at 1871 in Chicago, IL.

David Demaree

October 06, 2012
Tweet

More Decks by David Demaree

Other Decks in Design

Transcript

  1. Scaling factor Ratio of screen pixels to CSS pixels on

    a single dimension height: 2px width: 2px CSS Standard (1x) Android ‘hdpi’ (1.5x) ‘Retina’/ ‘xhdpi’ (2x)
  2. height: 2px width: 2px CSS There is no such thing

    as half a screen pixel, therefore artwork is blended/scaled on Android
  3. CSS & web fonts where possible SVG or icon fonts

    where appropriate HI-DPI RULES OF THUMB
  4. CSS & web fonts where possible SVG or icon fonts

    where appropriate Responsive images as needed HI-DPI RULES OF THUMB
  5. CSS3 colors (rgba, hsla) 9+ ✓ ✓ ✓ ✓ ✓

    ✓ Border radius 9+ ✓ ✓ ✓ ✓ ✓ ✓ Multiple backgrounds 9+ ✓ ✓ ✓ ✓ ✓ ✓ Box shadow 9+ ✓ ✓ ✓ ✓ ✓ ✓ 2D/3D transforms 9+ ✓ ✓ ✓ ✓ ✓ 2D only Text shadow 10+ ✓ ✓ ✓ ✓ ✓ ✓ Gradients 10+ ✓ ✓ ✓ ✓ ✓ ✓ Border images ✓ ✓ ✓ ✓ ✓ ✓ Text stroke ✓ ✓ ✓ ✓ Masks ✓ ✓ ✓ ✓ iOS CSS3 Browser Support
  6. .navigation-bar { background-color: #04aef4; background-image: -webkit-gradient(linear, left top, left bottom,

    color-stop(0%, #04aef4), color-stop(100%, #048ac2)); background-image: -webkit-linear-gradient(top, #04aef4, #048ac2); background-image: -moz-linear-gradient(top, #04aef4, #048ac2); background-image: -ms-linear-gradient(top, #04aef4, #048ac2); background-image: -o-linear-gradient(top, #04aef4, #048ac2); background-image: linear-gradient(top, #04aef4, #048ac2); color: white; border-bottom: 1px solid #ccc; display: table; width: 100%; } Vendor prefixes You hate ‘em, right?
  7. #linear-gradient { @include background-image(linear-gradient(left top, white, #dddddd)); } SASS +

    COMPASS #linear-gradient { background-image: -webkit-gradient(linear, 0% 0%, 100% 100%, color- stop(0%, #ffffff), color-stop(100%, #dddddd)); background-image: -webkit-linear-gradient(left top, #ffffff, #dddddd); background-image: -moz-linear-gradient(left top, #ffffff, #dddddd); background-image: -o-linear-gradient(left top, #ffffff, #dddddd); background-image: linear-gradient(left top, #ffffff, #dddddd); } COMPILES TO CSS
  8. Hundreds of commercial typefaces Licensing + CDN hosting included Unlimited

    websites + 500,000 pageviews for $49/yr Also included with Adobe Creative Cloud membership
  9. New free font service powered by Typekit technology Hundreds of

    free/open-source fonts, including Cooper Black No signup required Integrated into Edge Tools & Services Adobe Edge Web Fonts
  10. ⚠  ▻ ☁      ⬇

    ␡ Icon glyphs from SS Standard & SS Social by Symbolset
  11. <!-- Look, ma, no extra markup --> <div class="blank-slate"> <h2>No

    expenses found</h2> <p>Try another category, perhaps?</p> </div> .blank-slate:before { color: #999; content: '\1F4E5'; /* Unicode code point */ display: block; font-family: 'SSStandard'; /* Icon font */ font-size: 300%; }
  12.  Single color only font-family: ‘SSSocial’ content: ‘flickr’ Flickr’s actual

    logo is rendered in 2 colors, which icon fonts don’t support
  13. Accessibility Generated content is invisible to search engines, but not

    to assistive devices Inbox <span class="ss-icon ss-inbox"></span> Inbox
  14. Accessibility Generated content is invisible to search engines, but not

    to assistive devices Inbox <span class="ss-icon ss-inbox"></span> Inbox This will be read by VoiceOver on iOS as: “Inbox Tray, Inbox.”
  15. SVG

  16. iOS 9–10 4.0 SVG browser support 2-3 7-8 ✓ ␡

    These browsers/devices will see no image, or else will need a bitmap fallback
  17. #logo { /* 1x PNG for IE 7-8/Android 2-3 */

    background-image: url('/assets/logo.png'); /* SVG for everyone else */ background-image: url('/assets/logo.svg'); }
  18. <picture> <source srcset="small-1.jpg 1x, small-2.jpg 2x"> <source media="(min-width: 18em)" srcset="med-1.jpg

    1x, med-2.jpg 2x"> <source media="(min-width: 45em)" srcset="large-1.jpg 1x, large-2.jpg 2x"> <!-- fallback for legacy browsers --> <img src="small-1.jpg"> </picture> Proposed <picture> syntax Not implemented by any browser as of Oct 2012
  19. <picture> <source srcset="small-1.jpg 1x, small-2.jpg 2x"> <source media="(min-width: 18em)" srcset="med-1.jpg

    1x, med-2.jpg 2x"> <source media="(min-width: 45em)" srcset="large-1.jpg 1x, large-2.jpg 2x"> <!-- fallback for legacy browsers --> <img src="small-1.jpg"> </picture> Media query syntax Proposed <picture> syntax Not implemented by any browser as of Oct 2012
  20. <picture> <source srcset="small-1.jpg 1x, small-2.jpg 2x"> <source media="(min-width: 18em)" srcset="med-1.jpg

    1x, med-2.jpg 2x"> <source media="(min-width: 45em)" srcset="large-1.jpg 1x, large-2.jpg 2x"> <!-- fallback for legacy browsers --> <img src="small-1.jpg"> </picture> New image set syntax Proposed <picture> syntax Not implemented by any browser as of Oct 2012
  21. <picture> <source srcset="small-1.jpg 1x, small-2.jpg 2x"> <source media="(min-width: 18em)" srcset="med-1.jpg

    1x, med-2.jpg 2x"> <source media="(min-width: 45em)" srcset="large-1.jpg 1x, large-2.jpg 2x"> <!-- fallback for legacy browsers --> <img src="small-1.jpg"> </picture> Proposed <picture> syntax Not implemented by any browser as of Oct 2012
  22. #selector { background-image: url(no-image-set.png); background-image: -webkit-image-set(url(myimage.jpg) 1x, url(myimage-hires.jpg) 2x); /*

    other prefixes for -moz, -o and -ms go here */ } Proposed image-set syntax Available today in Chrome, Safari 6, iOS 6
  23. #logo { background-image: url(/assets/logo.png); background-size: 400px, 200px; } @media screen

    and (-webkit-min-device-pixel-ratio: 1.5) { #logo { background-image: url("/assets/[email protected]"); } } @media queries + background-size
  24. #logo { background-image: url(/assets/logo.png); background-size: 400px, 200px; } @media screen

    and (-webkit-min-device-pixel-ratio: 1.5) { #logo { background-image: url("/assets/[email protected]"); } } @media queries + background-size background-size fixes the image at its 1x size (in CSS pixels), otherwise 2x versions would be twice as large.
  25. #logo { background-image: url(/assets/logo.png); background-size: 400px, 200px; } @media screen

    and (-webkit-min-device-pixel-ratio: 1.5) { #logo { background-image: url("/assets/[email protected]"); } } @media queries + background-size Just like width breakpoints in a responsive grid, media queries establish pixel density breakpoints for replacing 1x images with higher-quality ones
  26. #logo { background-image: url(/assets/logo.png); background-size: 400px, 200px; } @media screen

    and (-webkit-min-device-pixel-ratio: 1.5) { #logo { background-image: url("/assets/[email protected]"); } } @media queries + background-size
  27. @media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (

    min--moz-device-pixel-ratio: 2), only screen and ( -o-min-device-pixel-ratio: 2/1), only screen and ( min-device-pixel-ratio: 2), only screen and ( min-resolution: 192dpi), only screen and ( min-resolution: 2dppx) { /* Retina-specific stuff here */ } It wouldn’t be CSS if there weren’t f$%&ing vendor prefixes
  28. .app-icon { background-image: url(icons.png); } @media screen and (min-device-pixel-ratio: 1.5)

    { .app-icon { background-image: url([email protected]); /* Size of 1x sprite set */ background-size: 750px 144px; } } Responsive CSS sprites
  29. .app-icon.logo { /* All other measurements in CSS px */

    background-position: -648px -90px; width: 82px; } Responsive CSS sprites
  30. // Returns the scaling factor, e.g. 1.5 or 2 if((window.devicePixelRatio

    === undefined ? 1 » : window.devicePixelRatio) > 1) { document.cookie='HTTP_IS_RETINA=1;path=/'; } devicePixelRatio property Available in WebKit browsers + Opera Sets a cookie ‘HTTP_IS_RETINA’ if scaling factor > 1
  31. Changes the src attribute of all <img> tags inside a

    container Uses data attributes to track opt into replacement, track which images have been replaced Loads both 1x and 2x versions, with noticeable “flash of non-Retina content” Naïve JavaScript replacement on Apple.com
  32. Picturefill polyfills the proposed <picture> syntax using <div> elements and

    JavaScript <div data-picture> <div data-src="external/imgs/pie.jpg"></div> <div data-src="external/imgs/[email protected]" data-media="(min-device-pixel-ratio: 1.5)"></div> <div data-src="external/imgs/[email protected]" data-media="(min-device-pixel-ratio: 2)"></div> <!-- Fallback content for non-JS browsers --> <noscript><img src="external/imgs/pie.jpg"></noscript> </div>
  33. Use the most appropriate strategy for each kind of image

    Whenever possible, use CSS Try serving only one resolution
  34. Use the most appropriate strategy for each kind of image

    Whenever possible, use CSS Try serving only one resolution Use Picturefill if true responsive images are needed
  35. DAVID DEMAREE BYE my name WAs ✉  [email protected] @ddemaree

    log.demaree.me typekit.com html.adobe.com