• CSS
  • Your first website: Styling the content
  • Challenge: Styling a biography page
  • Combinators
  • Sizing items in CSS
  • Styling tables
  • Challenge: A cool-looking box
  • Styling links
  • Introduction to CSS layout
  • CSS grid layout
  • CSS reference
  • Modules
    1. CSS basic user interface
    2. CSS cascading and inheritance
    3. CSS conditional rules
    4. CSS display
    5. CSS fonts
    6. CSS images
    7. CSS masking
    8. CSS namespaces
    9. CSS paged media
    10. CSS ruby layout
    11. CSS scroll-driven animations
    12. CSS shapes
    13. CSS text decoration
    14. CSS view transitions
    15. -moz-float-edge Non-standard Deprecated
    16. -moz-force-broken-image-icon Non-standard Deprecated
    17. -moz-image-region Non-standard
    18. -moz-orient Non-standard
    19. -moz-user-focus Non-standard Deprecated
    20. -moz-user-input Non-standard Deprecated
  • -webkit-*
    1. -webkit-border-before Non-standard
    2. -webkit-box-reflect Non-standard
    3. -webkit-mask-box-image Non-standard
    4. -webkit-mask-composite Non-standard
    5. -webkit-mask-position-x Non-standard
    6. -webkit-mask-position-y Non-standard
    7. -webkit-mask-repeat-x Non-standard
    8. -webkit-mask-repeat-y Non-standard
    9. -webkit-tap-highlight-color Non-standard
    10. -webkit-text-security Non-standard
    11. -webkit-touch-callout Non-standard
  • align-items
  • anchor-name Experimental
  • animation-*
    1. animation-direction
    2. animation-name
    3. animation-range Experimental
    4. animation-range-end Experimental
    5. animation-range-start Experimental
    6. animation-timeline Experimental
    7. backdrop-filter
    8. background-blend-mode
    9. background-origin
    10. background-repeat
    11. border-block
    12. border-block-end-style
    13. border-block-start-style
    14. border-bottom
    15. border-bottom-style
    16. border-end-end-radius
    17. border-image-repeat
    18. border-inline
    19. border-inline-end-style
    20. border-inline-start-style
    21. border-left
    22. border-radius
    23. border-right-width
    24. border-style
    25. border-top-right-radius
    26. bottom
    27. box-*
      1. box-align Non-standard Deprecated
      2. box-direction Non-standard Deprecated
      3. box-flex Non-standard Deprecated
      4. box-flex-group Non-standard Deprecated
      5. box-lines Non-standard Deprecated
      6. box-ordinal-group Non-standard Deprecated
      7. box-orient Non-standard Deprecated
      8. box-pack Non-standard Deprecated
      9. break-before
      10. clear
      11. clip-*
        1. clip Deprecated
        2. color-interpolation
        3. column-fill
        4. column-rule-style
        5. columns
        6. contain-*
          1. contain-intrinsic-inline-size
          2. container-name
          3. counter-increment
          4. cx
          5. display
          6. field-sizing Experimental
          7. fill-*
            1. filter
            2. flex-*
              1. flex-flow
              2. float
              3. font-family
              4. font-optical-sizing
              5. font-smooth Non-standard
              6. font-stretch Deprecated
              7. font-synthesis-position Experimental
              8. font-variant
              9. font-variant-emoji
              10. font-variation-settings
              11. grid
              12. grid-auto-rows
              13. grid-row
              14. grid-template-areas
              15. height
              16. image-orientation
              17. image-resolution Experimental
            3. inset-block
            4. inset-inline-end
            5. interpolate-size Experimental
            6. justify-self
          8. line-break
          9. line-height-step Experimental
        7. list-*
          1. list-style-type
        8. margin-*
          1. margin-block-start
          2. margin-inline-start
          3. margin-trim Experimental
        9. marker-*
          1. marker-start
        10. mask-*
          1. mask-border-outset
          2. mask-border-width
          3. mask-mode
          4. mask-size
          5. math-shift Experimental
          6. max-inline-size
          7. min-inline-size
          8. object-position
          9. offset-*
            1. offset-path
            2. order
            3. outline-offset
            4. overflow-anchor
            5. overflow-wrap
            6. overlay Experimental
            7. overscroll-*
              1. overscroll-behavior-x
              2. padding-block-end
              3. padding-inline-end
              4. padding-top
            8. page-*
              1. page-break-after Deprecated
              2. page-break-before Deprecated
              3. page-break-inside Deprecated
            9. place-content
            10. position
            11. position-anchor Experimental
            12. position-area Experimental
            13. position-try Experimental
            14. position-try-fallbacks Experimental
            15. position-try-order Experimental
            16. position-visibility Experimental
          10. resize
          11. ruby-align
          12. scale
          13. scroll-*
            1. scroll-margin-block-end
            2. scroll-margin-inline-end
            3. scroll-margin-top
            4. scroll-padding-block-start
            5. scroll-padding-inline-start
            6. scroll-snap-align
            7. scroll-timeline Experimental
            8. scroll-timeline-axis Experimental
            9. scroll-timeline-name Experimental
          14. scrollbar-*
            1. shape-image-threshold
            2. speak-as Experimental
            3. stroke-dasharray
            4. stroke-miterlimit
            5. table-layout
            6. text-*
              1. text-box
              2. text-decoration
              3. text-decoration-skip Experimental
              4. text-emphasis
              5. text-indent
              6. text-rendering
              7. text-size-adjust Experimental
              8. text-spacing-trim Experimental
              9. text-wrap
              10. timeline-scope Experimental
              11. transform-box
              12. transition-behavior
              13. transition-timing-function
            7. user-modify Non-standard Deprecated
            8. view-timeline Experimental
            9. view-timeline-axis Experimental
            10. view-timeline-inset Experimental
            11. view-timeline-name Experimental
            12. white-space-collapse
            13. word-break
            14. y
            15. Attribute selectors
            16. Universal selectors
          15. Combinators
            1. Column combinator Experimental
            2. Selector list
            3. :-moz-broken Non-standard Deprecated
            4. :-moz-drag-over Non-standard
            5. :-moz-first-node Experimental Non-standard
            6. :-moz-handler-blocked Non-standard
            7. :-moz-handler-crashed Non-standard
            8. :-moz-handler-disabled Non-standard
            9. :-moz-last-node Experimental Non-standard
            10. :-moz-loading Non-standard
            11. :-moz-locale-dir(ltr) Non-standard
            12. :-moz-locale-dir(rtl) Non-standard
            13. :-moz-only-whitespace Non-standard
            14. :-moz-submit-invalid Non-standard
            15. :-moz-suppressed Non-standard
            16. :-moz-user-disabled Non-standard
            17. :-moz-window-inactive Non-standard
          16. :blank Experimental
          17. :current Experimental
          18. :disabled
          19. :first-child
          20. :focus-within
        11. :has()
        12. :hover
        13. :is()
        14. :left
        15. :local-link Experimental
        16. :nth-child()
        17. :only-child
        18. :out-of-range
        19. :placeholder-shown
        20. :read-write
        21. :scope
        22. :target
        23. :target-within Experimental
        24. :visited
        25. ::-moz-color-swatch Non-standard
        26. ::-moz-focus-inner Experimental Non-standard
        27. ::-moz-list-bullet Experimental Non-standard
        28. ::-moz-list-number Experimental Non-standard
        29. ::-moz-meter-bar Non-standard
        30. ::-moz-progress-bar Experimental Non-standard
        31. ::-moz-range-progress Non-standard
        32. ::-moz-range-thumb Non-standard
        33. ::-moz-range-track Non-standard
      12. ::-webkit-*
        1. ::-webkit-inner-spin-button Non-standard
        2. ::-webkit-meter-bar Non-standard Deprecated
        3. ::-webkit-meter-even-less-good-value Non-standard
        4. ::-webkit-meter-inner-element Non-standard
        5. ::-webkit-meter-optimum-value Non-standard
        6. ::-webkit-meter-suboptimum-value Non-standard
        7. ::-webkit-progress-bar Non-standard
        8. ::-webkit-progress-inner-element Non-standard
        9. ::-webkit-progress-value Non-standard
        10. ::-webkit-scrollbar Non-standard
        11. ::-webkit-search-cancel-button Non-standard
        12. ::-webkit-search-results-button Non-standard
        13. ::-webkit-slider-runnable-track Non-standard
        14. ::-webkit-slider-thumb Non-standard
      13. ::cue
      14. ::first-line
      15. ::part()
      16. ::spelling-error
      17. ::view-transition-image-pair
      18. @color-profile
      19. @document Non-standard Deprecated
      20. @import
      21. @namespace
      22. @position-try Experimental
      23. @supports
      24. -moz-image-rect Non-standard Deprecated
      25. anchor-size() Experimental
      26. anchor() Experimental
      27. attr()
      28. calc-size() Experimental
      29. color-mix()
      30. cos()
      31. cubic-bezier()
      32. element() Experimental
      33. fit-content()
      34. hwb()
      35. inset()
      36. lch()
      37. log()
      38. min()
      39. oklch()
      40. palette-mix() Experimental
      41. scale3d()
      42. scroll() Experimental
      43. sin()
      44. steps()
      45. translateZ()
      46. view() Experimental
      47. <angle-percentage>
      48. <blend-mode>
      49. <color-interpolation-method>
      50. <custom-ident>
      51. <display-inside>
      52. <display-outside>
      53. <frequency-percentage>
      54. <hex-color>
      55. <image>
      56. <line-style>
      57. <overflow>
      58. <position-area> Experimental
      59. <resolution>
      60. <shape> Deprecated
      61. <time-percentage>
      62. Guides
      63. Animations
        1. Box alignment in block layout
        2. Introduction to the CSS basic box model
        3. Using relative colors
        4. Basic concepts of multi-column layout
        5. Handling content breaks in multi-column layout
      64. Conditional rules
        1. Using container size and style queries
      65. CSSOM view
        1. Introduction to formatting contexts
        2. Basic concepts of flexbox
        3. Controlling ratios of flex items along the main axis
        4. Variable fonts guide
      66. Grid
        1. Grid template areas
        2. Grids, logical values, and writing modes
        3. Masonry layout Experimental
      67. Images
        1. Basic concepts of logical properties and values
        2. Using CSS math functions
      68. Media queries
        1. Printing
      69. Nesting style rules
        1. Understanding z-index
      70. Scroll snap
        1. Basic shapes with shape-outside
        2. Using CSS transitions
      71. Center an element
      72. List group with badges
      73. Color picker tool
      74. Learn more
      75. See full compatibility
  • The animation-timing-function CSS property sets how an animation progresses through the duration of each cycle.

    Try it

    animation-timing-function: linear;
    
    animation-timing-function: ease-in-out;
    
    animation-timing-function: steps(5, end);
    
    animation-timing-function: cubic-bezier(0.1, -0.6, 0.2, 0);
    
    <section class="flex-column" id="default-example">
      <div class="animating" id="example-element"></div>
      <button id="play-pause">Play</button>
    </section>
    
    #example-element {
      animation-duration: 3s;
      animation-iteration-count: infinite;
      animation-name: slide;
      animation-play-state: paused;
      background-color: #1766aa;
      border-radius: 50%;
      border: 5px solid #333;
      color: white;
      height: 150px;
      margin: auto;
      margin-left: 0;
      width: 150px;
    }
    
    #example-element.running {
      animation-play-state: running;
    }
    
    #play-pause {
      font-size: 2rem;
    }
    
    @keyframes slide {
      from {
        background-color: orange;
        color: black;
        margin-left: 0;
      }
      to {
        background-color: orange;
        color: black;
        margin-left: 80%;
      }
    }
    
    "use strict";
    
    window.addEventListener("load", () => {
      const el = document.getElementById("example-element");
      const button = document.getElementById("play-pause");
    
      button.addEventListener("click", () => {
        if (el.classList.contains("running")) {
          el.classList.remove("running");
          button.textContent = "Play";
        } else {
          el.classList.add("running");
          button.textContent = "Pause";
        }
      });
    });
    

    It is often convenient to use the shorthand property animation to set all animation properties at once.

    Syntax

    css
    /* Keyword values */
    animation-timing-function: ease;
    animation-timing-function: ease-in;
    animation-timing-function: ease-out;
    animation-timing-function: ease-in-out;
    animation-timing-function: linear;
    animation-timing-function: step-start;
    animation-timing-function: step-end;
    
    /* cubic-bezier() function values */
    animation-timing-function: cubic-bezier(0.42, 0, 1, 1); /* ease-in */
    animation-timing-function: cubic-bezier(0, 0, 0.58, 1); /* ease-out */
    animation-timing-function: cubic-bezier(0.42, 0, 0.58, 1); /* ease-in-out */
    
    /* linear() function values */
    animation-timing-function: linear(0, 0.25, 1);
    animation-timing-function: linear(0 0%, 0.25 50%, 1 100%);
    animation-timing-function: linear(0, 0.25 50% 75%, 1);
    animation-timing-function: linear(0, 0.25 50%, 0.25 75%, 1);
    
    /* steps() function values */
    animation-timing-function: steps(4, jump-start);
    animation-timing-function: steps(10, jump-end);
    animation-timing-function: steps(20, jump-none);
    animation-timing-function: steps(5, jump-both);
    animation-timing-function: steps(6, start);
    animation-timing-function: steps(8, end);
    
    /* Multiple animations */
    animation-timing-function: ease, step-start, cubic-bezier(0.1, 0.7, 1, 0.1);
    
    /* Global values */
    animation-timing-function: inherit;
    animation-timing-function: initial;
    animation-timing-function: revert;
    animation-timing-function: revert-layer;
    animation-timing-function: unset;
    

    Values

    <easing-function>

    The easing function that corresponds to a given animation, as determined by animation-name.

    The non-step keyword values (ease, linear, ease-in-out, etc.) each represent cubic Bézier curves with fixed four-point values, while the cubic-bezier() function value allows non-predefined values to be specified. The steps() easing function divides the input time into a specified number of equal-length intervals. Its parameters include a number of steps and a step position.

    linear

    Equal to cubic-bezier(0.0, 0.0, 1.0, 1.0), animates at an even speed.

    ease

    Equal to cubic-bezier(0.25, 0.1, 0.25, 1.0), the default value, increases in velocity towards the middle of the animation, slowing back down at the end.

    ease-in

    Equal to cubic-bezier(0.42, 0, 1.0, 1.0), starts off slowly, with the speed of the transition of the animating property increasing until complete.

    ease-out

    Equal to cubic-bezier(0, 0, 0.58, 1.0), starts quickly, slowing down the animation continues.

    ease-in-out

    Equal to cubic-bezier(0.42, 0, 0.58, 1.0), with the animating properties slowly transitioning, speeding up, and then slowing down again.

    cubic-bezier(<number [0,1]> , <number> , <number [0,1]> , <number>)

    An author defined cubic-bezier curve, where the first and third values must be in the range of 0 to 1.

    linear(<number> <percentage>{1,2}, …)

    The function interpolates linearly between the provided easing stop points. A stop point is a pair of an output progress and an input percentage. The input percentage is optional and is inferred if not specified. If an input percentage is not provided then the first and last stop points are set to 0% and 100% respectively, and the stop points in the middle receive percentage values derived by linearly interpolating between the closest previous and next points that have a percentage value.

    steps(<integer>, <step-position>)

    Displays an animation iteration along n stops along the transition, displaying each stop for equal lengths of time. For example, if n is 5, there are 5 steps. Whether the animation holds temporarily at 0%, 20%, 40%, 60% and 80%, on the 20%, 40%, 60%, 80% and 100%, or makes 5 stops between the 0% and 100% along the animation, or makes 5 stops including the 0% and 100% marks (on the 0%, 25%, 50%, 75%, and 100%) depends on which of the following step position is used:

    jump-start

    Denotes a left-continuous function, so that the first jump happens when the animation begins.

    jump-end

    Denotes a right-continuous function, so that the last jump happens when the animation ends. This is the default.

    jump-none

    There is no jump on either end, effectively removing a step during the interpolation iteration. Instead, it holds at both the 0% mark and the 100% mark, each for 1/n of the duration.

    jump-both

    Includes pauses at both the 0% and 100% marks, effectively adding a step during the animation iteration.

    start

    Same as jump-start.

    end

    Same as jump-end.

    step-start

    Equal to steps(1, jump-start)

    step-end

    Equal to steps(1, jump-end)

    Note: When you specify multiple comma-separated values on an animation-* property, they are applied to the animations in the order in which the Setting multiple animation property values.

    Note: animation-timing-function has the same effect when creating CSS scroll-driven animations as it does for regular time-based animations.

    Description

    Easing functions may be specified on individual keyframes in a @keyframes rule. If no animation-timing-function is specified on a keyframe, the corresponding value of animation-timing-function from the element to which the animation is applied is used for that keyframe.

    Within a keyframe, animation-timing-function is an at-rule-specific descriptor, not the property of the same name. The timing is not being animated. Rather, a keyframe's easing function is applied on a property-by-property basis from the keyframe on which it is specified until the next keyframe specifying that property, or until the end of the animation if there is no subsequent keyframe specifying that property. As a result, an animation-timing-function specified on the 100% or to keyframe will never be used.

    Formal definition

    pseudo-elements
    #

    <easing-function> =
    <linear-easing-function> |
    ease-in |
    step-end && # )

    <cubic-bezier()> =
    cubic-bezier( ]? )

    <step-position> =
    jump-start |
    start |
    end

    Examples

    All the examples in this section animate the width and background-color properties of several <div> elements with different animation-timing-function values. The width is being animated from 0 to 100%, and the background color is being animated from lime to magenta.

    Linear function examples

    The example demonstrates the effects of various linear() easing function values.

    The following image shows graphs of all the linear() function values used in this example. Input progress (time) is plotted on the x-axis and output progress is plotted on the y-axis. As per the syntax, the input progress ranges from 0 to 100%, and the output ranges from 0 to 1.

    An image showing 'linear' function graphs

    Note that the output can go forward or backward.

    Cubic-Bézier examples

    The example demonstrates the effects of various bézier curve easing functions.

    The following image shows graphs of all the cubic bézier function values used in this example. The input progress (time) ranges from 0 to 1 and the output progress ranges from 0 to 1.

    An image showing 'cubic-bezier' function graphs

    Step examples

    This example demonstrates the effects of several step easing function values.

    The following image shows graphs of all the step() function values used in this example. The input progress (time) and output progress range from 0 to 1.

    CSS Easing Functions Level 1
    # linear-easing-function-parsin

    Browser compatibility

    BCD tables only load in the browser

    See also