CSS Transitions don't work on display:block/none; You can manage to give that effect using visibility/opacity properties.

Check this example, You can manually add the transition-delay property if you really want it to add.

.main_div {
  width: 100px;
  height: 100px;
  border: thin black solid;
  position: relative;
}

.main_div .overlay_div {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  visibility: hidden;
  opacity: 0;
  transition: all 1s ease-out;
}

.main_div:hover .overlay_div {
  visibility: visible;
  opacity: 1;
  transition: all 1s ease-in;
}
<div class="main_div">
  <div class="overlay_div">
    some text
  </div>
</div>

Answer from Deepak Yadav on Stack Overflow
🌐
W3Schools
w3schools.com › howto › howto_css_transition_hover.asp
How To - Transition on Hover
Add a transition effect (opacity and background color) to a button on hover: Fade in on hover: Fade In Try it Yourself » · Fade background on hover: Fade Bg Try it Yourself » · Go to our CSS Transition Tutorial to learn more about transitions. ❮ Previous Next ❯ ·
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Learn_web_development › Howto › Solve_CSS_problems › Transition_button
How to fade a button on hover - Learn web development | MDN
.fade { background-color: #db1f48; color: white; transition: background-color 1s; } .fade:hover { background-color: #004369; } .fade:focus, .fade:active { background-color: black; transition: none; }
Discussions

html - CSS3 : Fade in on hover and Fade out when hover is gone - Stack Overflow
I have a div. When I hover on it , it should be appeared using fadeIn effect and when I remove mouse then it should gone using fadeOut effect. I have tried the below code. .main_div{ width:1... More on stackoverflow.com
🌐 stackoverflow.com
css - Fade Effect on Link Hover? - Stack Overflow
on many sites, such as http://www.clearleft.com, you'll notice that when the links are hovered over, they will fade into a different color as opposed to immediately switching, the default action. I More on stackoverflow.com
🌐 stackoverflow.com
css - Fade in fade out on image hover using CSS3? - Stack Overflow
I was wondering if it was possible to state an unhover class at all on an image? What I am trying to achieve is when someone hovers over an image it will fade in and then when they unhover it fade... More on stackoverflow.com
🌐 stackoverflow.com
How to fade in text on hover?
They're basically just called hover effects. If you just Google "CSS image hover effects" you'll get a bazillion hits. This is ancient, but has tons of examples to browse through https://tympanus.net/Development/HoverEffectIdeas/index.html More on reddit.com
🌐 r/css
4
0
February 26, 2024
People also ask

How do you fade an image on hover with CSS?
Set the default state to opacity 1, then change it on :hover, for example to 0.7, and add transition: opacity 0.3s ease-in-out for a smooth fade.
🌐
wppoland.com
wppoland.com › blog › css image hover effect - smooth fade transition tutorial
CSS hover fade effect - change fade out on mouse over (copy-paste ...
How do you create a smooth CSS hover transition?
Use the CSS transition property with a specific animatable property such as opacity or transform, a short duration like 0.2s to 0.3s, and an ease or ease-in-out timing function.
🌐
wppoland.com
wppoland.com › blog › css image hover effect - smooth fade transition tutorial
CSS hover fade effect - change fade out on mouse over (copy-paste ...
How do you change the fade out effect on mouse over with CSS?
Add transition: opacity 0.3s ease-in-out to the element, then set a lower opacity value on the :hover pseudo-class. The browser handles the smooth fade animation automatically without JavaScript.
🌐
wppoland.com
wppoland.com › blog › css image hover effect - smooth fade transition tutorial
CSS hover fade effect - change fade out on mouse over (copy-paste ...
🌐
Squarespace Forum
forum.squarespace.com › home › customize with code › image hover fade out
Image Hover Fade Out - Customize with code - Squarespace Forum
December 16, 2022 - Hi, I am using the css code below to add a hover fade effect on my images. However, the images fade out very quickly. Any idea if there is a line I can add to make it fade out slowly when the cursor is taken off the image? .image-block:hover { background-color: #00000; opacity: 0.6; transition: a...
🌐
W3Schools
w3schools.com › howto › howto_css_fading_buttons.asp
How To - Fading Buttons
Fade in on hover: Fade In Try it Yourself » · Fade out on hover: Fade Out Try it Yourself » · Fade background on hover: Fade Bg Try it Yourself » · Go to our CSS Buttons Tutorial to learn more about how to style buttons. ❮ Previous Next ❯ · ★ +1 · Sign in to track progress ·
Top answer
1 of 4
333

Nowadays people are just using CSS3 transitions because it's a lot easier than messing with JS, browser support is reasonably good and it's merely cosmetic so it doesn't matter if it doesn't work.

Something like this gets the job done:

a {
  color:blue;
  /* First we need to help some browsers along for this to work.
     Just because a vendor prefix is there, doesn't mean it will
     work in a browser made by that vendor either, it's just for
     future-proofing purposes I guess. */
  -o-transition:.5s;
  -ms-transition:.5s;
  -moz-transition:.5s;
  -webkit-transition:.5s;
  /* ...and now for the proper property */
  transition:.5s;
}
a:hover { color:red; }

You can also transition specific CSS properties with different timings and easing functions by separating each declaration with a comma, like so:

a {
  color:blue; background:white;
  -o-transition:color .2s ease-out, background 1s ease-in;
  -ms-transition:color .2s ease-out, background 1s ease-in;
  -moz-transition:color .2s ease-out, background 1s ease-in;
  -webkit-transition:color .2s ease-out, background 1s ease-in;
  /* ...and now override with proper CSS property */
  transition:color .2s ease-out, background 1s ease-in;
}
a:hover { color:red; background:yellow; }

Demo here

2 of 4
9

I know in the question you state "I assume JavaScript is used to create this effect" but CSS can be used too, an example is below.

CSS

.fancy-link {
   color: #333333;
   text-decoration: none;
   transition: color 0.3s linear;
   -webkit-transition: color 0.3s linear;
   -moz-transition: color 0.3s linear;
}

.fancy-link:hover {
   color: #F44336;
}

HTML

<a class="fancy-link" href="#">My Link</a>

And here is a JSFIDDLE for the above code!


Marcel in one of the answers points out you can "transition multiple CSS properties" you can also use "all" to effect the element with all your :hover styles like below.

CSS

.fancy-link {
   color: #333333;
   text-decoration: none;
   transition: all 0.3s linear;
   -webkit-transition: all 0.3s linear;
   -moz-transition: all 0.3s linear;
}

.fancy-link:hover {
   color: #F44336;
   padding-left: 10px;
}

HTML

<a class="fancy-link" href="#">My Link</a>

And here is a JSFIDDLE for the "all" example!

Find elsewhere
🌐
CodePen
codepen.io › caseydennison › pen › oggdQa
Simple CSS Fade Transition on Hover
div { background: url("http://www.theabsolutelongestwebdomainnameinthewholegoddamnfuckinguniverse.com/wp-content/uploads/2010/08/hot_chick.jpg"); width: 600px; height: 400px; margin: 0 auto; } .hover { background: #66FF33; opacity: 0; top: 0; left: 0; transition: opacity .25s ease-in-out; -moz-transition: opacity .25s ease-in-out; -webkit-transition: opacity .25s ease-in-out; } div:hover > .hover { opacity: 0.4; }
🌐
Phppot
phppot.com › css › html-element-hover-fade-effect-using-css
HTML Element Hover Fade Effect using CSS - Phppot
<html> <head> <title>HTML Element Hover Fade Effect using CSS</title> <style> .fadding-photo:hover { opacity:0.4;} </style> </head> <body> <img class="fadding-photo" src="fading-photo.png" /> <img class="fadding-photo" src="fading-photo1.png" /> <img class="fadding-photo" src="fading-photo2.png" /> </body> </html>
🌐
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 - How do you change the fade out effect on mouse over with CSS? ... Use the CSS transition property with a specific animatable property such as opacity or transform, a short duration like 0.2s to 0.3s, and an ease or ease-in-out timing function. ... Set the default state to opacity 1, then change it on :hover, for example to 0.7, and add transition: opacity 0.3s ease-in-out for a smooth fade.
🌐
YouTube
youtube.com › codenewbies
CSS Text fade in and out on hover | CSS Animation Examples - YouTube
CSS Text fade in and out on hover | CSS Animation ExamplesFollow this Channel On :-----------------------------------------Facebook: https://tinyurl.com/uh8b...
Published   December 1, 2022
Views   1K
🌐
Reddit
reddit.com › r/css › how to fade in text on hover?
r/css on Reddit: How to fade in text on hover?
February 26, 2024 -

Usually I would just look it up but I genuinely dont know what to call this. Its a really common thing you see on a lot of sites sometimes where when you hover over an image a small bit of shade and text fades in at the bottom. More specifically, hover on the images on this site: https://www.midjourney.com/explore?tab=random to know what I'm talking about. I tried to inspect the code but it honestly looks so confusing to me and I have a feeling there's a simpler way to do it, I just have no idea how.

This might be a stupid question but my web dev classes only went over basic stuff, I know nothing about transitions and animations and stuff like that.

🌐
Squarespace Forum
forum.squarespace.com › home › customize with code › other › custom css fade in on hover
Custom CSS fade in on hover - Other - Squarespace Forum
June 23, 2024 - Hey everyone, I am trying to do some CSS based animations such as fade in and fade out. I have the base plan that has no code injection so I am sticking to CSS. I want an image to start off as invisible/hidden and then with an on-click/on-hover fade the image in. I found this code that seems to w...
🌐
Iamleenalavanya
iamleenalavanya.github.io › a-simple-fade-in-fade-out-trick
Fade-In Fade-Out Hover Effect Using CSS Transitions – Leena Lavanya
.element_parent:hover .element { opacity: 1; /* now it's visible */ /* and scale(1) so it takes up the space it's supposed to */ transform: scale(1); /* again, the confusing bit */ transition: transform 0s, opacity 0.3s; }
🌐
HubSpot
blog.hubspot.com › home › website › how to add a css fade-in transition animation to text, images, scroll & hover
How to Add a CSS Fade-in Transition Animation to Text, Images, Scroll & Hover
May 1, 2025 - For example, you could set an image to start at 50% opacity and increase to 100% opacity over the duration of one second when a user hovers over it. ... See the Pen CSS Fade-in Transition on Hover by HubSpot (@hubspot) on CodePen.
🌐
GeeksforGeeks
geeksforgeeks.org › css › how-to-fade-a-button-on-hover-using-css
How to Fade a Button on Hover using CSS ? - GeeksforGeeks
July 23, 2025 - In this approach, we are using a linear gradient with RGBA Value as the background for the button to achieve a fading effect on hover. The linear-gradient function defines a smooth transition between two colors, creating an appealing gradient.
🌐
Trys Mudford
trysmudford.com › blog › fade-out-siblings-css-trick
Fading out siblings on hover in CSS | Trys Mudford
April 18, 2019 - But, if we tell the child element to listen to the mouse again with pointer-events: auto; we get a neat effect where the hover events only run on the children, but still trigger the :hover pseudo selector on the parent: .parent { pointer-events: none; } .parent > * { pointer-events: auto; } All together, here’s the code for the above example: .fade-out-siblings { --gutter: 2.5rem; background: var(--gradient-blue); text-align: center; grid-gap: var(--gutter); padding: var(--gutter); display: grid; margin: 2rem 0; pointer-events: none; } .fade-out-siblings > * { box-shadow: 0 2px 30px rgba(0,
🌐
egghead.io
egghead.io › lessons › css-use-hover-css-pseudo-class-with-opacity-property-to-create-fade-in-fade-out-effect
Use :hover CSS Pseudo-Class with Opacity Property to Create 'Fade-in'/'fade-Out' Effect | egghead.io
By utilizing the :hover selector, you can set the opacity of an element to change on mouse-over to create a "fade in" or "fade out" effect.
Published   August 25, 2020
🌐
W3Schools
w3schools.com › howto › howto_css_image_overlay.asp
How To Create Image Hover Overlay Effects
Learn how to create a fading overlay effect to an image, on hover: Fade in text: Hello World Try it Yourself » · Fade in a box: John Try it Yourself » · Tip: Go to our CSS Images Tutorial to learn more about how to style images. Also check out: Image Overlay Slide, Image Overlay Zoom, Image Overlay Title and Image Overlay Icon.
🌐
Orangeable
orangeable.com › css
CSS Fade In Transition: Text, Images, Scroll & Hover - Orangeable
July 8, 2023 - Learn how to create a fade in transition with CSS for text and image elements, on scroll, and on mouse hover.