27 February 2008
How to recreate Silverback’s parallax effect
When I was a lad, I remember being wowed by an effect in Sonic the Hedgehog known as parallax scrolling. Moving my little spiky friend to the right caused the foreground to move past the camera to the left faster than the background, creating a faux-3D view of Green Hill Zone.
We can create a similar effect on a web page by fixing semi-transparent background images to different sides of the browser viewport, and at different horizontal percentage positions. In addition to this, blurring some of those images will emulate focus and depth-of-field. The effect can only be seen as the browser window is resized, but I really like the subtlety of this — not everybody will notice it, but it’s like a hidden Easter egg for those who do.
I used this effect with great success on the holding page for Clearleft’s latest project, Silverback.
Upfront about IE6
Frankly, this just ain’t gonna happen in IE6. Although we could use javascript to force the browser to display transparent PNGs, its not suitable for this effect. We could use alpha-transparent GIFs instead, but the lack of anti-aliasing will end up looking terrible. My recommendation is to think about your target audience and the browsers they will likely be using, show this effect to those with Safari, Firefox, Opera, or IE7 and use conditional comments to override it in IE6. In my example below, IE6 users just see a flat background image and are none the wiser.
Choosing a suitable scene
It’s a web page that we’re creating, so as always we should be mindful of file sizes. Because it uses large transparent PNGs this effect isn’t frugal on the bandwidth, and although we’re not going to achieve this in under 100k, we should obviously try to avoid making the total image filesize 500k or more! To avoid large file sizes, we should restrict the height of each layer, or choose a scene which works well with horizontally tiled layers. It’s always a compromise because too much tiling becomes obvious and reduces the impact of the effect.
As you can see from Silverback, hanging vines lend themselves nicely to being split into multiple layers because they are positioned in the foreground, middle distance, and background. You might choose a plane flying through some clouds, or a city-scape with houses and skyscrapers. To use a clich�, the only limit is your imagination … and the fact that you should only use 3 or 4 layers. Any more and the overall file size would be too much of a strain on those with delicate Intertubes.
Your page content will become one layer within the scene, and since even the transparent areas of images can’t be clicked “through”, its best to make your content the foreground element unless your page contains no links or forms. We can fake elements nearer to the “camera” if they don’t overlap the content. I’ll come to that later.
Creating your layers
Looking at the Silverback site, there are three layers of vines (1, 2, 3) plus the main content layer at the front (4). Although all of the vines are technically “behind” the main content layer, the foreground vines look closer to the camera because they’re larger, very blurred, and don’t stretch far enough down the screen to ever dip behind Steve (the gorilla) and shatter that illusion.

