Big note here! Sliding doors is a pretty old technique. It had its time on the web, but it’s probably not the smartest way to go these days. We have border-radius now and gradient backgrounds and all that, which unlock most of what we were trying to achieve back in the day of sliding doors.
But it’s still fun to document how it works, so here it is:
<a href="#" class="button">
<span>Sliding Doors Button</span>
</a>
.button {
float: left;
clear: both;
background: url(RIGHT_SIDE.png) top right no-repeat;
margin: 5px;
padding-right: 20px;
color: white;
text-decoration: none;
}
.button span {
background: url(LEFT_SIDE.png) top left no-repeat;
line-height: 22px;
padding: 7px 0 5px 18px;
display: block;
}
.button:hover {
background-position: right -34px;
}
.button:hover span {
background-position: 0 -34px; color: #fff;
}
Which assumes graphics like these:


See the Pen Sliding Doors Buttons by Chris Coyier (@chriscoyier) on CodePen.
Hey Chris! Glad you liked this! I was working on a website for Biola University and needed something beautiful that scaled… to make it easy for future updates to their sites – then presto this came out of my head! I sure hope this is something useful for more designers out there! Enjoy!
Hello Chris,
Really appreciated this method as it works like a charm. However, there is 1 issue that keeps it from being 100% flexible…
How can you get it to work with rounded corner buttons with a transparent background? What happens with me is the right side is fine, but the left side’s corner is transparent so the body of the button shows underneath the left corners…
Do you have any solutions for this perplexing issue?
THANKS!
I guess not Chris?
Hey Mark, your name is awesome! Anyway, that is the same problem I’m trying to find a solution to. If I figure anything out, I’ll post it here. Or if you already have, please do tell.
Nudge it with relative positioning.
Anyone have an example of this using <input> tags of various types? I’m working on one but IE keeps messing up the alignment of the images.
Very helpful. Just like a light in the dark.
Thanks…
Not sure if this will help anyone, but if you need to center this button remove the float:left and change the two instances of display:block to display: inline-block. That way if you drop the button into an element that’s set to text-align:center it will center but maintain the proper width.
Thanks Joe for this great trick! It helped a lot.
Great, its really helpful.
demo’s cool it’s the code that I need. thanks
Your site is SO VERY much what I need. Thanks for all of your help! Your instruction is clear, understandable and perfect!
Any idea how to center this button? It won’t center inside of divs or table cells.
Thanks for the tip. I use your site as a reference daily. Still, I can’t wait for better browser support so I never have to use this technique again.
Not working in IE8. When I hover over the right portion of the button disappears.
Perfect from first attempt
Works for IE7 / IE8 too
I think it is important for developers to understand that Links are not buttons
I like this post very much. Thanks!