{"id":4921,"date":"2021-11-08T01:00:00","date_gmt":"2021-11-08T00:00:00","guid":{"rendered":"https:\/\/alvarotrigo.com\/epa\/css-transition-timing-function\/"},"modified":"2024-02-08T00:33:28","modified_gmt":"2024-02-07T23:33:28","slug":"css-transition-timing-function","status":"publish","type":"post","link":"https:\/\/alvarotrigo.com\/blog\/css-transition-timing-function\/","title":{"rendered":"CSS Transition [Timing Function &#038; Delay]"},"content":{"rendered":"\n<p>This is part 2 of the complete guide to CSS transitions. In this post, you&#8217;ll learn the advanced Jedi skills of CSS <code>transition-timing-function<\/code>, and <code>transition-delay<\/code>!<\/p>\n\n\n\n<p>If you missed part 1, click here to learn about <a href=\"https:\/\/alvarotrigo.com\/blog\/css-transition-duration\/\">CSS transition-duration and transition-property<\/a>.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"css-transition-timing-function\">CSS Transition-timing-function<\/h2>\n\n\n<p>This is where things get really cool.<\/p>\n\n\n\n<p>While <code>transition-duration<\/code> controls how long it takes to transition from one state to the next, <code>transition-timing-function<\/code> controls the rate of the transition <em>within<\/em> that time.<\/p>\n\n\n\n<p>For example, if you&#8217;re moving a box from one side of the screen to another, do you want it to move at a constant pace? Or do you want it to move quickly at first, but then slow down as it nestles into its finishing position?<\/p>\n\n\n\n<p>That&#8217;s what CSS <code>transition-timing-function<\/code> can do for you. There are five commonly used pre-set options:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>linear: The transition happens at a constant speed.<\/li>\n\n\n\n<li>ease: Starts off fast, but slows down just before the end. This is the default value.<\/li>\n\n\n\n<li>ease-in: Start off slow, and gradually builds up speed.<\/li>\n\n\n\n<li>ease-out: Starts off fast, but slows down early.<\/li>\n\n\n\n<li>ease-in-out: Starts off slow, slows down early, but fast in the middle section.<\/li>\n<\/ul>\n\n\n\n<p>This is easier to understand visually &#8211; hover over the image below to trigger the boxes to move:<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_JjyLgwJ\" data-src=\"\/\/codepen.io\/anon\/embed\/JjyLgwJ?height=450&amp;theme-id=1&amp;slug-hash=JjyLgwJ&amp;default-tab=css,result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed JjyLgwJ\" title=\"CodePen Embed JjyLgwJ\" class=\"cp_embed_iframe lazyload\" style=\"width:100%;overflow:hidden\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<p>As you can see, they all reach the finish line at the same time, but they move at different speeds along the way.<\/p>\n\n\n\n<p>To do this, I absolutely positioned each box, gave each one a unique class, and then used that class to set the transition on the <code>left<\/code> property:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.linear<\/span> {\n  <span class=\"hljs-attribute\">transition<\/span>: left <span class=\"hljs-number\">2s<\/span> linear;\n}\n\n<span class=\"hljs-selector-class\">.ease<\/span> {\n  <span class=\"hljs-attribute\">transition<\/span>: left <span class=\"hljs-number\">2s<\/span> ease;\n}\n\n<span class=\"hljs-selector-class\">.ease-in<\/span> {\n  <span class=\"hljs-attribute\">transition<\/span>: left <span class=\"hljs-number\">2s<\/span> ease-in;\n}\n\n<span class=\"hljs-selector-class\">.ease-out<\/span> {\n  <span class=\"hljs-attribute\">transition<\/span>: left <span class=\"hljs-number\">2s<\/span> ease-out;\n}\n\n<span class=\"hljs-selector-class\">.ease-in-out<\/span> {\n  <span class=\"hljs-attribute\">transition<\/span>: left <span class=\"hljs-number\">2s<\/span> ease-in-out;\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>As we discussed in part 1, <a href=\"https:\/\/alvarotrigo.com\/blog\/css-transition-duration\/\">CSS Transition Duration &amp; Property<\/a>, you can assign these three values separately, for example, you could use this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.ease-in-out<\/span> {\n  <span class=\"hljs-attribute\">transition-property<\/span>: left;\n  <span class=\"hljs-attribute\">transition-duration<\/span>: <span class=\"hljs-number\">2s<\/span>;\n  <span class=\"hljs-attribute\">transition-timing-function<\/span>: ease-in-out;\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>However you&#8217;ll run into the same issues regarding readability and maintainability that we talked about before &#8211; so it&#8217;s best to set them all together with <code>transition<\/code>.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"setting-customised-timing-functions-with-cubic-bezier()\">Setting Customised Timing Functions With <code>cubic-bezier()<\/code><\/h3>\n\n\n<p>For most situations, these five default CSS <code>transition-timing-function<\/code> values will probably have you covered.<\/p>\n\n\n\n<p>However if needed, you can customise the acceleration and deceleration of your transition by using the <code>cubic-bezier()<\/code> function.<\/p>\n\n\n\n<p>A cubic B\u00e9zier is a <a href=\"https:\/\/en.wikipedia.org\/wiki\/B%C3%A9zier_curve\" target=\"_blank\" rel=\"noopener nofollow\">type of curve<\/a>, named after French engineer Pierre B\u00e9zier, who used it to create the curves on Renault cars in the 1960s. The function takes four arguments, and from these, calculates a curve which determines the timing of the transition.<\/p>\n\n\n\n<p>OK, that&#8217;s a mouthful!<\/p>\n\n\n\n<p>What does it all mean? Well, let&#8217;s first think about <code>linear<\/code> timing. If you plotted that on a chart it&#8217;d look like this:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/alvarotrigo.com\/blog\/assets\/imgs\/2021-11-08\/linear.jpeg\" alt=\"Linear timing function\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" \/><\/figure>\n\n\n\n<p>The time the transition takes is along the x axis, and the progress of the transition (e.g. how far the box moves) is up the y axis. We see a straight line with <code>linear<\/code>, because the transition happens at a constant rate.<\/p>\n\n\n\n<p>Now let&#8217;s look at another one, <code>ease<\/code>:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" data-src=\"https:\/\/alvarotrigo.com\/blog\/assets\/imgs\/2021-11-08\/ease.jpeg\" alt=\"Easing timing function\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" \/><\/figure>\n\n\n\n<p>As you can see here, most of the progress of an <code>ease<\/code> transition happens quite early. Halfway through the duration, 80% of the animation has already been completed. The final 20% of the animation takes the same amount of time, which gives that deceleration effect.<\/p>\n\n\n\n<p>Each of the five &#8216;pre-set&#8217; transition timings has their own curve, and you could re-create them using <code>cubic-bezier()<\/code> if you really wanted:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>linear = cubic-bezier(0.0, 0.0, 1.0, 1.0)<\/li>\n\n\n\n<li>ease = cubic-bezier(0.25, 0.1, 0.25, 1.0)<\/li>\n\n\n\n<li>ease-in = cubic-bezier(0.42, 0, 1.0, 1.0)<\/li>\n\n\n\n<li>ease-out = cubic-bezier(0, 0, 0.58, 1.0)<\/li>\n\n\n\n<li>ease-in-out = cubic-bezier(0.42, 0, 0.58, 1.0)<\/li>\n<\/ul>\n\n\n\n<p>And of course, you are completely free to create your own curve!  Lea Verou has an excellent <a href=\"https:\/\/cubic-bezier.com\/#.17,.67,.83,.67\" target=\"_blank\" rel=\"noopener nofollow\">cubic bezier tool<\/a> that you can play around with.<\/p>\n\n\n\n<p>I&#8217;ll say one more thing on this before we move on &#8211; in general, and especially with movement, you&#8217;ll want to avoid <code>linear<\/code>.<\/p>\n\n\n\n<p>In the real world around us, objects rarely move at a constant, linear speed &#8211; they accelerate and decelerate. And it&#8217;s not just movement &#8211; even the amount of daylight we get per day doesn&#8217;t change at a linear rate through the year.<\/p>\n\n\n\n<p>If we replicate that in our transitions, they&#8217;ll feel more natural.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"css-transitions-with-steps()\">CSS transitions with <code>steps()<\/code><\/h3>\n\n\n<p>Each of the above options creates a nice, smooth transition from one state to the next. But what if you don&#8217;t want a smooth transition? What if you want to change state in a number of distinct stages? Well, CSS <code>transition-timing-function<\/code> has a <code>steps()<\/code> function which can do exactly that:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\">  <span class=\"hljs-selector-tag\">transition-timing-function<\/span>: <span class=\"hljs-selector-tag\">steps<\/span>(10);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Again, you can combine this into the <code>transition<\/code> property:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\">  <span class=\"hljs-selector-tag\">transition<\/span>: <span class=\"hljs-selector-tag\">left<\/span> 2<span class=\"hljs-selector-tag\">s<\/span> <span class=\"hljs-selector-tag\">steps<\/span>(10);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here we&#8217;re transitioning the <code>left<\/code> property, setting a <code>transition-duration<\/code> of 2 seconds, and we want it to happen in 10 discrete stages rather than one smooth movement.<\/p>\n\n\n\n<p>The pen below shows what a few different <code>steps()<\/code> values look like in action &#8211; and I&#8217;ve put a linear timing function at the top for comparison:<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_dyzmxwJ\" data-src=\"\/\/codepen.io\/anon\/embed\/dyzmxwJ?height=450&amp;theme-id=1&amp;slug-hash=dyzmxwJ&amp;default-tab=css,result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed dyzmxwJ\" title=\"CodePen Embed dyzmxwJ\" class=\"cp_embed_iframe lazyload\" style=\"width:100%;overflow:hidden\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<p>Note that <em>all<\/em> CSS <code>transition-timing-function<\/code> values technically use steps. It&#8217;s just that when we use <code>ease<\/code> or one of the other options, the browser is using so many steps that it appears smooth to the human eye. If you use a really high value with steps, like <code>steps(240)<\/code>, it should be indistinguishable from the <code>linear<\/code> version.<\/p>\n\n\n<h3 class=\"wp-block-heading\" id=\"css-steps---do-you-need-a-jump-start%3F\">CSS steps &#8211; do you need a jump start?<\/h3>\n\n\n<p>You might be thinking, if the transition takes five steps, does that <em>include<\/em> the starting point? For example, if we use <code>steps(5)<\/code>, is the initial position of the element included in those 5 steps? Or does it make 5 steps <em>from<\/em> that point?<\/p>\n\n\n\n<p>For that matter, is the final state included? Or does it mean there are 5 intermediate steps between the beginning state and the ending state?<\/p>\n\n\n\n<p>This is something you can choose for yourself, by passing a second argument, a jumpterm, to <code>steps()<\/code> &#8211; along with the number of steps. You have a few options here (these examples each assume you want 5 steps):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>jump-start<\/code>: The element will make five steps from the starting state to the end state. So there will be 6 stages in total. As soon as the transition begins, the element will <em>immediately<\/em> jump to the first step &#8211; a jump start!<\/li>\n\n\n\n<li><code>jump-end<\/code>: The element will make the exact same steps as <code>jump-start<\/code>, but it will reach the final stage exactly when the transition ends. This is a bit like <code>ease-in<\/code> &#8211; it will feel like a slow start. This is the default setting.<\/li>\n\n\n\n<li><code>jump-none<\/code>: The initial state and the end state are included in the 5 steps. So there will be 3 intermediate steps, between them, and the element will technically make 4 changes in total.<\/li>\n\n\n\n<li><code>jump-both<\/code>: The initial state and the end state are <em>not<\/em> included in the 5 steps. So there will be 5 intermediate steps between them, and the element will technically make 6 changes in total.<\/li>\n<\/ul>\n\n\n\n<p>(note that you can also use <code>start<\/code> instead of <code>jump-start<\/code> and <code>end<\/code> instead of <code>jump-end<\/code>).<\/p>\n\n\n\n<p>Let&#8217;s see how these look! Using the same boxes as above, I&#8217;ve added a different class to each box, and applied a different jumpterm to each one, asking for 5 steps each time:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-class\">.no-jump-setting<\/span> {\n  <span class=\"hljs-attribute\">transition<\/span>: left <span class=\"hljs-number\">2s<\/span> <span class=\"hljs-built_in\">steps<\/span>(<span class=\"hljs-number\">5<\/span>);\n}\n\n<span class=\"hljs-selector-class\">.jump-start<\/span> {\n  <span class=\"hljs-attribute\">transition<\/span>: left <span class=\"hljs-number\">2s<\/span> <span class=\"hljs-built_in\">steps<\/span>(<span class=\"hljs-number\">5<\/span>, jump-start);\n}\n\n<span class=\"hljs-selector-class\">.jump-end<\/span> {\n  <span class=\"hljs-attribute\">transition<\/span>: left <span class=\"hljs-number\">2s<\/span> <span class=\"hljs-built_in\">steps<\/span>(<span class=\"hljs-number\">5<\/span>, jump-end);\n}\n\n<span class=\"hljs-selector-class\">.jump-none<\/span> {\n  <span class=\"hljs-attribute\">transition<\/span>: left <span class=\"hljs-number\">2s<\/span> <span class=\"hljs-built_in\">steps<\/span>(<span class=\"hljs-number\">5<\/span>, jump-none);\n}\n\n<span class=\"hljs-selector-class\">.jump-both<\/span> {\n  <span class=\"hljs-attribute\">transition<\/span>: left <span class=\"hljs-number\">2s<\/span> <span class=\"hljs-built_in\">steps<\/span>(<span class=\"hljs-number\">5<\/span>, jump-both);\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>And here&#8217;s the result:<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_Yzxamda\" data-src=\"\/\/codepen.io\/anon\/embed\/Yzxamda?height=450&amp;theme-id=1&amp;slug-hash=Yzxamda&amp;default-tab=css,result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed Yzxamda\" title=\"CodePen Embed Yzxamda\" class=\"cp_embed_iframe lazyload\" style=\"width:100%;overflow:hidden\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"it's-not-just-about-movement!\">It&#8217;s Not Just About Movement!<\/h2>\n\n\n<p>I&#8217;ve used moving boxes in all the examples here, because that makes it easier to see what the different values are actually doing.<\/p>\n\n\n\n<p>But remember that these <code>transition-timing-function<\/code> settings apply to all transitions. Here&#8217;s how they affect colour change transitions, for example:<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_ExvEqeN\" data-src=\"\/\/codepen.io\/anon\/embed\/ExvEqeN?height=450&amp;theme-id=1&amp;slug-hash=ExvEqeN&amp;default-tab=css,result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed ExvEqeN\" title=\"CodePen Embed ExvEqeN\" class=\"cp_embed_iframe lazyload\" style=\"width:100%;overflow:hidden\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"css-transition-delay\">CSS transition-delay<\/h2>\n\n\n<p>The final transition property is CSS <code>transition-delay<\/code>. As the name implies, this enables you to set a delay between when the transition is triggered, and when the animation actually begins.<\/p>\n\n\n\n<p>You use it like this:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-selector-tag\">transition-delay<\/span>: 1<span class=\"hljs-selector-tag\">s<\/span>;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>To combine it with every else in <code>transition<\/code>, you just add the delay to the end:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\">  <span class=\"hljs-selector-tag\">transition<\/span>: <span class=\"hljs-selector-tag\">left<\/span> 2<span class=\"hljs-selector-tag\">s<\/span> <span class=\"hljs-selector-tag\">ease<\/span> 1<span class=\"hljs-selector-tag\">s<\/span>;\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Hover over the boxes to see a few different delays:<\/p>\n\n\n\n<div class=\"wp-block-cp-codepen-gutenberg-embed-block cp_embed_wrapper\"><iframe id=\"cp_embed_rNzdXoL\" data-src=\"\/\/codepen.io\/anon\/embed\/rNzdXoL?height=450&amp;theme-id=1&amp;slug-hash=rNzdXoL&amp;default-tab=css,result\" height=\"450\" scrolling=\"no\" frameborder=\"0\" allowfullscreen allowpaymentrequest name=\"CodePen Embed rNzdXoL\" title=\"CodePen Embed rNzdXoL\" class=\"cp_embed_iframe lazyload\" style=\"width:100%;overflow:hidden\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" data-load-mode=\"1\">CodePen Embed Fallback<\/iframe><\/div>\n\n\n\n<p>Note that the delay time is <em>not<\/em> included in the <code>transition-duration<\/code>. So a transition with a 2s duration and a 1s delay will take 3s in total.<\/p>\n\n\n\n<p>Another thing to note &#8211; try hovering over the boxes, but then move your mouse away before they have reached the finish line. You&#8217;ll see that the delay also applies when the transition is reversing itself.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"accessibility-with-transitions-and-animations\">Accessibility with transitions and animations<\/h2>\n\n\n<p>While many people will love all the awesome animations you&#8217;re going to create, many others would rather do without them. In fact, on-screen movement can cause sickness and even seizures in some folk.<\/p>\n\n\n\n<p>But you may have noticed that animations are all over the web now. So what do these people do? Do they just not use the internet?<\/p>\n\n\n\n<p>No they do, but they change a setting in their OS to indicate that they would prefer reduced movement. Browsers detect this setting, and pass it to your site. You can then detect what their preference is, and use a <code>prefers-reduced-motion<\/code> media query to turn off your transitions:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-keyword\">@media<\/span> (<span class=\"hljs-attribute\">prefers-reduced-motion:<\/span> reduce) {\n  <span class=\"hljs-selector-class\">.box<\/span> {\n    <span class=\"hljs-attribute\">transition<\/span>: none;\n  }\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>You can simply list all elements with transitions in this query, and set <code>transition<\/code> to none as you see above. To be on the safe side though, you can approach this from the opposite angle:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\"><span class=\"hljs-keyword\">@media<\/span> (<span class=\"hljs-attribute\">prefers-reduced-motion:<\/span> no-preference) {\n  <span class=\"hljs-selector-class\">.box<\/span> {\n    <span class=\"hljs-attribute\">transition<\/span>: background <span class=\"hljs-number\">2s<\/span> ease-in-out <span class=\"hljs-number\">1s<\/span>;\n  }\n}\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The <code>no-preference<\/code> value is the default for <code>prefers-reduced-motion<\/code>. So if you put all of your transitions in this query, your site will turn transitions on unless told not to. It&#8217;s a safer option, just in case you or your colleagues forget to turn a transition off in the <code>reduce<\/code> query.<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"what-will-you-create%3F\">What will you create?<\/h2>\n\n\n<p>Congratulations! You now have the tools to create all manner of transitions for your website. Once you get to grips with this, you&#8217;ll be amazed at what you&#8217;re able to create.<\/p>\n\n\n\n<p>If you want some inspiration, to see what&#8217;s really possible, have a look at <a href=\"https:\/\/alvarotrigo.com\/fullPage\/\">fullPage.js<\/a>. fullPage enables you to create beautiful, fully-responsive, full page sites that run smoothly and provide an awesome experience for your visitors.<\/p>\n\n\n\n<p>Check out these <a href=\"https:\/\/alvarotrigo.com\/fullPage\/#examples\">fullPage examples<\/a> to see the different transitions, animations, and effects you can apply to your own site. There are different scroll effects, fades, parallax effects, and a range of different sliders. Give it a try!<\/p>\n\n\n<h2 class=\"wp-block-heading\" id=\"related-articles\">Related articles<\/h2>\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/alvarotrigo.com\/blog\/css-page-transitions\/\">Beutiful pure CSS page transitions<\/a>.<\/li>\n\n\n\n<li><a href=\"https:\/\/alvarotrigo.com\/blog\/css-transition-duration\/\">CSS Transition Duration explained<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/alvarotrigo.com\/blog\/css-animations-scroll\/\">CSS animations on scroll<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Psst! Wanna know how to use CSS transition timing function &#038; delay to make super-cool web animations? Then check out this post!<\/p>\n","protected":false},"author":6,"featured_media":4920,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[106],"tags":[9,17,67],"class_list":["post-4921","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-css","tag-css","tag-web","tag-web-design"],"acf":[],"_links":{"self":[{"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/posts\/4921","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/comments?post=4921"}],"version-history":[{"count":4,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/posts\/4921\/revisions"}],"predecessor-version":[{"id":9577,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/posts\/4921\/revisions\/9577"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/media\/4920"}],"wp:attachment":[{"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/media?parent=4921"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/categories?post=4921"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/alvarotrigo.com\/blog\/wp-json\/wp\/v2\/tags?post=4921"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}