lynx   »   [go: up one dir, main page]

Menu
×
   ❮     
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SASS VUE GEN AI SCIPY CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING BASH RUST

CSS Tutorial

CSS HOME CSS Introduction CSS Syntax CSS Selectors CSS How To CSS Comments CSS Errors CSS Colors CSS Backgrounds CSS Borders CSS Margins CSS Padding CSS Height/Width CSS Box Model CSS Outline CSS Text CSS Fonts CSS Icons CSS Links CSS Lists CSS Tables CSS Display CSS Max-width CSS Position CSS Z-index CSS Overflow CSS Float CSS Inline-block CSS Align CSS Combinators CSS Pseudo-classes CSS Pseudo-elements CSS Opacity CSS Navigation Bars CSS Dropdowns CSS Image Gallery CSS Image Sprites CSS Attr Selectors CSS Forms CSS Counters CSS Units CSS Specificity CSS !important CSS Math Functions CSS Optimization CSS Accessibility CSS Website Layout

CSS Advanced

CSS Rounded Corners CSS Border Images CSS Backgrounds CSS Colors CSS Color Keywords CSS Gradients CSS Shadows CSS Text Effects CSS Custom Fonts CSS 2D Transforms CSS 3D Transforms CSS Transitions CSS Animations CSS Tooltips CSS Image Styling CSS Image Modal CSS Image Centering CSS Image Filters CSS Image Shapes CSS object-fit CSS object-position CSS Masking CSS Buttons CSS Pagination CSS Multiple Columns CSS User Interface CSS Variables CSS @property CSS Box Sizing CSS Media Queries CSS MQ Examples

CSS Flexbox

Flexbox Intro Flex Container Flex Items Flex Responsive

CSS Grid

Grid Intro Grid Columns/Rows Grid Lines Grid Container Grid Item CSS @supports

CSS Responsive

RWD Intro RWD Viewport RWD Grid View RWD Media Queries RWD Images RWD Videos RWD Frameworks RWD Templates

CSS SASS

SASS Tutorial

CSS Examples

CSS Templates CSS Examples CSS Editor CSS Snippets CSS Quiz CSS Exercises CSS Website CSS Syllabus CSS Study Plan CSS Interview Prep CSS Bootcamp CSS Certificate

CSS References

CSS Reference CSS Selectors CSS Combinators CSS Pseudo-classes CSS Pseudo-elements CSS At-rules CSS Functions CSS Reference Aural CSS Web Safe Fonts CSS Animatable CSS Units CSS PX-EM Converter CSS Colors CSS Color Values CSS Default Values CSS Browser Support

CSS Transitions


CSS Transitions

CSS transitions allows you to change property values smoothly, over a given duration.

Mouse over the element below to see a CSS transition effect:

CSS

The CSS transition Property

To create a transition effect, you must specify the CSS property you want to add a transition to, and the duration of the transition.

The CSS transition property is a shorthand property for:

CSS Transition Example

The following example shows a 100px * 100px <div> element. The <div> element has specified a transition effect for the width property, with a duration of 2 seconds:

Example

div {
  width: 100px;
  height: 100px;
  background-color: red;
  transition: width 2s;
}

How to Trigger the Transition

The transition is triggered when there is a change in the element's properties. This often happens within pseudo-classes (:hover, :active, :focus, or :checked).

So, from the code above, the transition effect will start when the width property changes value.

Now, we add a div:hover class that specifies a new value for the width property when a user mouses over the <div> element:

Example

div:hover {
  width: 300px;
}
Try it Yourself »

Notice that when the cursor mouses out of the element, it will gradually change back to its original style.


Change Multiple Property Values

You can change multiple properties by separating them by commas.

The following example adds a transition effect for the width, height, and background-color properties, with a duration of 2 seconds for the width, 4 seconds for the height, and 3 seconds for the background-color:

Example

Add a transition effect for the width, height, and background-color properties:

div {
  transition: width 2s, height 4s, background-color 3s;
}
Try it Yourself »


CSS Transition Speed Curve

The transition-timing-function property specifies the speed curve of the transition effect.

This property can have one of the following values:

  • ease - transition will start slow, then go fast, and end slow (this is default)
  • linear - transition will keep the same speed from start to end
  • ease-in - transition will start slow
  • ease-out - transition will end slow
  • ease-in-out - transition will have a slow start and end
  • cubic-bezier(n,n,n,n) - lets you define your own values in a cubic-bezier function

The following example shows some of the different speed curves that can be used:

Example

Some different speed curves for transition:

#div1 {transition-timing-function: linear;}
#div2 {transition-timing-function: ease;}
#div3 {transition-timing-function: ease-in;}
#div4 {transition-timing-function: ease-out;}
#div5 {transition-timing-function: ease-in-out;}
Try it Yourself »

CSS Transition Delay

The transition-delay property specifies a delay before the transition starts.

The transition-delay value is defined in seconds (s) or milliseconds (ms).

The following example has a 1 second delay before starting:

Example

Add a 1 second delay before starting:

div {
  transition-delay: 1s;
}
Try it Yourself »

Transition + Transform

The following example combines transition and transform for a <div>:

Example

div {
  transition: width 2s, height 2s, background-color 2s, transform 2s;
}
Try it Yourself »

The following example combines transition and transform for a button:

Example

button {
  transition: background-color 1s ease-out, transform 1s ease-out;
}
Try it Yourself »

More Transition Examples

The CSS transition properties can be specified one by one, like this:

Example

div {
  transition-property: width;
  transition-duration: 2s;
  transition-timing-function: linear;
  transition-delay: 1s;
}
Try it Yourself »

or by using the shorthand property transition:

Example

div {
  transition: width 2s linear 1s;
}
Try it Yourself »


CSS Transition Properties

The following table lists all the CSS transition properties:

Property Description
transition A shorthand property for setting the four transition properties into a single property
transition-delay Specifies a delay (in seconds) for the transition effect
transition-duration Specifies how many seconds or milliseconds a transition effect takes to complete
transition-property Specifies the name of the CSS property the transition effect is for
transition-timing-function Specifies the speed curve of the transition effect

×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookie and privacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved. W3Schools is Powered by W3.CSS.

Лучший частный хостинг