img {
    border: solid 10px transparent;
}
img:hover {
    border-color: green;
}
Answer from Brandon Durham on Stack Overflow
๐ŸŒ
Prismic
prismic.io โ€บ blog โ€บ css-hover-effects
CSS Hover Effects: 40 Engaging Animations To Try
December 11, 2024 - Hover.css is a collection of CSS-powered hover effects that you can apply to images, links, SVGs, buttons, and more. It is a lightweight library that weighs 6.7kb (minified + gzipped). Hover.css provides over 110 animation effects for animating CSS properties like background colors, borders, ...
People also ask

What is CSS Hover Effect?
An element in CSS responds with transition effects when a user lingers over it. It's used to draw attention to the website's most important features and genuinely enhance user experience.
A website's user experience can be made more dynamic and user-friendly by using the CSS hover property, which offers a minor animation effect.
๐ŸŒ
codewithrandom.com
codewithrandom.com โ€บ 2023 โ€บ 10 โ€บ 20 โ€บ image-hover-border-effect-css
Image Hover Border Effect Using CSS
Which code editor do you use for Image Hover Border Effect coding?
I personally recommend using VS Code Studio, it's straightforward and easy to use.
๐ŸŒ
codewithrandom.com
codewithrandom.com โ€บ 2023 โ€บ 10 โ€บ 20 โ€บ image-hover-border-effect-css
Image Hover Border Effect Using CSS
How many types of hover effects are there in CSS?
1. Overlay.
2. Zoom
3. Shadow.
4. Background.
5. Border.
๐ŸŒ
codewithrandom.com
codewithrandom.com โ€บ 2023 โ€บ 10 โ€บ 20 โ€บ image-hover-border-effect-css
Image Hover Border Effect Using CSS
๐ŸŒ
Penpot
penpot.app โ€บ blog โ€บ how-to-create-interactive-image-hover-effects-with-css
How to create interactive image hover effects with CSS
November 13, 2025 - Pseudo-classes: The :hover pseudo-class triggers our effect when a cursor moves over an element. ... The images in the gallery use the transform and scale as above. That might seem like a lot of code for such a small effect, but most of this ...
Top answer
1 of 2
8

Add a wrapper and pseudo-element

You cannot apply any style directly to the image that will give it an inset border on hover. But you can achieve the desired effect by wrapping each image in some kind of container element and adding an ::after pseudo-element with the applied border.

.border {
  display: inline-block;
  position: relative;
}
.border::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  box-shadow: inset 0 0 0 0 rgba(255,255,255,.5);
  transition: box-shadow .1s ease;
}
.border:hover::after {
  box-shadow: inset 0 0 0 10px rgba(255,255,255,.5);
}
img {
  display: block;
  position: relative;
}
<div class="border">
  <img src="http://placehold.it/150" />
</div>

2 of 2
5

You could use an inset box-shadow e.g.

http://codepen.io/anon/pen/qdEJGj

Markup

<figure>
  <img src="http://lorempixel.com/300/300/nature/" />
</figure>

CSS

figure {
    display: inline-block;
    box-shadow: inset 0 0 0 10px rgba(255, 255, 255, .4);
}

figure img {
    display: block;
    position: relative;
    z-index: -1;
}

If you need to have this effect on hover you could also use a transition, e.g.

figure {
    display: inline-block;
    box-shadow: inset 0 0 0 10px rgba(255,255,255, 0);
    transition: all .5s 0s;
}

figure:hover {
    box-shadow: inset 0 0 0 10px rgba(255,255,255, .4);
}

figure img {
    display: block;
    position: relative;
    z-index: -1;
}

For the border I've defined a white colour with a 40% opacity. The image has a negative z-index so the inset shadow applied to the figure element can be visible (of course feel free to use a different wrapper element, if you need)


Result