The main content of the site will naturally be the focal point of the camera, and in the Silverback example the middle distance layer of vines – which appears to be slightly behind the main content – is left without a blur to give the impression that they’re roughly the same distance from the camera as Steve.
Lastly, the back layer of vines are blurred (though not as much as those in the foreground) and slightly lighter, as if fading away into the misty distance. These vines are flattened onto the green gradient which forms the background of the page – since we don’t need to see anything further into the distance, we can use an opaque JPG instead of a transparent PNG. This saves on file size, and as a result allows us to use an image with larger dimensions for the background if we like.
Creating the parallax
There really is nothing new about the CSS we use to create this effect – it’s just cleverly applied. I will give code examples not because it’s difficult but precisely to show how simple it is.
We wrap the content in a “div” which is centered on the screen using this CSS:
div#content{
margin:0 auto;
width:640px;
}
For the purposes of positioning the other layers we need to think in percentages, so it makes sense to do the same thing here. Centering the content effectively positions it 50% of the way across the screen. As you make the browser window smaller, it moves horizontally at half the speed of the window-edge that you’re pulling around with your mouse.
The background layer of vines is tiled horizontally across the body of the website, and positioned 20% of the way across the screen. Although this doesn’t change how it initially looks, it does change how it behaves – 20% of the width is relative to the screen size, so as you make the window smaller the 20% gets proportionally smaller, giving the illusion that the vines are moving slowly to the left (at a fifth of the speed of your mouse).
body {
background:#d3ff99 url(../images/bg-rear.jpg) 20% 0 repeat-x;
}
The middle distance layer of vines is a tiled transparent PNG background on a “div” wrapped around the content. It needs to appear to be between the content and the background, so we need to choose a percentage between 50% (the content) and 20% (the background). For this example, I’ve chosen 40% to position them closer to the content than the background. When you resize the browser you’ll notice that they move slower than the main content, but not by much.
div#midground{
background: transparent url(../images/bg-mid.png) 40% 0 repeat-x;
margin: 0;
padding: 0;
width: 100%;
}
The enlarged and blurred foreground layer of vines follows the same pattern, but for added fun we position the background beyond the top right of the browser window, at 150% (100% would be fixed to the top right), to make it move faster than the browser resize! This gives the illusion that they’re really close to the camera.
div#foreground{
background: transparent url(../images/bg-front.png) 150% 0 repeat-x;
margin: 0;
padding: 0;
width: 100%;
}
Nothing fancy for IE6
Finally, we use conditional comments to make sure IE6 only sees a flat image with no faux-3D effect. Remember to override the foreground style even if you’re overriding it with nothing, by specifying “background:none”.
body{
background:#d3ff99 url(../images/gradient.gif) 0 0 repeat-x;
}
#midground{
background:transparent url(../images/flatvines.jpg) top center repeat-x;
}
#foreground{
background:none;
}
And that’s it! Feel free to use the source code of the Silverback holding page as an aid to understanding my method. There are a couple of variations to this effect, which I’ll mention now.
Genuine foreground
We can move the empty foreground “div” to the start of the HTML and add the following lines to the “div#foreground” CSS to position it actually in front of the content. Doing this will allow its background image to dip over the content but will also mean that the content can’t be clicked. Only use this if your content contains no links or form elements.
position:absolute;
top:0;
left:0;
z-index:1;
Genuine foreground demo (for the purposes of this demo the content is nearer to the top of the page so that it dips behind the shorter foreground vines).
The Rissington Effect
With hat tipped gratefully in the direction of The Rissington Podcast, I should mention the joys of playing around with negative percentages. Notice that the Spitfire at the bottom of their website cleverly moves off the screen to the left as you widen the browser window. It’s positioned at -5%, and the wider the browser the larger 5% of it is, so the further it moves to the left. In our example, if you set the background layers to have negative percentages you can make the landscape appear to rotate around the content as you resize the browser. The more extreme the percentages, the faster the rotational effect.
My happy ending
With all my designs I like to try to include something remarkable, pushing the boundaries of what can be achieved using just HTML and CSS. This technique, combined with others, opens the door to all sorts of possibilities. I can imagine things hiding behind solid foregrounds and only sliding into view as the browser size exceeds a certain dimensions, or elements fading into view as the browser is resized. Show me what you can do!


We're big fans of 


