14

I was wondering how to make an image blink in CSS, if it is possible. I want to have it blink where it is.

I would also like to change the speed but mainly I want to make it blink.

4
  • 2
    Don't think it's possible with just CSS but you could do it with Javascript. Commented Aug 24, 2012 at 19:08
  • Could you explain "blink" a little more? Do you want to brighten the image for a instant, or turn it white, or a different color?
    – Cᴏʀʏ
    Commented Aug 24, 2012 at 19:09
  • 4
    There's a reason the <blink> tag died a horrible death you know.
    – j08691
    Commented Aug 24, 2012 at 19:09
  • You can use CSS Animations and keyframes for this, but that might be a bit overkill for a simple blink. Commented Nov 20, 2013 at 10:01

3 Answers 3

60

CSS animations to the rescue!

@keyframes blink {
    0% {
        opacity: 1;
    }
    50% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}
img {
    animation: blink 1s;
    animation-iteration-count: infinite;
}

http://jsfiddle.net/r6dje/

You can make it a sharp blink by adjusting the intervals:

@keyframes blink {
    0% {
        opacity: 1;
    }
    49% {
        opacity: 1;
    }
    50% {
        opacity: 0;
    }
    100% {
        opacity: 0;
    }
}

http://jsfiddle.net/xtJF5/1/

3
  • If i hover, image wont blink. Any option?
    – KarSho
    Commented Dec 16, 2013 at 6:01
  • This is great, but it also needs code for Chrome browsers as well.
    – LauraNMS
    Commented May 7, 2014 at 15:12
  • 1
    You need also add cross-browser compability rules for keyframes (like -moz-keyframes, -webkit-keyframes etc.), animation-iteration-count (like -moz-animation-iteration-count, -webkit-animation-iteration-count etc.) and animation (-moz-animation, -webkit-animation etc).
    – 1_bug
    Commented Jan 30, 2017 at 10:18
1

use setInterval method of Javascript use it as a reference of W3Schools and then change the css from visibility:visible to visiblity:hidden we will not use display:none as it will remove the space of the image as well but we do need the space for the image for the blinking thing to work.

1
  • BTW please create a formal account on SO. It is really helpful. Thanks. I hope my answer helps. Commented Aug 24, 2012 at 19:12
1

You can do it with CSS easily. Just add below cross browser code in the CSS element of your image. You can set also timing if you change the digit in the code.

-webkit-transition:all 1s ease-in-out;
-o-transition:all 1s ease-in-out;
-ms-transition:all 1s ease-in-out;
transition:all 1s ease-in-out;
-webkit-animation:blink normal 2s infinite ease-in-out; 
-ms-animation:blink normal 2s infinite ease-in-out; 
animation:blink normal 2s infinite ease-in-out;

Not the answer you're looking for? Browse other questions tagged or ask your own question.