Unlimited WordPress themes, plugins, graphics & courses! Unlimited asset downloads! From $16.50/m
  1. Web Design
  2. CSS

CSS3 Transitions and Transforms From Scratch

Read Time:8 minsLanguages:

There are some amazing examples of CSS transforms and transitions, and whilst you may be blown away by them, there's a good chance that you're also overwhelmed and a bit intimidated! This tutorial will take you back to the very basics. We're going to create some fundamental CSS3 transitional movements, step by step.

A Quick Note on Browser Support:

Support across browsers is already pretty reasonable. Firefox 3.5, Chrome, Opera 10.5, Safari 3.1, and Internet Explorer 9.0 have you covered where transforms are concerned. IE is a little less accommodating with regard to transitions, though support is planned for IE10.

The Axes and Grid

To help understand the movement easily we'll be working on an axis grid (which you'll probably recognize from basic math). We'll be using x and y coordinates to move our objects.

The AxisThe AxisThe Axis

The only (crucial) difference is that on our axis the -y value is above the x axis, whilst it would ordinarily be below it. Why? Well, HTML and CSS (along with other web technologies like ActionScript) use an inverted Cartesian coordinate system because web pages start from top-left and read downwards. So now you know :)

Note: I'm going to assume that you're already familiar with HTML and CSS file structure. I'm going to skip explaining how to set up the CSS file, placing images and styling the Axis. Our focus will be on animating the objects. If you're not confident that your HTML + CSS skills are up to scratch, take a look at the new Tuts+ Premium HTML & CSS in 30 days (which is free) and you’ll learn everything you need to know.

1. Horizontal Movement

The first movement we'll demonstrate is "horizontal"; we'll animate the object to move to the right and to the left.

Moving to the Right

To move an object from its initial position we use: transform: translate(x,y);, where the x value should be positive and the y value should be 0 to move the object to the right.


Open your favorite Text Editor and enter the following html markup, then save the file.

We've assigned three classes to the image:

  • object: We use this class to set general rules for all the objects we will use.
  • van: We're going to use different objects to demonstrate each animation, so we'll apply different classes to them as well. This way we can position each object separately.
  • move-right: We'll move the object using this class, each movement will have different class.


Firstly, we'll position the object (our van image) to the center of the grid.

In this example we are going to move the object 350px to the right. The syntax is transform: translate(350px,0); and the object will move when the Axis is hovered over. We therefore declare it with #axis:hover .move-right.

The CSS transform property will only move the object from one point to another, it will not animate between the two states. To do this we need to add a transition property in the .object class.

This transition rule will tell the browser to animate all properties attached to the object for 2 seconds using an ease-in-out timing function (tween), without delay.

We can use 6 types of transition-timing-functions:

  • linear: the transition will have constant speed from start to end.
  • ease: the transition will start slowly, then get faster, before ending slowly.
  • ease-in: the transition will start slowly.
  • ease-out: the transition will end slowly.
  • ease-in-out: the transition starts and ends slowly.
  • cubic-bezier: define specific values for your own transition.
View Demo

Moving to the Left

To move an object to the left we simply need to enter a negative value in the x coordinate, while the y coordinate should remain 0. In this example we will move the object -350px to the left.


Create another HTML file and enter the following markup.

This time we use the move-left class to set the css rule for moving the object to the left.


Then, we enter -350px as the x coordinate. transform: translate(-350px,0); to move the object to the left. Quite easy, right?

Since we have previously set the transition rule in our .object class, we don’t need to set it again.

View Demo

2. Vertical Movement

Moving an object vertically is pretty easy, almost identical to moving horizontally. The only difference is that we will use the -y value to move the object upward and the y value to move downward.

Moving Upwards


The HTML markup is identical to the previous two examples. However, we're replacing the object with a rocket (for illustrative purposes), and the class that we use for our upwards movement is move-up.


As with our van, we'll position the rocket in the center of the grid:

As we've mentioned before, the y coordinate should be negative, in order to move the rocket upwards. in this case we move it 350px up.

View Demo

Moving Downwards

The method for moving an object downwards is (surprise, surprise) the opposite of moving upwards; the y coordinate value should be positive and the x coordinate should remain 0. The syntax is transform: translate(0,y);


In this example, we'll demonstrate downwards movement using a coin. Genius!


View Demo

3. Diagonal Movement

To create a diagonal transition, we'll combine values of both coordinates x and y. The syntax should be transform: translate(x,y). Depending on the direction, the value of x and y could be negative or positive.


And to demonstrate our diagonal movement, we'll use a paper plane.


We'll direct movement toward the north east. For the x coordinate value we enter a positive value (350px) and for the y coordinates we enter a negative value (-350px). The syntax will therefore look like this: transform: translate(350px,-350px);

Feel free to experiment and direct the movement of objects along the other diagonal axes.

View Demo

4. Rotation

Rotational movement in CSS3 is regulated using a radial coordinate from 0° to 360°. To rotate an object simply apply the following css property: transform: rotate(ndeg); where n is the degree of rotation.

360° Clockwise

To rotate an object clockwise, we enter a positive value for the rotate(ndeg) property.


For this example we'll use a pencil to demonstrate the movement.


And we'll rotate the object 360 degrees clockwise.

View Demo

360° Counter Clockwise

To perform counter-clockwise rotation we enter (you guessed it) a negative value.


We're still using the pencil as our object, but we'll change its class to .rotate360ccw.


View Demo

5. Scaling

Scale is an interesting feature in CSS3. By using the scale(n) or scale(x,y) property we can enlarge or shrink an object within our HTML. The object will be scaled according to n/x,y value, where the x-axis is for the width and the y-axis represents the height. For example, if we enter scale(2), the object will be scaled twice (200% larger) along both axes, from its initial dimension.

Let’s take a look at the example below.

In this example we'll increase the size of the car by 200%, giving the illusion that the car is moving closer (hopefully).


Again, the HTML markup has barely changed, but this time we use a car as the object.


View Demo

6. Multiple Movements

After having played with basic movements and transforms, we'll now try to combine some of them. Let's take a look.


This time, we'll be using a boomerang to demonstrate the animation.


The plan is to move the boomerang diagonally, while performing rotations at the same time. In order to do this, we simply have to list the transformations, separated by spaces.

View Demo


These are basic examples, and there's huge scope for developing them further! Remember: take browser support into account when using CSS3 properties, and don't go crazy with these effects - they should enhance your design, not drown it!

More CSS3 Transition Examples

For more inspiration, take a look at some of the cool CSS3 animations and effects on Envato Market. Here are a few examples:

1. Social Mosaic Wall

This item lets you build your own mosaic grid with your social media for staff and more. It includes 28 social icons and a range of different grid configurations.

Social Mosaic Wall on Envato MarketSocial Mosaic Wall on Envato MarketSocial Mosaic Wall on Envato Market
Social Mosaic Wall on Envato Market
Did you find this post useful?
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.