oyun oyna
# January 17, 2009 - 5:09 pm
bendende thanks efe mucu.
I had some problems with my css. Thanks for the article!
Paul Gonella
# January 20, 2009 - 3:15 am
Hi, thanks loads for the tutorial, I had fun adapting it for a new blog:
http://www.forevercircling.com
I still need to tie up loose ends (and sort out IE6, etc).
Efren Hidalgo
# January 26, 2009 - 3:05 pm
Excellent tut! I am looking forward to implementing your example on some client (or personal blog) soon. Have you seen Dizignus use of parallax headers? a total of five images that move when you scroll your mouse across the top.
Benjamin C
# January 29, 2009 - 7:49 pm
I've always pondered doing something like this with PNG's in a web environment. I have only just begun using PNG elements in my web design and it was very inspiring to see your work. Subtle and effective.
I look forward to seeing more.
Jon
# February 4, 2009 - 9:48 am
Very interesting tutorial. As tutor for a web design course in London (http://www.digitalartscollege.co.uk) I am always interested in teaching students the latest techniques so will recommend they read this post.
Dan the MilK Man
# March 19, 2009 - 12:36 pm
That is totally awesome. I love that effect when you scroll over the header. I'm definitely going to try this myself! Thanks for the great tut.
Are these layers made in photoshop and put into separate div tags inside or on top of eachother? I'm kind of new to Web Design so I'm still kind of learning. Thanks
Velkommen til macbruker.com - martin berglund | webdesigner og macbruker
# May 10, 2009 - 6:58 am
[...] du se en slags parallax effekt om du endrer størrelsen på nettleservinduet. Prinsippet for denne effekten forklares detaljert i en artikkel hos thinkvitamin.com. I tillegg har jeg gjemt en liten effekt, laget med jQuery, et sted i [...]
Don’t forget about :active | StylizedWeb.com
# May 10, 2009 - 6:37 pm
[...] these capabilities are valuable for creating new ways to add creative touches, such as the parallax scrolling effect. Other times they can greatly improve the usability and user experience of our sites. In some cases [...]
Don’t forget about :active | JVC
# May 19, 2009 - 9:29 am
[...] these capabilities are valuable for creating new ways to add creative touches, such as the parallax scrolling effect. Other times they can greatly improve the usability and user experience of our sites. In some cases [...]
Markweee
# May 22, 2009 - 5:39 am
Thank you in writing in the meantimethe tracking of people often do Thank you in writing in the meantimebig join
Philosophy Dissertation
Paul
# May 27, 2009 - 5:35 am
did you mean for div#foreground backgound-position to be: -150%
sohbet
# June 10, 2009 - 9:57 am
thanks admin good post
kız oyunları
# July 16, 2009 - 2:01 pm
I had some problems with my css. Thanks for the article! Aynen game abime katılıyorum :D
5 innovative CSS Techniques You Should Know About « typesett - Your AMUSING Resource for Useful Design, Typography and Web Dev Articles
# August 31, 2009 - 2:50 am
[...] http://carsonified.com/blog/design/how-to-recreate-silverbacks-parallax-effect/ [...]
John Rees
# October 9, 2009 - 10:04 am
Probably the most offensive comment form I have ever seen.
This Week’s Favourites – October 16th 2009
# October 16, 2009 - 7:02 am
[...] parallax scrolling effect on the Silverback website has wowed many viewers, find out how to create your own on the Think [...]
This Week’s Favourites – October 16th 2009 | meshdairy
# October 29, 2009 - 7:46 am
[...] parallax scrolling effect on the Silverback website has wowed many viewers, find out how to create your own on the Think [...]
This Week’s Favourites – October 16th 2009 - MaC Donald
# November 28, 2009 - 4:43 pm
[...] parallax scrolling effect on the Silverback website has wowed many viewers, find out how to create your own on the Think [...]
Jake Lee
# November 30, 2009 - 12:39 pm
Hey thanks loads for the post!
I used the technique here: http://www.readymadedesigns.co.uk
madewithpixels: design | graphics | multimedia
# December 9, 2009 - 3:47 am
[...] Those readers that follow the web-design community closely will have noticed a new trend for parallax backgrounds. There have been a few notable examples recently. The Rissington Podcast and Clearleft’s ‘Silverback‘ to name but two (with an excellent tutorial on how to recreate the effect by Carsonified here). [...]
sukubidu oyunları
# December 11, 2009 - 3:13 am
I have only just begun using PNG elements in my web design and it was very inspiring to see your work. Subtle and effective. I’ve always pondered doing something like this with PNG’s in a web environment.
adana çiçekçi
# December 17, 2009 - 7:20 am
adana çiçekçi
adana çiçekçi
adana çiçekçi
adana çiçekçi
adana çiçekçi
haber
# December 20, 2009 - 2:20 pm
The information you provide for the formation thank
teknoloji
# December 20, 2009 - 3:00 pm
The information you provide for the formation thank
oyun
# December 20, 2009 - 3:01 pm
The information you provide for the formation thank
DVD
# December 22, 2009 - 9:30 am
read through these but the ones
adana çiçekçi
# December 25, 2009 - 7:07 am
adana çiçek siparişi
adana çiçek siparişi
adana çiçek siparişi
adana çiçek siparişi
adana çiçek siparişi
adana çiçekçi
# December 25, 2009 - 7:08 am
adana çiçek sipariş
adana çiçek sipariş
adana çiçek sipariş
adana çiçek sipariş
adana çiçek sipariş
adana çiçekçi
# December 25, 2009 - 7:09 am
adana çiçek gönder
adana çiçek gönder
adana çiçek gönder
adana çiçek gönder
adana çiçek gönder
adana çiçekçi
# December 25, 2009 - 7:09 am
adana çiçek
adana çiçek
adana çiçek
adana çiçek
adana çiçek
adana çiçekçi
# December 25, 2009 - 7:09 am
adana çiçekçi
adana çiçekçi
adana çiçekçi
adana çiçekçi
adana çiçekçi
adana çiçekçi
# December 25, 2009 - 7:10 am
adana çiçekçileri
adana çiçekçileri
adana çiçekçileri
adana çiçekçileri
adana çiçekçileri
adana çiçekçi
# December 25, 2009 - 7:10 am
kadirli çiçekçi
kadirlide çiçekçi
kadirlide çiçekçilik
kadirli çiçek siparişi
kadirli çiçekçileri
adana çiçekçi
# December 25, 2009 - 7:11 am
kadirli çiçek
kadirli çiçek
kadirli çiçek
kadirli çiçek
kadirli çiçek
adana çiçekçi
# December 25, 2009 - 7:11 am
osmaniye çiçek
osmaniye çiçekçi
osmaniyede çiçek
osmaniyede çiçekçi
osmaniyede çiçekçiler
adana çiçekçi
# December 25, 2009 - 7:12 am
osmaniye çiçekçilik
osmaniye çiçekçi
osmaniyede çiçek
osmaniyede çiçekçi
osmaniyede çiçekçiler
adana çiçekçi
# December 25, 2009 - 7:12 am
osmaniye çiçek siparişi
osmaniye çiçekçi
osmaniyede çiçek
osmaniyede çiçekçi
osmaniyede çiçekçiler
adana çiçekçi
# December 25, 2009 - 7:13 am
adana çiçekçi
adanada çiçekçi
adana çiçekçilik
adana çiçek siparişi
adana çiçek satışı
adana çiçekçi
# December 25, 2009 - 7:13 am
adana çiçek
adana çiçekçi
adana çiçekçilik
adana çiçek siparişi
adana çiçek satışı
osmaniye çiçekçi
# December 28, 2009 - 7:46 am
osmaniye çiçekçi
osmaniyede çiçekçi
osmaniye çiçekçilik
osmaniye çiçek siparişi
osmaniye çiçekçileri
osmaniye çiçekçi
# December 28, 2009 - 7:47 am
osmaniyede çiçekçi
osmaniyede çiçekçi
osmaniyede çiçekçi
osmaniyede çiçekçi
osmaniyede çiçekçi
osmaniye çiçekçi
# December 28, 2009 - 7:47 am
adana çiçekçi
adanada çiçekçi
adana çiçekçilik
adana çiçek siparişi
adana çiçekçileri
osmaniye çiçekçi
# December 28, 2009 - 7:47 am
osmaniye çiçekçi
osmaniye çiçekçi
osmaniye çiçekçi
osmaniye çiçekçi
osmaniye çiçekçi
osmaniye çiçekçi
# December 28, 2009 - 7:48 am
osmaniye çiçek
osmaniye çiçek
osmaniye çiçek
osmaniye çiçek
osmaniye çiçek
osmaniye çiçekçi
# December 28, 2009 - 7:48 am
sumbas çiçekçi
sumbasda çiçekçi
sumbas çiçekçilik
sumbas çiçek siparişi
sumbas çiçekçileri
osmaniye çiçekçi
# December 28, 2009 - 7:48 am
hatay çiçekçi
hatay çiçekçi
hatay çiçekçilik
hatay çiçek siparişi
hatay çiçekçileri
osmaniye çiçekçi
# December 28, 2009 - 7:49 am
antakya çiçekçi
antakya çiçekçi
antakya çiçekçilik
antakya çiçek siparişi
antakya çiçekçileri
osmaniye çiçekçi
# December 28, 2009 - 7:49 am
iskenderun çiçekçi
iskenderunda çiçekçi
iskenderun çiçekçilik
iskenderun çiçek siparişi
iskenderun çiçekçileri
osmaniye çiçekçi
# December 28, 2009 - 7:49 am
kilis çiçekçi
kilisde çiçekçi
kilis çiçekçilik
kilis çiçek siparişi
kilis çiçekçileri
osmaniye çiçekçi
# December 28, 2009 - 7:49 am
yüreğir çiçekçi
yüreğirde çiçekçi
yüreğir çiçekçilik
yüreğir çiçek siparişi
yüreğir çiçekçileri
osmaniye çiçekçi
# December 28, 2009 - 7:50 am
seyhan çiçekçi
seyhanda çiçekçi
seyhan çiçekçilik
seyhan çiçek siparişi
seyhan çiçekçileri
osmaniye çiçekçi
# December 28, 2009 - 7:50 am
çukurova çiçekçi
çukurovada çiçekçi
çukurova çiçekçilik
çukurova çiçek siparişi
çukurova çiçekçileri
Squirrel Hacker » Daily Digest for January 8th
# January 9, 2010 - 4:52 am
[...] Shared How to recreate Silverback’s parallax effect | Carsonified. [...]