How to Create a Shuffled Paper Effect in CSS3

Share this article

This is a nice effect which transforms a standard boxy-looking element and makes it look like shuffled paper. I recall seeing a similar effect a few years ago where it was handled with images but we’re going to use pure CSS3: shuffled paper View the demonstration and code… It should come as no surprise that :before and :after pseudo elements are used to display the bottom pages. These are rotated using a transformation to give the shuffled look. The code works in Chrome, Safari, Firefox, IE10 and Opera (Presto and probably Webkit versions). Older browsers may show the lower pages, but they won’t rotate them so they are effectively invisible. However, the effect should degrade gracefully. Let’s start with some HTML:

<div class="papers">
<p>some content</p>
</div>
Nothing special to see here. I’ve used a generic div, but you could use section, article or whatever is appropriate. The “papers” class is responsible for applying the effect. First, we’ll apply a background, border and shadow to the main and both pseudo elements:
.papers, .papers:before, .papers:after
{
	background-color: #fff;
	border: 1px solid #ccc;
	box-shadow: inset 0 0 30px rgba(0,0,0,0.1), 1px 1px 3px rgba(0,0,0,0.2);
}
Notice that two box-shadows are defined: the inner page shading and a subtle drop-shadow. Next, we’ll define the styles for the main element. Primarily, it’s the width, padding and margins but the relative position is the most important. Incidentally, do not be tempted to apply a z-index; it’ll cause the pseudo elements to appear on top.
.papers
{
	position: relative;
	width: 50%;
	padding: 2em;
	margin: 50px auto;
}
We’ll now apply some content, dimensions and positioning to the :before and :after pseudo elements. In essence, they have the same size, shape and location as the main element:
.papers:before, .papers:after
{
	content: "";
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
Now comes the interesting part — we’ll rotate them using a transform. We require the -webkit prefix for Chrome and Safari. The -o prefix is required for Opera which prefers ‘rotate’ to ‘rotateZ’. Firefox and IE10 support the non-prefixed transform.
	-webkit-transform: rotateZ(2.5deg);
	-o-transform: rotate(2.5deg);
	transform: rotateZ(2.5deg);
	z-index: -1;
}
Note that we’ve set the z-index to -1 to push the elements below the main container. Finally, we apply a different rotation to the :after pseudo element.
.papers:after
{
	-webkit-transform: rotateZ(-2.5deg);
	-o-transform: rotate(-2.5deg);
	transform: rotateZ(-2.5deg);
}
Easy. View the demonstration and code… Please use the code as you wish — it’s relatively simple to apply different colors and rotation degrees, but you might discover a range of interesting effects. Post your links below…

Frequently Asked Questions about CSS3 Shuffled Paper Effect

How can I create a realistic paper effect using CSS3?

Creating a realistic paper effect using CSS3 involves using a combination of CSS properties such as box-shadow, border-radius, and transform. The box-shadow property is used to create a shadow effect that gives the paper a 3D look. The border-radius property is used to round the corners of the paper, and the transform property is used to rotate the paper to give it a shuffled look. You can also use the :before and :after pseudo-elements to create additional layers of paper.

What are some practical applications of the CSS3 paper effect?

The CSS3 paper effect can be used in a variety of ways to enhance the visual appeal of a website. It can be used to create realistic-looking documents, notes, or memos on a webpage. It can also be used to create interesting backgrounds or overlays. Additionally, it can be used in animations to create a paper folding or shuffling effect.

Can I use the CSS3 paper effect in responsive design?

Yes, the CSS3 paper effect can be used in responsive design. You can use media queries to adjust the size and position of the paper effect based on the screen size. This ensures that the paper effect looks good on all devices, from desktops to tablets to mobile phones.

How can I add texture to the CSS3 paper effect?

Adding texture to the CSS3 paper effect can be achieved by using a background image. The background image can be a texture image that resembles the surface of a paper. You can use the background-size property to adjust the size of the image and the background-repeat property to repeat the image if necessary.

How can I animate the CSS3 paper effect?

Animating the CSS3 paper effect can be done using CSS animations or transitions. You can use the transform property to rotate, scale, or move the paper. You can also use the opacity property to create a fading effect. To create a smooth animation, you can use the transition property to specify the duration and timing function of the animation.

Can I use the CSS3 paper effect with other CSS effects?

Yes, the CSS3 paper effect can be combined with other CSS effects to create more complex and interesting designs. For example, you can use the paper effect with the CSS3 gradient effect to create a colorful paper. You can also use it with the CSS3 text effect to create a paper with text.

How can I create a stack of papers using the CSS3 paper effect?

Creating a stack of papers using the CSS3 paper effect involves creating multiple layers of paper using the :before and :after pseudo-elements. Each layer can be positioned and rotated differently to create the appearance of a stack of shuffled papers.

How can I create a folded paper effect using CSS3?

Creating a folded paper effect using CSS3 involves using the transform property to fold the paper. You can use the rotate function to rotate the paper, and the skew function to skew the paper. You can also use the :before and :after pseudo-elements to create the folded parts of the paper.

How can I create a torn paper effect using CSS3?

Creating a torn paper effect using CSS3 involves using the border-image property. The border-image property allows you to use an image as the border of an element. You can use an image of a torn paper as the border image to create the torn paper effect.

How can I create a crumpled paper effect using CSS3?

Creating a crumpled paper effect using CSS3 involves using a combination of the transform property and the background image. The transform property is used to distort the paper, and the background image is used to add texture to the paper. You can use a crumpled paper texture as the background image to create the crumpled paper effect.

Craig BucklerCraig Buckler
View Author

Craig is a freelance UK web consultant who built his first page for IE2.0 in 1995. Since that time he's been advocating standards, accessibility, and best-practice HTML5 techniques. He's created enterprise specifications, websites and online applications for companies and organisations including the UK Parliament, the European Parliament, the Department of Energy & Climate Change, Microsoft, and more. He's written more than 1,000 articles for SitePoint and you can find him @craigbuckler.

AdvancedCSSCSS TransformsCSS3HTML5 Dev CenterHTML5 Tutorials & Articles
Share this article
Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week