Using CSS instead of images when coding your web design

DZone 's Guide to

Using CSS instead of images when coding your web design

· Web Dev Zone ·
Free Resource

As an Interface Developer, it has always been a challenge to make the designers’ dreams come true, especially when it comes to shadows, gradients and various level of transparency. Slicing images till no end, trying to make it look good. Nowadays, though, a nice alternative is to do it with CSS.

The issues with images

First, there are a number of issues with using images in design that I’d like to bring up:

File size

The file size for images is very often the major part of the download size of a web site, and usually only one or a few images’ file size is more than the entire code for a page. This naturally affects download and rendering time negatively.


Usually in teams, most developers don’t have Photoshop (or a similar tool) and/or not the necessary skills, and very often the designer has moved on to other things and don’t have the time to help out with changes. It also takes a lot more time to edit an image than changing a few characters in a CSS file.


One of the biggest threats when it comes to the performance of a web site is the number of HTTP request it has, and each extra request is lost rendering time. Files have to be compared, header information about the files has to be checked, modified dates compared etc. Imagine cutting down on all of this by just writing plain CSS code instead.

Where CSS steps in

Naturally, what you’d want to be able to do is offer the effects from the design with CSS code, and that it works in all major web browsers (Internet Explorer, Firefox, Google Chrome, Safari & Opera). I have described the options to use CSS instead of images in a number of blog posts:

Rounded corners with CSS

Then we have other things like rounded corners, where progressive enhancement steps into place: capable web browsers get rounded corners where the others get square content (the progressive enhancement approach could also apply to shadows, gradients and transparency). The way to achieve rounded corners with CSS looks like this:

.rounded-corners {
-moz-border-radius: 5px; /* Firefox */
-webkit-border-radius: 5px; /* Safari, Google Chrome */
border-radius: 5px; /* Internet Explorer 9, Opera 10.5+, dev channel releases of Google Chrome */

Possible downsides

Potential issues with using CSS lie, “surprisingly”, with Internet Explorer when we bring in filters to achieve what we want. At times, filters work just fine, but there are situations where it could affect performance negatively. Filters can also remove ClearType from fonts and they need block element or hasLayout fixes to be rendered properly.

So, proceed with caution and test in your specific use cases.

Evaluate your situation

Of course I don’t believe CSS is the solution to every design on the web and that I think no images should ever be used again. But what I’m advocating is to consider CSS an option for the design of parts of your web site, because for file size, maintenance and performance reasons, things can get drastically better, and more fun to work with at the same time! :-)


Published at DZone with permission of Robert Nyman , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}