๐ŸŒ
Medium
medium.com โ€บ @cwrworksite โ€บ image-hover-border-effect-using-css-b2399c8fc7d1
Image Hover Border Effect Using CSS | by Cwrcode | Medium
May 24, 2023 - Hey Learners, Today we will learn how to create an Image Hover Border Effect. When we hover it, we can also use this property For Cards, Profile cards or etc. ... This is a very simple project. We are today going 2 code. We have used internal CSS means we have inserted all the CSS in the style tag within the head tag.
๐ŸŒ
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: ... Tip: Go to our CSS Images Tutorial to learn more about how to style images.
Find elsewhere
๐ŸŒ
FooPlugins
fooplugins.com โ€บ home โ€บ wordpress gallery โ€บ quickly add hover effects to images: easy css guide
Quickly Add Hover Effects To Images: Easy CSS Guide
May 23, 2025 - Hover.css specializes in interactive hover effects with an impressive collection of 2D transitions, icon animations, and border effects that can be easily integrated into buttons or links.
๐ŸŒ
CodeWithRandom
codewithrandom.com โ€บ 2023 โ€บ 10 โ€บ 20 โ€บ image-hover-border-effect-css
Image Hover Border Effect Using CSS
November 25, 2023 - The image hover border effect is a type of CSS animation in which, as the user hovers over the image due to image hover property, a border around the image will be created.
๐ŸŒ
egghead.io
egghead.io โ€บ lessons โ€บ css-use-the-hover-css-pseudo-class-to-change-border-effects-in-multiple-ways-on-mouse-over
Use the :hover CSS pseudo-class to change border effects in multiple ways on mouse-over | egghead.io
August 27, 2020 - You can set an element's border to change on mouse-over by using the ":hover" CSS pseudo-class. The ":hover" selector creates a "hover-over" effect for an element when you mouse-over it.
๐ŸŒ
FreeFrontend
freefrontend.com โ€บ css-border-animations
57 CSS Border Animations
3 weeks ago - These snippets showcase the padding-box and border-box layering technique, providing a high-performance UI solution for cards and buttons with zero extra HTML bloat. A sophisticated squircle shape implementation for images using SVG clip-paths and pure CSS. This snippet features a fluid hover animation with spring-like physics, offering a high-performance and visually polished solution for modern frontend UI components.
๐ŸŒ
Tutorial Republic
tutorialrepublic.com โ€บ faq โ€บ apply-border-on-mouse-hover-without-affecting-the-layout-in-css.php
Apply Border on Mouse Hover without Affecting the Layout in CSS
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Add CSS Border on Hover without Moving the Elements</title> <style> ul { padding: 0; list-style: none; } ul li { float: left; margin: 10px; } ul li a, ul li a img { display: block; } ul li a:hover { border: 5px solid #333333; overflow: hidden; } ul li a:hover img{ margin: -5px; } </style> </head> <body> <ul> <li><a href="#"><img src="club.jpg" alt="Club Card"></a></li> <li><a href="#"><img src="diamond.jpg" alt="Diamond Card"></a></li> <li><a href="#"><img src="spade.jpg" alt="Spade Card"></a></li> <li><a href="#"><img src="heart.jpg" alt="Heart Card"></a></li> </ul> </body> </html>
๐ŸŒ
CSS-Tricks
css-tricks.com โ€บ animating-border
Animating Border | CSS-Tricks
December 6, 2017 - .border-button { background-repeat: no-repeat; /* background-size values will repeat so we only need to declare them once */ background-size: calc(100% - 10px) 5px, /* top & bottom */ 5px calc(100% - 10px); /* right & left */ background-position: 5px 5px, /* top */ calc(100% - 5px) 5px, /* right */ 5px calc(100% - 5px), /* bottom */ 5px 5px; /* left */ /* Since we're sizing and positioning with the above properties, we only need to set up a simple solid-color gradients for each side */ background-image: linear-gradient(0deg, #FC5185, #FC5185), linear-gradient(0deg, #FC5185, #FC5185), linear-gr
๐ŸŒ
CSS-Tricks
css-tricks.com โ€บ image-rollover-borders-that-do-not-change-layout
Image Rollover Borders That Do Not Change Layout | CSS-Tricks
October 11, 2013 - I used to encapsulate the image into a div, and make itโ€™s background change. (BTW, i know better now!) ... Itโ€™s not about showing or not-showing the border, itโ€™s about placing the border. ;) You need the space whether you make it visible or not. ... example-problem a img, #example-problem a { border: 3px solid *white*; float: left; } example-problem a:hover { border: 3px solid black; }
๐ŸŒ
The Brandsmen
thebrandsmen.com โ€บ home โ€บ journal โ€บ 10 simple css hover effects
10 Simple DIV Hover Effects | CSS Image Hover Effects
December 10, 2024 - Below I have provided a series of CSS elements that you can copy and paste into your CSS style sheet to achieve different effects on images. ... Please note that some CSS coding may not be translated by specific browsers and versions. In order to experience all CSS elements please view in the latest version of Google Chrome. If you would like detailed information on how to achieve every effect across all browsers please contact us today. ... .color img{ filter: grayscale(100%); -webkit-filter: grayscale(100%); -webkit-transition: all 1s ease; } .color img:hover{ filter: grayscale(0%); filter: gray; -webkit-filter: grayscale(0%); filter: none; transition: 1s ease; }
๐ŸŒ
Pixel Free Studio
blog.pixelfreestudio.com โ€บ home โ€บ creating css-only image hover effects
Creating CSS-Only Image Hover Effects - PixelFreeStudio Blog
July 31, 2024 - An expanding border effect can make your images pop by animating the borderโ€™s growth on hover.
๐ŸŒ
CSS-Tricks
css-tricks.com โ€บ fancy-image-decorations-masks-and-advanced-hover-effects
Fancy Image Decorations: Masks and Advanced Hover Effects | CSS-Tricks
October 28, 2022 - The font-size is initially equal to 0 ,so 1em is also equal to 0 and --_d is be equal to --d. On hover, though, the font-size is equal to a value defined by an --o variable that sets the borderโ€™s offset. This, in turn, updates the --_d variable, moving the border by the offset.
๐ŸŒ
DevSnap
devsnap.me โ€บ css-border-animations
40+ CSS Border Animations (Free)
CSS-only border animation on hover. It needs a solid background in order to work. ... A border animation in SVG using two lines. Based on Zach Saucier's animation. ... The website of Carl Philipe Brenner has some very creative and subtle animations and today we want to explore how to recreate a border animation effect ...
๐ŸŒ
SitePoint
sitepoint.com โ€บ html & css
Border effect over an image - HTML & CSS - SitePoint Forums | Web Development & Design Community
May 22, 2014 - Or you could do it more simply by using box-sizing but this shrinks the image rather than leaving it the same size. <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> <style> .border { -moz-box-sizing: border-box; -webkit-box-sizing: border-box; box-sizing: border-box; } .border:hover { border:10px solid #fff } </style> </head> <body> <div><img class="border" src="http://placehold.it/300x300/" width="300" height="300" alt="test img"></div> </body> </html>