Using CSS3 for transitions in web applications | HTML Goodies

Using CSS3 for transitions in web applications

Written By
Vipul Patel
Vipul Patel
Jun 6, 2014
3 minute read

CSS3 specification includes support for transitions which allows to change properties from one state to another. Classic example of transition in HTML include behavior defined under the ‘hover’ keyword. However, unlike the behavior observed with ‘hover’ keyword, CSS3 transitions have a time lapse element.


CSS transitions are used to change styles from one to another.


To use CSS transitions , we need to specify the property for which we want to add an effect, as well as the duration for the effect.


Note that transitions are a presentational effect and only work with animatable CSS properties.


The following chart indicates the CSS properties which are animatable:

Property NameTransition type
background-coloras color
background-positionas repeatable list of simple list of length, percentage, or calc
border-bottom-coloras color
border-bottom-widthas length
border-left-coloras color
border-left-widthas length
border-right-coloras color
border-right-widthas length
border-spacingas simple list of length
border-top-coloras color
border-top-widthas length
bottomas length, percentage, or calc
clipas rectangle
coloras color
font-sizeas length
font-weightas font weight
heightas length, percentage, or calc
leftas length, percentage, or calc
letter-spacingas length
line-heightas either number or length
margin-bottomas length
margin-leftas length
margin-rightas length
margin-topas length
max-heightas length, percentage, or calc
max-widthas length, percentage, or calc
min-heightas length, percentage, or calc
min-widthas length, percentage, or calc
opacityas number
outline-coloras color
outline-widthas length
padding-bottomas length
padding-leftas length
padding-rightas length
padding-topas length
rightas length, percentage, or calc
text-indentas length, percentage, or calc
text-shadowas shadow list
topas length, percentage, or calc
vertical-alignas length
visibilityas visibility
widthas length, percentage, or calc
word-spacingas length
z-indexas integer

 

We define a transition using two new CSS properties.

  • transition-property
  • transition-duration

 

A typical CSS transition is of the following format

div

{

transition-property: propertyname;

transition-duration: duration;

}

 

E.g.

div

{

transition-property: color, #(100,100,100);

transition-duration: 2s;

}

 

If you want to specify multiple transitions, you need to specify them as comma-separated-values.

div

{

transition-property: first_propertyname, second_propertyname, …;

transition-duration: duration_for_first, duration_for_second,…;

}

 

In case the number of transition properties and transition duration are not equal, the length of transition-property list determines the number of items in each list examined when starting transitions.

 

When the number of transition-properties are multiple of items in transition-duration, the duration durations are cycled. In case they are not multiple, they are used until there are a multiple and the remaining values are ignored.

 

We can also specify ‘none’ as value for transition-property , which would imply that no properties are transitioned.

We can also specify ‘0s’ as value for transition-duration, which would imply an immediate transition.

 

There are two additional transition relate properties:

1.       transition-timing – which specifies how fast/slow the transitions will occur.

2.       transition-delay – which specifies how long to wait to start the transition after transition is initiated.

 

Here is an example of a simple transition:

input {

transition-property: width;

transition-duration: 1s;

transition-timing-function: linear;

transition-delay: 2s;

}

 

Here is a simple HTML page which shows transition in play.

 

   

   

   

Hover over the input element above, to see the transition effect.

 

 

When we hover over the orange input box, the length of the box changes. This is CSS3 transition in action.

Summary

In this article, we saw how to use CSS3 transitions in web pages. I hope you have found this information useful.

About the author

Vipul Patel is a Program Manager currently working at Amazon Corporation. He has formerly worked at Microsoft in the Lync team and in the .NET team (in the Base Class libraries and the Debugging and Profiling team). He can be reached at vipul.patel@hotmail.com

 

References

http://www.w3.org/TR/css3-transitions/

 

HTML Goodies Logo

The original home of HTML tutorials. HTMLGoodies is a website dedicated to publishing tutorials that cover every aspect of being a web developer. We cover programming and web development tutorials on languages and technologies such as HTML, JavaScript, and CSS. In addition, our articles cover web frameworks like Angular and React.JS, as well as popular Content Management Systems (CMS) that include WordPress, Drupal, and Joomla. Website development platforms like Shopify, Squarespace, and Wix are also featured. Topics related to solid web design and Internet Marketing also find a home on HTMLGoodies, as we discuss UX/UI Design, Search Engine Optimization (SEO), and web dev best practices.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.