{"id":3076,"date":"2017-08-10T18:20:19","date_gmt":"2017-08-10T23:20:19","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=2443"},"modified":"2017-08-10T18:20:19","modified_gmt":"2017-08-10T23:20:19","slug":"implement-a-blur-or-filter-effect-on-an-image-using-css3","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/implement-a-blur-or-filter-effect-on-an-image-using-css3\/","title":{"rendered":"Implement a Blur or Filter Effect on an Image Using CSS3"},"content":{"rendered":"<p>It\u2019s very common to have different hover effects on HTML elements, especially on images. The power of CSS3 and modern browsers have made this easy to achieve. CSS3 filters are a powerful property to apply filters to images, just like photoshop filters. The filter CSS property lets you apply graphical effects like blurring, sharpening, or color shifting to an element. Filters are commonly used to adjust the rendering of images, backgrounds, and borders. This short post shows how to apply blur filter and combination of blur and greyscale filter on hover on image using pure CSS.<\/p>\n<h2>HTML Markup<\/h2>\n<p>Let\u2019s start off by creating the HTML markup. Define two image tags with CSS class blur and blurGrey respectively. These CSS classes are also applied to 2 H1 heading elements. So, in case of mouse hover on H1 tag or image, the filter will be applied.<br \/>\nThe image used in this demo is taken from <a href=\"http:\/\/www.freeimages.com\/\">FreeImages<\/a>.<\/p>\n<h3 class=\"blur\">Blur on Hover<\/h3>\n<p><img decoding=\"async\" class=\"blur\" src=\"http:\/\/images.freeimages.com\/images\/small-previews\/2fe\/butterfly-1390152.jpg\" alt=\"\" \/><\/p>\n<h3 class=\"blurGrey\">Blur and GreyScale on Hover<\/h3>\n<p><img decoding=\"async\" class=\"blurGrey\" src=\"http:\/\/images.freeimages.com\/images\/small-previews\/2fe\/butterfly-1390152.jpg\" alt=\"\" \/><\/p>\n<h2>CSS<\/h2>\n<p>The filter property accepts a built-in filter function or a custom function. The function accepts a value which can be in percentage or a decimal value. To apply blur filter, we need to pass a blur function with some values. In the HTML, one of the image element and H1 element is having blur CSS class. As we want to apply blur effect on hover, therefore :hover selector is used. Inside the hover selector, pass a decimal value or percentage value to blur function. The bigger the number, the more blur would be there.<\/p>\n<pre>.blur {\n -webkit-filter: blur(0);\n filter: blur(0);\n -webkit-transition: .3s ease-in-out;\n transition: .3s ease-in-out;\n }\n .blur:hover {\n -webkit-filter: blur(3px);\n filter: blur(3px);\n }<\/pre>\n<p>The above CSS classes will apply blur effect on images. The CSS3 transition property allows you to change property values smoothly (from one value to another), over a given duration.<br \/>\nWe can also pass multiple filter functions separate by space. This is required when multiple effects are needed. For example, to apply both blur and greyscale effects on image, pass both the filters. Like,<\/p>\n<pre>.blurGrey {\n -webkit-filter: grayscale(0) blur(0);\n filter: grayscale(0) blur(0);\n -webkit-transition: .3s ease-in-out;\n transition: .3s ease-in-out;\n }\n .blurGrey:hover {\n -webkit-filter: grayscale(100%) blur(3px);\n filter: grayscale(100%) blur(3px);\n }<\/pre>\n<p>You can check out working <a href=\"https:\/\/jsfiddle.net\/4kezvey9\/embedded\/result,html,css,js\/\">demo here<\/a>. There are other built-in filter functions to create different effects. Below is a list of all such built-in filter functions to choose.<\/p>\n<p>\u2022 brightness() \u2013 To adjust the brightness.<br \/>\n\u2022 contrast() \u2013 To adjust the contrast.<br \/>\n\u2022 drop-shadow() \u2013 Apply a drop shadow effect.<br \/>\n\u2022 hue-rotate() \u2013 Applies a hue rotation on the image.<br \/>\n\u2022 invert() \u2013 Invert the samples on the image.<br \/>\n\u2022 opacity() \u2013 To manipulate the opacity of the image.<br \/>\n\u2022 saturate() \u2013 Saturates the image.<br \/>\n\u2022 sepia() \u2013 Apply sepia (redish brown color) filter on the image.<br \/>\n\u2022 url() &#8211; for applying SVG filters<\/p>\n<h2>Conclusion<\/h2>\n<p>To sum it up, we\u2019ve just learned how to apply CSS3 filters to create a blur and greyscale effect on the images and H1 heading element. CSS3 filters are like photoshop filters and can be implemented very easily with a few lines of CSS code. We also saw a list of other built-in filter functions to apply different effects. Have fun!<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>It\u2019s very common to have different hover effects on HTML elements, especially on images. The power of CSS3 and modern browsers have made this easy to achieve. CSS3 filters are a powerful property to apply filters to images, just like [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/implement-a-blur-or-filter-effect-on-an-image-using-css3\/\" title=\"Click to read 'Implement a Blur or Filter Effect on an Image Using CSS3'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[168,174,194],"tags":[49,263,372],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3076"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=3076"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/3076\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=3076"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=3076"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=3076"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}