How to Create Different Overlay Effects using CSS? Last Updated : 30 Jul, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Overlay effects are a powerful way to enhance the visual appeal and user experience of a website. With CSS, creating various overlay effects can be achieved relatively easily, offering designers a plethora of creative possibilities. Below are the approaches to create different overlay effects using CSS:Table of Content Overlay with ColorUsing Slide OverlayOverlay Effect with ColorDefine a container div for the image with nested elements for overlay and content.Style the image container to position elements and set image dimensions.Create an overlay with a semi-transparent background using CSS.Initially, set the overlay's opacity to 0 to make it invisible. On hover, change the opacity to reveal the overlay.Position the content div within the container. Style the text content for visibility and aesthetics.Example: The example below shows how to create overlay effects with the CSS colour. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title> Overlay with Semi-Transparent Color </title> <style> body { margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; background-color: #fff; } h1 { font-family: Arial, sans-serif; text-align: center; color: rgb(23, 214, 102); margin-top: 20px; } .image-container { position: relative; display: inline-block; cursor: pointer; } .image-container img { display: block; width: 400px; height: auto; margin: 0 auto; } .overlay { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.5); opacity: 0; transition: opacity 0.3s ease; } .image-container:hover .overlay { opacity: 2; } .content { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); color: rgb(23, 214, 102); font-size: 24px; text-align: center; font-family: Arial, sans-serif; z-index: 2; } </style> </head> <body> <div class="image-container"> <h1> Hover over the image to see the overlay </h1> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240514123440/image.jpg" alt="DevOps Roadmap"> <div class="overlay"></div> <div class="content"> You Hover The Image </div> </div> </body> </html> Output:Output : Overlay with ColorUsing Slide Overlay EffectCreate an HTML document with a container div for the image and overlay.Place an image inside the container.Define styles for the body, header, and image container and Set dimensions and positioning for the image.Implement a sliding overlay effect using CSS pseudo-elements.Initially position the overlay off-screen to the left also utilize transitions for smooth animation.Trigger the overlay animation on hover using the :hover pseudo-class.Transition the overlay from off-screen to cover a portion of the image.Example : The example below shows how to create overlay effects by the slide overlay. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Hover Slide Overlay</title> <style> body { margin: 0; padding: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; background-color: #f0f0f0; } h1 { font-family: Arial, sans-serif; text-align: center; color: rgb(23, 214, 102); margin-bottom: 20px; } .slide-overlay-container { position: relative; display: inline-block; overflow: hidden; } .slide-overlay-container img { display: block; width: 400px; height: auto; margin: 0 auto; } .slide-overlay::before { content: ""; position: absolute; top: 0; left: -100%; width: 50%; height: 100%; background-color: rgba(0, 0, 0, 0.5); transition: left 0.3s ease; } .slide-overlay-container:hover .slide-overlay::before { left: 0; } </style> </head> <body> <h1>Hover Slide Overlay</h1> <div class="slide-overlay-container"> <img src= "https://media.geeksforgeeks.org/wp-content/uploads/20240514123440/image.jpg" alt="DevOps Roadmap"> <div class="slide-overlay"></div> </div> </body> </html> Output: Comment More infoAdvertise with us Next Article How to create image overlay hover slide effects using CSS ? S skaftafh Follow Improve Article Tags : Web Technologies CSS CSS-Questions Similar Reads How to create a drop shadow effect using CSS ? In this article, we are going to learn how to create a drop shadow effect using CSS. drop-shadow() is an inbuilt function used to create a blurred shadow in a given offset and color. A drop shadow effect adds depth and visual interest to elements on a web page by creating a shadow behind them. This 3 min read How to create image overlay hover slide effects using CSS ? In this article, we will learn how to make image overlay hover slide effects using CSS. When the users hover over the image, a smooth sliding overlay effect occurs. This technique gives a visual appeal with interactivity, making your website more interactive.Table of ContentFull Width Slide-In Text 4 min read How to Create Paradoxical Effect using CSS ? Paradoxical effect is the effect where the divs or the elements are placed in circular form top of each other. This type of effect is useful when you want to design a circular button that opens up when you hover and each button assigns some task and place like the top of each other. In the below exa 2 min read How to create a marquee effect using CSS ? In this article, we will be creating the marquee effect by using HTML and CSS. This effect can be created by using the <marquee> tag in HTML, but we will not use this tag as it is not widely used nowadays. We will create and design a marquee effect by using the CSS classes and styling properti 2 min read How to create icon hover effect using CSS ? To style an icon's color, size, and shadow using CSS, use the color property to set the icon's color, font size to adjust its size, and text-shadow or box-shadow for adding shadow effects, creating a visually appealing and dynamic look.Using: hover Pseudo-ClassUsing the: hover pseudo-class, you can 2 min read How to Create Embossed Text Effect using CSS ? The embossed text effect creates a 3D illusion, making text appear raised or pressed into the page. Using CSS, this effect is achieved by applying contrasting text-shadow values that simulate light and shadow, giving the text a visually elevated or indented appearance.Approach:Basic HTML Structure: 2 min read Like