Put transition only on the normal state:

.design-box {
  transition: all 1s ease;
}

Have a look at the snippet below:

.design-box {
  width: 100%;
  height: 250px;
  margin: 100px auto;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 50%;
  position: relative;
  transition: all 1s ease;
}

.design-box:hover {
  border-radius: 0;
}
<div class="design-box"></div>

Answer from Saurav Rastogi on Stack Overflow
🌐
W3Schools
w3schools.com β€Ί css β€Ί css3_transitions.asp
CSS Transitions
1 month ago - 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: ... Notice that when the cursor mouses out of the element, it will gradually change back to its original style.
Discussions

How to smoothly transition from a hover to a non hover ?
In your code, it's only transitioning while you're hovering over it. When you mouse away, it no longer has a transition, so it instantly reverts. Instead, you can apply the transition to the ul without :hover, so it's always got the attribute, wherever your mouse may be. ul { transition: background-color 1.2s; } ul:hover { background-color: green; } More on reddit.com
🌐 r/css
4
4
September 1, 2021
html - CSS: Smooth transition between hover and leaving - Stack Overflow
The easy fix is to simply add the same transition to the original element (as well as the hover state of the element). .effect { border: none; margin: 0 auto; -webkit-transition: all 0.4s ease-in-out; -moz-transition: all 0.4s ease-in-out; -o-transition: all 0.4s ease-in-out; transition: all ... More on stackoverflow.com
🌐 stackoverflow.com
css - What is the opposite of :hover (on mouse leave)? - Stack Overflow
I was doing some styling with scrollbar ... (:not(:hover) apparently) on scrollable area. I wanted the scrollbar thumb fade out with 1.5s delay when mouse left the scrollable area and this really helped me out! 2023-08-24T22:47:18.473Z+00:00 ... Just use CSS transitions instead of animations. A { color: #999; transition: color 1s ease-in-out; } ... More on stackoverflow.com
🌐 stackoverflow.com
html - CSS Transition - eases in but doesn't ease out? - Stack Overflow
.img-blur:hover { -webkit-filter: ... -ms-transition: all 0.35s ease-in-out; } The image blurs when the mouse hovers but when I take my mouse off it goes straight back to normal, how can I make it ease out of the blur? Also, is there a way to show text when the mouse hovers over? When the user hovers over the image I want it to blur and then show some text such as "Learn More". Is this also possible with just css... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com β€Ί r/css β€Ί applying transition only on hover in and out action
r/css on Reddit: Applying transition only on hover in and out action
February 5, 2023 -

I have a following section of css:

.navbar {   
   position: fixed;
   display: flex;
   z-index: 3;
   width: 70px;
   background-color: black;
   height: 100%;
   transition: 0.5s;
 }  
.navbar:hover {
   width: 200px;
 }  

@media (width < 1080px) {
   .navbar {
     position: sticky;
     transition: none;
     flex-direction: row;
     width: 100%;
     height: 100px;
    }      
   .navbar:hover {
     width: 100%;   } 
}

It describes a navigation bar that is a sidebar when the viewport is bigger than 1080px. When I hover over it, it stretches to 200px. If the vieport becomes smaller than 1080px, the sidebar becomes horizontal navigation bar.

What I wanted to achieve was a smooth transition of stretching the sidebar on hover and on hover leave. At this moment this works as intended.

What I also wanted was snappy transition from sidebar to horizontal navigation bar and vice versa. Unfortunately it works only partialy. Although I have achieved the snappy transition from sidebar to horizontal navigation bar, I cannot figure out how can I create snappy transition from horizontal navigation bar to sidebar.

I understand what is the problem here (when changing from horizontal navigation bar to sidebar the transtion is set again to 0.5s hence the animation) but I am struggling to figure out how to achieve two-way snappines from sidebar to navbar while maintaining the "hover-in-and-out" transition.

What would be the correct way of achieving such effect ?

Here is example of current state of the sidebar/navbar in jsfiddle: https://jsfiddle.net/mz29afyh/2/

Top answer
1 of 2
1
You need to add starting transition properties for your non-hover state. By default, the transition property has no value. /* starting state */ .navButton{ background-color: black; padding: 5px; transition: all .26s ease } The transition declaration is set to affect all valid property values, for a duration of 2600ms (.26s), and the timing function is set to ease. /* hover state */ .navButton:hover { background-color: red; } Because you've set up default transition property values. Your pseudo-states will inherit original values. Furthermore, you're now able to see transition values added to your pseudo-state rule. /* alternative state */ .navButton-alt { background-color: orange; padding: 5px; transition: color .56s linear } /* alternative hover state */ .navButton-alt:hover{ background-color: green; transition: color .16s ease } Notice the difference between the "transition" declaration in both examples. Reference material (Mozilla Docs)
2 of 2
1
The advice I would have is to think about your states: non-interactive state (base styles) hovering leaving-hover In your CSS that would mean: .navbar { // shared styles } .navbar:hover { // styles for when you're explicitly hovering } .navbar:not(:hover){ // styles for when you're explicitly NOT hovering } As u/raccoonrocoso has pointed out, you could put your :not(:hover) styles in the base styles instead, but I've found that transitions and animations are much easier to manage when they are given directly comparable A:B states, and so the separation of base and interaction styles contributes to readability and maintainability. If you implement like this, you'll also find that your transition inconsistencies disappear as long as the position property doesn't change. The spanner in the works, you see, is that you cannot transition between discrete states; there is no transition between position: fixed and position:sticky in the same way that there's no transition between height: 100px and height: auto - CSS needs contiguous values to transition between. SO: separate out your transition states into separate selectors decide whether you need position: fixed or position: sticky and use one, not both. Here's a codepen that demonstrates the above .
🌐
CSS-Tricks
css-tricks.com β€Ί almanac β€Ί properties β€Ί t β€Ί transition
transition | CSS-Tricks
December 13, 2024 - It looks like you’re using two separate elements – the first line targets the LI while the second targets the A:HOVER Try this instead: ` .header_menu ul li a { background:url(../images/menu_bg.png) left center no-repeat; width:auto; -webkit-transition: background 3s ease; -moz-transition: background 3s ease; transition: background 3s ease; } .header_menu ul li a:hover{ background:url(../images/menu_bg_hover.png) repeat-x; }`
🌐
MDN Web Docs
developer.mozilla.org β€Ί en-US β€Ί docs β€Ί Web β€Ί CSS β€Ί Reference β€Ί Properties β€Ί transition
transition CSS property - MDN Web Docs - Mozilla
3 days ago - The transition CSS property is a shorthand property for transition-property, transition-duration, transition-timing-function, transition-delay, and transition-behavior. transition: margin-right 2s; transition: margin-right 2s 0.5s; transition: margin-right 2s ease-in-out; transition: margin-right ...
🌐
Josh W. Comeau
joshwcomeau.com β€Ί animation β€Ί css-transitions
An Interactive Guide to CSS Transitions β€’ Josh W. Comeau
A cute little detail is to give each action its own transition settings. For hover animations, I like to make the enter animation quick and snappy, while the exit animation can be a bit more relaxed and lethargic: ... Focus the editor. This will trap focus until you press Escape.Code editor: ... Focus the editor. This will trap focus until you press Escape.Code editor: ... Another common example is modals. It can be useful for modals to enter with an ease-out animation, and to exit with a quicker ease-in animation:
🌐
MDN Web Docs
developer.mozilla.org β€Ί en-US β€Ί docs β€Ί Web β€Ί CSS β€Ί transition
transition - CSS - MDN Web Docs - Mozilla
The transition CSS property is a shorthand property for transition-property, transition-duration, transition-timing-function, transition-delay, and transition-behavior. transition: margin-right 2s; transition: margin-right 2s 0.5s; transition: margin-right 2s ease-in-out; transition: margin-right ...
Find elsewhere
🌐
EASEOUT
easeout.co β€Ί blog β€Ί 2020-06-19-css-transitions
CSS Transitions | EASEOUT
You can activate a CSS transition with a pseudo-class like :hover (when a mouse hovers over the element), :focus (when a user tabs onto or clicks an input element), or :active (when user clicks the element). ... .button { background-color: pink; transition: background-color 2s ease-out; } ...
🌐
Jefersonsilva
jefersonsilva.me β€Ί articles β€Ί writing-smooth-css-transitions
Writing Smooth CSS transitions
January 28, 2024 - In the example above, you will notice we’ve added a CSS variable --order to handle the delay of each block. This is useful so the elements don’t show at the same time in the animation but rather at sequential, a staggered animation. We can’t talk about micro-interactions without SVG animations, probably the most fun to build!hover me! svg #handle { /* Exit transition */ transition: transform 300ms 100ms ease-in-out; transform: translateY(-14px); } svg :is(#left, #right, #mid) { transition: opacity 300ms ease-in-out; transition-delay: calc(var(--delay, 1) * 1ms); opacity: 0; } svg:hover { #left, #right, #mid { opacity: 1; } #handle { /* Enter transition */ transition: transform 500ms 100ms cubic-bezier(0.68, -0.6, 0.32, 1.6); transform: translateY(0); } }
🌐
Tailwind CSS
tailwindcss.com β€Ί docs β€Ί transition-property
transition-property - Transitions & Animation - Tailwind CSS
Use utilities like transition and transition-colors to specify which properties should transition when they change: ... <button class="bg-blue-500 transition delay-150 duration-300 ease-in-out hover:-translate-y-1 hover:scale-110 ...
🌐
WPPoland
wppoland.com β€Ί blog β€Ί css image hover effect - smooth fade transition tutorial
CSS hover fade effect - change fade out on mouse over (copy-paste code) | webdesign | WPPoland
January 7, 2026 - If you searched for a CSS image hover effect, the shortest answer is this: add transition: opacity 0.3s ease-in-out; to the element, then change opacity on :hover.
🌐
W3Schools
w3schools.com β€Ί howto β€Ί howto_css_transition_hover.asp
How To - Transition on Hover
CSS transitions allows you to change property values smoothly (from one value to another), over a given duration. Add a transition effect (opacity and background color) to a button on hover:
🌐
Thoughtbot
thoughtbot.com β€Ί blog β€Ί transitions-and-transforms
CSS transitions and transforms for beginners
February 21, 2025 - For more advanced timing options, you can define a custom timing function with a cubic-bezier. ... The transition-delay property allows you to specify when the transform will start. By default, the transition starts as soon as it is triggered ...
Top answer
1 of 2
61

Add the transition properties to the element itself rather than the :hover pseudo-class version.

In doing so, the transition will take place when hovering on and off.

Updated Example

.img-blur {
  transition: all 0.35s ease-in-out;
}
.img-blur:hover {
  -moz-filter: blur(4px);
  -webkit-filter: blur(4px);
  filter: blur(4px);
}
<img src="http://i.imgur.com/Vp5StNs.png" class="img-blur" />


If you want different transition properties when hovering on/off, see this example.

  • The transition property on the element itself will take place when hovering off of the element.

  • The transition on the :hover pseudo class will take place when hovering on the element:

.img-blur {
    transition: all 0.35s ease-in-out;   /* Hover off */
}
.img-blur:hover {
    -moz-filter: blur(4px);
    -webkit-filter: blur(4px);
    filter: blur(4px);
    transition: all 1s ease-in;         /* On hover */
}
<img src="http://i.imgur.com/Vp5StNs.png" class="img-blur">


If you want text to be added on hover, take a look at either of these past answers.

  • https://stackoverflow.com/a/18322705/2680216

  • https://stackoverflow.com/a/21371665/2680216

2 of 2
0

Gotta remember you need to tell the computer what happens when it is not getting hovered over. Why you need to add a transition property into the class when its not getting hovered.

here is the CSS:

.nav__menuIcon--button {
    visibility: hidden;
    width: 24px;
    height: 24px;
    background-color: transparent;
    border-color: transparent;
    border-width: 0;
    transition: all 300ms ease-in;
}

.nav__menuIcon--button:hover {
    color: red;
    transition: all 300ms ease-in;
} 
🌐
DEV Community
dev.to β€Ί cydstumpel β€Ί css-transitions-3gdn
CSS Transitions - DEV Community
December 20, 2020 - ease-in - specifies a transition effect with a slow start Β· ease-out - specifies a transition effect with a slow end