Skip to content

Instantly share code, notes, and snippets.

@jakearchibald
Created February 12, 2013 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakearchibald/2f6baeeefd0eee59d9ec to your computer and use it in GitHub Desktop.
Save jakearchibald/2f6baeeefd0eee59d9ec to your computer and use it in GitHub Desktop.
.whatever {
/* Falling back from webp to png */
background-image: image("whatever.webp" format('webp'), "whatever.jpg");
/* Falling back from webp to png with image-set dpi negotiation */
background-image: image(
image-set("whatever.webp" 1x, "whatever-2x.webp" 2x) format('webp'),
image-set("whatever.png" 1x, "whatever-2x.png" 2x)
);
}
/* Here's an alternative I don't like as much, using the fragment for format info */
.whatever {
background-image: image("whatever.webp#format=webp", "whatever.jpg");
/* The format repetition in the image-set doesn't fit so well */
background-image: image(
image-set("whatever.webp#format=webp" 1x, "whatever-2x.webp#format=web" 2x),
image-set("whatever.png" 1x, "whatever-2x.png" 2x)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment