{"id":1768,"date":"2015-11-04T10:50:15","date_gmt":"2015-11-04T16:50:15","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=1768"},"modified":"2015-11-04T10:50:15","modified_gmt":"2015-11-04T16:50:15","slug":"how-to-alter-images-using-css-filters","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/how-to-alter-images-using-css-filters\/","title":{"rendered":"How To Alter Images Using CSS Filters"},"content":{"rendered":"<p>CSS filters allow you to do some funky\u00a0stuff to HTML elements using only CSS. A fun way to take advantage of this cool tool is to use it to put filters on your images, much like the ones you would add to your images on photo editing applications like Photoshop or Instagram.\u00a0CSS filter isn&#8217;t supported on every browser yet, and it usually has to be used with\u00a0the <strong>-webkit-<\/strong> prefix, but it&#8217;s still very useful to be able to apply filters to your photos using only CSS.<\/p>\n<p>The syntax is pretty straightforward. Below, I have an image that I assigned\u00a0the class of <b>&#8220;change-me&#8221;<\/b>. All I have to do is apply the <strong>-webkit-filter<\/strong> selector to it and input the desired parameters. <!--more--><\/p>\n<div id=\"ig-sh-1\" class=\"syntax_hilite\">\r\n\r\n\t\t<div class=\"toolbar\">\r\n\r\n\t\t<div class=\"view-different-container\">\r\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\r\n\t\t\t\t\t<\/div>\r\n\r\n\t\t<div class=\"language-name\">css<\/div>\r\n\r\n\t\t\r\n\t\t<br clear=\"both\">\r\n\r\n\t<\/div>\r\n\t\r\n\t<div class=\"code\">\r\n\t\t<ol class=\"css\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">.change-me<span style=\"color: #00AA00\">&#123;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">-webkit-filter<span style=\"color: #00AA00\">:<\/span> blur<span style=\"color: #00AA00\">&#040;<\/span><span style=\"color: #933\">10px<\/span><span style=\"color: #00AA00\">&#041;<\/span><span style=\"color: #00AA00\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #00AA00\">&#125;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\r\n\r\n<\/div>\r\n\n<p>Here&#8217;s what &#8220;<strong>change-me<\/strong>&#8221; looks like without any filter:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-1770 size-medium aligncenter\" src=\"http:\/\/cssnewbie.com\/wp-content\/uploads\/2015\/11\/foliage-300x225.jpg\" alt=\"foliage\" width=\"300\" height=\"225\" \/><\/p>\n<p>And here&#8217;s how it looks with 10px of blur applied to it:<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-1771 size-medium\" src=\"http:\/\/cssnewbie.com\/wp-content\/uploads\/2015\/11\/blur-300x226.png\" alt=\"blur\" width=\"300\" height=\"226\" \/><\/p>\n<p style=\"text-align: left;\">The blur filter is the only one that takes pixel values. The rest: saturate, contrast, brightness, grayscale, sepia, invert, and opacity take number and\/or percentage values.<\/p>\n<p style=\"text-align: left;\">You can saturate (or de-saturate!) an image using the saturate filter. Use a percentage 0-100% to de-saturate the original image (0% is no saturation, 100% is the saturation value of the original image). If you want to add saturation, you can use any number over 1. The higher the number you use, the more saturated the image will get. Here&#8217;s an example of an image with only 30% of its original saturation:<\/p>\n<p style=\"text-align: center;\"><img decoding=\"async\" loading=\"lazy\" class=\"alignnone wp-image-1773 size-medium\" src=\"http:\/\/cssnewbie.com\/wp-content\/uploads\/2015\/11\/saturate-300x226.png\" alt=\"saturate\" width=\"300\" height=\"226\" \/><\/p>\n<p style=\"text-align: left;\">The code for the above image looks like this:<\/p>\n<div id=\"ig-sh-2\" class=\"syntax_hilite\">\r\n\r\n\t\t<div class=\"toolbar\">\r\n\r\n\t\t<div class=\"view-different-container\">\r\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\r\n\t\t\t\t\t<\/div>\r\n\r\n\t\t<div class=\"language-name\">css<\/div>\r\n\r\n\t\t\r\n\t\t<br clear=\"both\">\r\n\r\n\t<\/div>\r\n\t\r\n\t<div class=\"code\">\r\n\t\t<ol class=\"css\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&amp;lt<span style=\"color: #00AA00\">;<\/span>\/p&amp;gt<span style=\"color: #00AA00\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&amp;lt<span style=\"color: #00AA00\">;<\/span>p style<span style=\"color: #00AA00\">=<\/span>&amp;quot<span style=\"color: #00AA00\">;<\/span><span style=\"color: #000000;font-weight: bold\">text-align<\/span><span style=\"color: #00AA00\">:<\/span> <span style=\"color: #000000;font-weight: bold\">left<\/span><span style=\"color: #00AA00\">;<\/span>&amp;quot<span style=\"color: #00AA00\">;<\/span>&amp;gt<span style=\"color: #00AA00\">;<\/span>.change-me<span style=\"color: #00AA00\">&#123;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">-webkit-filter<span style=\"color: #00AA00\">:<\/span> saturate<span style=\"color: #00AA00\">&#040;<\/span><span style=\"color: #cc66cc\">1<\/span><span style=\"color: #00AA00\">&#041;<\/span><span style=\"color: #00AA00\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #00AA00\">&#125;<\/span>&amp;lt<span style=\"color: #00AA00\">;<\/span>\/p&amp;gt<span style=\"color: #00AA00\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&amp;lt<span style=\"color: #00AA00\">;<\/span>p style<span style=\"color: #00AA00\">=<\/span>&amp;quot<span style=\"color: #00AA00\">;<\/span><span style=\"color: #000000;font-weight: bold\">text-align<\/span><span style=\"color: #00AA00\">:<\/span> <span style=\"color: #000000;font-weight: bold\">left<\/span><span style=\"color: #00AA00\">;<\/span>&amp;quot<span style=\"color: #00AA00\">;<\/span>&amp;gt<span style=\"color: #00AA00\">;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\r\n\r\n<\/div>\r\n\n<p style=\"text-align: left;\">Want your image to look like it&#8217;s old or faded? There are CSS filters for that. Use the\u00a0<strong>sepia<\/strong> or <strong>grayscale<\/strong>\u00a0filters (each of which takes percentage values\u00a0from 0-100) to achieve the desired effect. A filter of <strong>grayscale(100%)<\/strong> was used on the example below.<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-1774 size-medium\" src=\"http:\/\/cssnewbie.com\/wp-content\/uploads\/2015\/11\/grayscale-300x225.png\" alt=\"grayscale\" width=\"300\" height=\"225\" \/><\/p>\n<p style=\"text-align: left;\">CSS filters also lets you use multiple filters at once. Let&#8217;s say you wanted to blur your image and make it a little bit brighter at the same time. \u00a0Your CSS code would need to look something like this:<\/p>\n<div id=\"ig-sh-3\" class=\"syntax_hilite\">\r\n\r\n\t\t<div class=\"toolbar\">\r\n\r\n\t\t<div class=\"view-different-container\">\r\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\r\n\t\t\t\t\t<\/div>\r\n\r\n\t\t<div class=\"language-name\">css<\/div>\r\n\r\n\t\t\r\n\t\t<br clear=\"both\">\r\n\r\n\t<\/div>\r\n\t\r\n\t<div class=\"code\">\r\n\t\t<ol class=\"css\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&amp;lt<span style=\"color: #00AA00\">;<\/span>\/p&amp;gt<span style=\"color: #00AA00\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&amp;lt<span style=\"color: #00AA00\">;<\/span>p style<span style=\"color: #00AA00\">=<\/span>&amp;quot<span style=\"color: #00AA00\">;<\/span><span style=\"color: #000000;font-weight: bold\">text-align<\/span><span style=\"color: #00AA00\">:<\/span> <span style=\"color: #000000;font-weight: bold\">left<\/span><span style=\"color: #00AA00\">;<\/span>&amp;quot<span style=\"color: #00AA00\">;<\/span>&amp;gt<span style=\"color: #00AA00\">;<\/span>.change-me<span style=\"color: #00AA00\">&#123;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">-webkit-filter<span style=\"color: #00AA00\">:<\/span> blur<span style=\"color: #00AA00\">&#040;<\/span><span style=\"color: #933\">20px<\/span><span style=\"color: #00AA00\">&#041;<\/span> brightness<span style=\"color: #00AA00\">&#040;<\/span><span style=\"color: #cc66cc\">1.5<\/span><span style=\"color: #00AA00\">&#041;<\/span><span style=\"color: #00AA00\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #00AA00\">&#125;<\/span>&amp;lt<span style=\"color: #00AA00\">;<\/span>\/p&amp;gt<span style=\"color: #00AA00\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&amp;lt<span style=\"color: #00AA00\">;<\/span>p style<span style=\"color: #00AA00\">=<\/span>&amp;quot<span style=\"color: #00AA00\">;<\/span><span style=\"color: #000000;font-weight: bold\">text-align<\/span><span style=\"color: #00AA00\">:<\/span> <span style=\"color: #000000;font-weight: bold\">left<\/span><span style=\"color: #00AA00\">;<\/span>&amp;quot<span style=\"color: #00AA00\">;<\/span>&amp;gt<span style=\"color: #00AA00\">;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\r\n\r\n<\/div>\r\n\n<p style=\"text-align: left;\">And this is what the filtered image would look like:<\/p>\n<p style=\"text-align: left;\"><img decoding=\"async\" loading=\"lazy\" class=\"wp-image-1776 size-medium aligncenter\" src=\"http:\/\/cssnewbie.com\/wp-content\/uploads\/2015\/11\/blurbrightness-300x225.png\" alt=\"blurbrightness\" width=\"300\" height=\"225\" \/><\/p>\n<p style=\"text-align: left;\">Check out\u00a0<a href=\"http:\/\/www.inserthtml.com\/2012\/06\/css-filters\/\">this page<\/a> to learn how to use even more CSS filters.<\/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>CSS filters allow you to do some funky\u00a0stuff to HTML elements using only CSS. A fun way to take advantage of this cool tool is to use it to put filters on your images, much like the ones you would [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/how-to-alter-images-using-css-filters\/\" title=\"Click to read 'How To Alter Images Using CSS Filters'\">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":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1768"}],"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=1768"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/1768\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=1768"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=1768"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=1768"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}