<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>CSS – IMG.LY Blog</title><description>Posts tagged CSS on the IMG.LY blog.</description><link>https://img.ly/blog/tag/css/</link><language>en-us</language><image><url>https://img.ly/apple-touch-icon.png</url><title>CSS – IMG.LY Blog</title><link>https://img.ly/blog/tag/css/</link></image><atom:link href="https://img.ly/blog/tag/css/rss.xml" rel="self" type="application/rss+xml"/><generator>Astro</generator><lastBuildDate>Fri, 19 Jun 2026 11:26:07 GMT</lastBuildDate><ttl>60</ttl><item><title>How To Scale, Crop, Flip, and Filter an Image in CSS</title><link>https://img.ly/blog/how-to-scale-crop-flip-and-filter-an-image-in-css/</link><guid isPermaLink="true">https://img.ly/blog/how-to-scale-crop-flip-and-filter-an-image-in-css/</guid><description>Learn how to use CSS to perform the most common image processing manipulations.</description><pubDate>Wed, 09 Feb 2022 19:41:38 GMT</pubDate><content:encoded>&lt;p&gt;In this article, you will learn how to perform popular image processing operations in CSS. That is possible thanks to the several features introduced by CSS3, which allow you to change how the images look to end-users. To learn instead about image manipulation operations for other frameworks, you can head on here: &lt;a href=&quot;https://img.ly/blog/how-to-resize-an-image-with-javascript/&quot;&gt;React&lt;/a&gt; or &lt;a href=&quot;https://img.ly/blog/how-to-resize-an-image-with-javascript/&quot;&gt;vanilla JS&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;First, let’s delve into how image manipulation works in CSS. Then, let’s finally see the most common CSS image processing operations in action.&lt;/p&gt;
&lt;h2 id=&quot;how-css-image-manipulation-work&quot;&gt;How CSS Image Manipulation Work&lt;/h2&gt;
&lt;p&gt;CSS does not allow you to deal with files, data formats, or data transformation. In other words, CSS cannot change an image on a deep level, yet with CSS, you can determine how a browser displays elements.&lt;/p&gt;
&lt;p&gt;As a result, as opposed to what would happen when using an HTML &lt;code&gt;canvas&lt;/code&gt; element, no pixel manipulation will be executed behind-the-scene. Therefore, your CSS rules won’t affect the file that represents your image. What changes is how your image is displayed frontend-side.&lt;/p&gt;
&lt;p&gt;You can flip, blur, and crop an image in CSS, but when downloading the image with the right-click option, the image saved will always be a copy of the original image file. Read &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/Replaced_element&quot;&gt;this&lt;/a&gt; page from MDN Web Docs, if you want to learn more about this phenomenon.&lt;/p&gt;
&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;
&lt;p&gt;The CSS properties you will see are widely based on CSS3 and are not supported by Internet Explorer. To verify if your target browsers support a CSS property, visit &lt;a href=&quot;https://developer.mozilla.org/en-US/&quot;&gt;MDN Web Docs&lt;/a&gt; and explore the &lt;em&gt;Browser compatibility&lt;/em&gt; section.&lt;/p&gt;
&lt;h2 id=&quot;image-processing-in-css&quot;&gt;Image Processing in CSS&lt;/h2&gt;
&lt;p&gt;Let’s look at how to perform scaling, cropping, flipping, and filtering an image in CSS.&lt;/p&gt;
&lt;h3 id=&quot;scaling-an-image-with-object-fit-scale-down&quot;&gt;Scaling an image with &lt;code&gt;object-fit: scale-down&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit&quot;&gt;&lt;code&gt;object-fit&lt;/code&gt;&lt;/a&gt; CSS property allows you to define how the content of an HTML &lt;code&gt;&amp;#x3C;img&gt;&lt;/code&gt; element should be resized to fit its container. In particular, &lt;code&gt;scale-down&lt;/code&gt; acts as if &lt;code&gt;none&lt;/code&gt; or &lt;code&gt;contain&lt;/code&gt; were set, depending on which would result in a smaller image.&lt;/p&gt;
&lt;p&gt;When it acts like &lt;code&gt;none&lt;/code&gt;, the image will keep its original intrinsic size and not be scaled down. On the contrary, when it acts like &lt;code&gt;contain&lt;/code&gt; the image will be scaled down to fit the container while maintaining its aspect ratio.&lt;/p&gt;
&lt;p&gt;Test this CSS rule in the live demo below:&lt;/p&gt;
&lt;p&gt;In particular, this is the CSS rule where the magic happens:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;.manipulated-image&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  object-fit&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;scale-down&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  height&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;100&lt;/span&gt;&lt;span&gt;px&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;cropping-an-image-with-object-fit-and-object-position&quot;&gt;Cropping an image with &lt;code&gt;object-fit&lt;/code&gt; and &lt;code&gt;object-position&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;By employing &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/object-fit&quot;&gt;&lt;code&gt;object-fit&lt;/code&gt;&lt;/a&gt; in conjunction with &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/object-position&quot;&gt;&lt;code&gt;object-position&lt;/code&gt;&lt;/a&gt;, you can show a part of your image, just if it has been cropped. In detail, the &lt;code&gt;object-position&lt;/code&gt; CSS property allows you to specify the positioning of your &lt;code&gt;&amp;#x3C;img&gt;&lt;/code&gt; element within its container box. This happens by passing this CSS property a &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/position_value&quot;&gt;&lt;code&gt;position&lt;/code&gt;&lt;/a&gt; parameter containing from one to four values. This parameter is what defines the position of the &lt;code&gt;&amp;#x3C;img&gt;&lt;/code&gt; element.&lt;/p&gt;
&lt;p&gt;By using &lt;code&gt;object-fit&lt;/code&gt; to set how your &lt;code&gt;&amp;#x3C;img&gt;&lt;/code&gt; element should fit its container and by positioning it with &lt;code&gt;object-position&lt;/code&gt;, you can show only a part of your image as shown in the live example below:&lt;/p&gt;
&lt;p&gt;This is the CSS rule to look attention to:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;.manipulated-image&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  object-fit&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;cover&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  object-position&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;-150&lt;/span&gt;&lt;span&gt;px&lt;/span&gt;&lt;span&gt; -25&lt;/span&gt;&lt;span&gt;px&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;flipping-an-image-with-transform&quot;&gt;Flipping an image with &lt;code&gt;transform&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/transform&quot;&gt;&lt;code&gt;transform&lt;/code&gt;&lt;/a&gt; CSS property is a powerful tool that gives you the ability to rotate, scale, skew, or translate an&lt;code&gt;&amp;#x3C;img&gt;&lt;/code&gt; element. Specifically, you can flip an image by using the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/scaleX()&quot;&gt;&lt;code&gt;scaleX()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/scaleY()&quot;&gt;&lt;code&gt;scaleY()&lt;/code&gt;&lt;/a&gt; transformation functions, or by adopting the &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotateX()&quot;&gt;&lt;code&gt;rotateX()&lt;/code&gt;&lt;/a&gt; or &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/transform-function/rotateY()&quot;&gt;&lt;code&gt;rotateY()&lt;/code&gt;&lt;/a&gt; functions.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;scaleX()&lt;/code&gt; and &lt;code&gt;scaleY()&lt;/code&gt; define a transformation that resizes an HTML element along the x-axis and y-axis, respectively. Both accept a &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/number&quot;&gt;&lt;code&gt;number&lt;/code&gt;&lt;/a&gt; representing the scaling factor as a parameter. Learn how to flip an image vertically with &lt;code&gt;scaleX()&lt;/code&gt; in the example below:&lt;/p&gt;
&lt;p&gt;In detail, this is the CSS rule to flip an image vertically:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;.manipulated-image&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  transform&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;scaleX&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;-1&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Similarly, &lt;code&gt;rotateX()&lt;/code&gt; and &lt;code&gt;rotateY()&lt;/code&gt; define a transformation that rotates an HTML element without deforming it around the horizontal axis and vertical axis, respectively. Both require an &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/angle&quot;&gt;&lt;code&gt;angle&lt;/code&gt;&lt;/a&gt; representing the angle of rotation as a parameter. Now, let’s see how to flip an image vertically with &lt;code&gt;rotateY()&lt;/code&gt; in the example below:&lt;/p&gt;
&lt;p&gt;Specifically, this is what the CSS rule to flip an image vertically looks like:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;.manipulated-image&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  transform&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;rotateY&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;180&lt;/span&gt;&lt;span&gt;deg&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h3 id=&quot;filtering-an-image-with-filter&quot;&gt;Filtering an image with &lt;code&gt;filter&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/filter&quot;&gt;&lt;code&gt;filter&lt;/code&gt;&lt;/a&gt; CSS property allows you to apply visual effects on an &lt;code&gt;&amp;#x3C;img&gt;&lt;/code&gt; element. This property provides access to several built-in effects, such as &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/blur()&quot;&gt;&lt;code&gt;blur()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/grayscale()&quot;&gt;&lt;code&gt;grayscale()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/filter-function/contrast()&quot;&gt;&lt;code&gt;contrast()&lt;/code&gt;&lt;/a&gt;, and &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/CSS/filter#functions&quot;&gt;many others&lt;/a&gt;. If required, you can also define your custom image filtering functions.&lt;/p&gt;
&lt;p&gt;CSS filters are a powerful tool that is typically used to adjust how an image is displayed by the browser and shown to the end-user. Using them is really easy, as shown in the live demo below:&lt;/p&gt;
&lt;p&gt;These are the CSS rules where the filtering operations are defined:&lt;/p&gt;
&lt;pre class=&quot;astro-code github-dark&quot; tabindex=&quot;0&quot; data-language=&quot;css&quot;&gt;&lt;code&gt;&lt;span class=&quot;line&quot;&gt;&lt;span&gt;.blurred-image&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  filter&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;blur&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;2&lt;/span&gt;&lt;span&gt;px&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;.grayscale-image&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  filter&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;grayscale&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;80&lt;/span&gt;&lt;span&gt;%&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;.high-contrast-image&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;  filter&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span&gt;contrast&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;150&lt;/span&gt;&lt;span&gt;%&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;line&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;h2 id=&quot;css-only-image-editor-vs-photoeditor-sdk&quot;&gt;CSS-Only Image Editor vs PhotoEditor SDK&lt;/h2&gt;
&lt;p&gt;Image manipulation in CSS is an easy and straightforward way to manipulate how an image is displayed with no effort. On the other hand, you cannot save or export the manipulated images with CSS. This means that it is not possible to implement a file image editor based solely on CSS.&lt;/p&gt;
&lt;p&gt;Therefore, you can rely on CSS only if you are interested in changing how your images are rendered by the browser. Conversely, if you are looking for a way to manipulate your images and then export them as files, then you need a much more advanced tool. In this case, a commercial solution like IMG.LY’s &lt;a href=&quot;https://img.ly/products/photo-sdk/&quot;&gt;Photo Editor SDK&lt;/a&gt; will provide you with a complete, fast, and easy-to-use image editor.&lt;/p&gt;
&lt;p&gt;&lt;img alt=&quot;manipulate-filter-grayscale-blur-image-css-css3&quot; loading=&quot;lazy&quot; decoding=&quot;async&quot; sizes=&quot;(min-width: 600px) 600px, 100vw&quot; data-astro-image=&quot;constrained&quot; data-astro-image-pos=&quot;center&quot; width=&quot;600&quot; height=&quot;322&quot; src=&quot;https://img.ly/_astro/manipulate-filter-grayscale-blur-image-css-css3_Z1MFnx8.webp&quot; srcset=&quot;/_astro/manipulate-filter-grayscale-blur-image-css-css3_Z1MFnx8.webp 600w&quot;&gt;&lt;/p&gt;
&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Today we learned how to use CSS to control how browsers display images. In detail, we delved into how to scale, crop, flip, and filter an image in CSS. These represent the most common image manipulation operations and allow you to transform your image CSS-side. As we have learned, these operations only determine how your browser renders an image. They do not change an image as a data structure.&lt;br&gt;
This means that it is not possible to create an image editor that allows users to export manipulated images while using only CSS. So, if this is what you were looking for, you should consider adopting a fast, advanced, and ready-to-use solution – such as &lt;a href=&quot;https://www.npmjs.com/package/photoeditorsdk&quot;&gt;&lt;code&gt;PhotoEditorSDK&lt;/code&gt;&lt;/a&gt;. And you can get right into the PhotoEditorSDK or VideoEditorSDK and its myriad integrations by starting with a &lt;a href=&quot;https://img.ly/docs/cesdk/&quot;&gt;free trial over here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Thanks for reading! We hope that you found this article helpful. Feel free to reach out to us on &lt;a href=&quot;https://twitter.com/imgly&quot;&gt;Twitter&lt;/a&gt; with any questions, comments, or suggestions.&lt;/p&gt;
&lt;h3 id=&quot;to-stay-in-the-loop-with-our-latest-articles-and-case-studies-subscribe-to-our-newsletter&quot;&gt;To stay in the loop with our latest articles and case studies, subscribe to our &lt;a href=&quot;https://photoeditorsdk.us13.list-manage.com/subscribe?u=dc9f652839dbb620d14d6d28d&amp;#x26;id=04a306e4b2&quot;&gt;Newsletter&lt;/a&gt;.&lt;/h3&gt;</content:encoded><dc:creator>Antonello</dc:creator><media:content url="https://blog.img.ly/2022/02/blur-flip-manipulate-filter-image-css-css3-.png" medium="image"/><category>How-To</category><category>CSS</category><category>Web Development</category><category>Photo Editing</category><category>Image Editing</category><category>Tech</category><category>Tutorial</category></item></channel></rss>