I’m Dudley Storey, the author of Pro CSS3 Animation. This is my blog, where I talk about web design and development with , and . To receive more information, including news, updates, and tips, you should follow me on Twitter or add me on Google+.

web developer guide

my books

Book cover of Pro CSS3 AnimationPro CSS3 Animation, Apress, 2013

my other blogs

Massive Head Canon: Intelligent discussion of movies, books, games, and technology.

my projects

A Sass color keyword system for designers. Replaces CSS defaults with improved hues and more memorable, relevant color names.

CSSslidy: an auto-generated #RWD image slider. 3.8K of JS, no JQuery. Drop in images, add a line of CSS. Done.

tipster.ioAutomatically provides local tipping customs and percentages for services anywhere.

Gentleman wearing a steampunk gasmask and top hatGentleman wearing a steampunk gasmask and top hat

Sepia-toning photographs with CSS

css / filters

Estimated reading time: 1 minute, 13 seconds

Previously I’ve discussed the concept of CSS filters, and stepped you through converting an image to black and white using CSS, without needing to create a new version. We can use the same approach to sepia-tone an image for an old-timey photographic effect.

The HTML for this example is an image with an attached class:

<img src="steampunk-man-in-gasmask.jpg" alt="Gentleman wearing a steampunk gasmask and top hat" class="sepia">

Using a CSS filter is the easiest approach:

img.sepia { -webkit-filter: sepia(1); -webkit-filter: sepia(100%);  filter: sepia(100%); }

That covers Chrome 18+, Firefox 35+, Safari 6+, Opera 15+ and the latest versions of all other mobile browsers. To cover earlier versions of Firefox, we write a separate filter:

<svg version="1.1" xmlns="">
<filter id="old-timey">
<feColorMatrix values="0.14 0.45 0.05 0 0
0.12 0.39 0.04 0 0
0.08 0.28 0.03 0 0
0 0 0 1 0" />

Saving this code as a file with the name sepia.svg allows us to reference it in our CSS:

filter: url(sepia.svg#old-timey);
-webkit-filter: sepia(1);
-webkit-filter: sepia(100%);
filter: sepia(100%);

Unfortunately there’s currently no explicit sepia filter for Internet Explorer, so we must fake it by placing a sepia color behind the image and making the image slightly transparent while restricting these changes to IE 9 and earlier (as I've discussed in previous articles, IE 10 and 11 are currently in an impossible situation regarding CSS filters):

img.sepia {
filter: url(sepia.svg#old-timey);
-webkit-filter: sepia(1);
-webkit-filter: sepia(100%);
filter: sepia(100%);
background-color: #5E2612;
filter: alpha(opacity = 50);

Next, we’ll look at blurring images.

Photograph by Daniel Proulx, licensed under Creative Commons. Play with this code on CodePen.

comments powered by Disqus

This site helps millions of visitors while remaining ad-free. For less than the price of a cup of coffee, you can help pay for bandwidth and server costs while encouraging further articles.