惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
Forbes - Security
Forbes - Security
Blog — PlanetScale
Blog — PlanetScale
P
Proofpoint News Feed
Apple Machine Learning Research
Apple Machine Learning Research
Google DeepMind News
Google DeepMind News
MyScale Blog
MyScale Blog
GbyAI
GbyAI
B
Blog RSS Feed
S
SegmentFault 最新的问题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
小众软件
小众软件
The Last Watchdog
The Last Watchdog
W
WeLiveSecurity
Webroot Blog
Webroot Blog
S
Security @ Cisco Blogs
Hugging Face - Blog
Hugging Face - Blog
Microsoft Security Blog
Microsoft Security Blog
月光博客
月光博客
博客园 - 聂微东
F
Fortinet All Blogs
H
Hacker News: Front Page
A
About on SuperTechFans
Application and Cybersecurity Blog
Application and Cybersecurity Blog
C
Check Point Blog
V
V2EX
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Y
Y Combinator Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
N
News | PayPal Newsroom
Cisco Talos Blog
Cisco Talos Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The Cloudflare Blog
P
Privacy & Cybersecurity Law Blog
N
Netflix TechBlog - Medium
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recorded Future
Recorded Future
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
大猫的无限游戏
大猫的无限游戏
美团技术团队
Security Latest
Security Latest
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
I
InfoQ
Recent Announcements
Recent Announcements
The GitHub Blog
The GitHub Blog
Google Online Security Blog
Google Online Security Blog
T
The Exploit Database - CXSecurity.com

ImageKit.io Blog

Next.js Image Optimization with ImageKit Use Video as a Background in Your Next.js Project How to Fix Autoplay Video in Next.js How Durian Scaled a Visual-First Retail Experience to 350K Monthly Visitors Online How Matsmart accelerated image delivery across countries with ImageKit AI in Digital Asset Management: From Smart Workflows to Agentic Automation How Joseph Joseph unified and secured global video delivery with ImageKit How Modall powers fast, effortless media delivery across 40+ projects with ImageKit Digital Asset Management (DAM) Trends: 2026 Report How to add a poster image to Video.js player (and automate it) HLS streaming with Video.js + React Building the future of storytelling with fast, AI-powered video delivery How PushOwl delivers 100M+ image-rich notifications seamlessly with ImageKit How Homify delivers millions of interior design images seamlessly with ImageKit Better event discovery with lightning‑fast videos & images Adding video player in React Native Video player in Angular applications Crop and resize videos in React Next.js image and video upload React image and video upload React video optimization How we quadrupled our traffic to 625K monthly page views How Apollo 24|7 boosted performance & reduced costs with ImageKit Simplify your media workflows with ImageKit DAM integrations Extending Lighthouse for custom image and video optimization analysis Brand Asset Management: What is it? How does it work? WordPress Digital Asset Management Guide - Manage your WP media assets better Why Shopify retailers need a digital asset management solution DAM vs. SharePoint: Which is best for you? AI-powered Metadata and Tagging in Digital Asset Management How Hopscotch built India's largest online Kids' fashion brand with ImageKit Dropbox Vs. DAM: Which Is The Right Tool For Digital Asset Management Digital Asset Management for Photographers: A Complete Guide Why digital asset management for agencies is essential Helping both Top and Bottom Line: SaffronStays rapid, profitable growth with ImageKit How KreditBee simplified media experiences with ImageKit Google Drive alternatives for businesses (with fast-growing teams) Node.js image upload ImageKit: The Secret Ingredient in Swiggy’s Expansion Journey Streamlining the Design Approval Process: A Comprehensive Guide AV1 Codec - Complete guide for video application devs PHP image and video upload Angular image & video upload AV1 vs VP9: Which codec should you choose? Adding video player in Next.js React Video Player VP8 vs VP9 - In the context of online video delivery Exploring WebM vs MP4 7 Free Digital Asset Management Software that are not Open-Source Comparing 9 Top Digital Asset Management Tools in the Market What are Brand Standards and Why do they Matter? Boost Sales and Brand Appeal: Essential Tips for eCommerce Image Management Brand Recall: The Strategy to Create Unforgettable Brands How to upload files in HTML? Branding for Small Businesses (2025 Edition) Everything you need to know about VP9 codec Recent updates from ImageKit and what's next Best Ways to Write RFP For Digital Asset Management (+ with free RFP template) What is Brand Dilution? How to Avoid It? Explained with [Examples] The Importance of Brand Identity: Leveraging Digital Asset Management for Impact From Launch to Scale: How to Launch a Brand Campaign Digital Asset Management Requirements - What do You Need to Evaluate and How? Marketing Collateral Management: A Quick End-to-End Guide Video Content Management System: What Is It And How To Choose One? Dropbox vs. Google Drive vs. Onedrive: The Best Cloud Storage Solution How to Build Brand Trust: Get Started In 2025 Google Drive vs. Box: A Detailed Comparison How Digital Asset Management Solutions Help Protect Brand Equity A DAM Solution Can Safeguard Your Digital Intellectual Property - Here’s How WebP Vs. PNG: Which Image Format Should You Use and Why? How to Resize Images in Bootstrap Easily Progressive jpegs (PJPEG): the key to loading images faster on your website Dropbox vs. Google Drive: The Best Cloud Storage For Digital Assets Dropbox Pros & Cons In 2024: An In-Depth Analysis and Why A DAM Solution Stands Out Google Drive Vs OneDrive: The Better Storage Option For Digital Assets Manage your video assets better with video metadata Understanding DAM's Role in Strengthening Brand Identity Digital asset management strategy: What to know before creating one The Ultimate Guide To Marketing Agency Onboarding 6 Solutions To Simplify Large File Sharing Over The Web A Step-by-Step Breakdown of a Video Production Workflow 13 Digital Asset Management Use Cases You Should Know How to Conduct a Brand Audit and Manage Your Brand Assets Costly Consequences of Inconsistent Branding And How DAM Can Help Dynamic Asset Transformation: What It Is, Why You Need It, and How ImageKit Can Help Everything You Need to Know About HTML Video Autoplay How To Select Your DAM Vendor: A Complete Guide How to Boost User Experience with Smart Digital Asset Management React Image Optimization: A Guide for Web Developers Why Should DAM Be A Part Of Your MarTech Stack? Unleashing the Power of Content Repurposing with ImageKit MKV vs MP4: Which Video File Format Is Better for Your Needs? Digital Asset Management For Ecommerce: A Complete Guide How an Image Tagging Software can Transform Your Image Search How to Manage Your Content Lifecycle Effectively M4V vs MP4: Which Video Format Should You Use and Why? Why Every Business Needs An Image Management System All The Questions To Ask During A Dam Demo Which is the Best Image Format for Your Website? Uploading Multiple Files Using JavaScript: A Comprehensive Guide
Image rotation with HTML and CSS
Rahul Nanwani · 2022-08-30 · via ImageKit.io Blog

Images are crucial for conveying information and enhancing the appearance of your website. You can use them for creating stunning visuals such as product images, banners, illustrations, and more.

Sometimes you might want to rotate or flip images on your page to fit specific visual requirements for your business.

This article will discuss how to rotate and flip images in your HTML using the CSS transform operations.

Later we will look at ImageKit's real-time image transformations that will help you achieve similar effects across platforms without relying on CSS.

Image rotation and flip operations using CSS and HTML

You can apply CSS functions to an image to create transformations such as rotation, flip, and other effects. We will utilize the following CSS functions and build different effects -

  1. rotate() function
  2. scaleX() function
  3. scaleY() function

For demonstration, we have picked up the following image by Helena Lopes from Pexels.

This image has been stored in the free integrated media library offered by ImageKit.io.

ImageKit is a complete image and video management and delivery product that helps us optimize image delivery in real-time with no effort. The image stored on ImageKit is accessible here -

https://ik.imagekit.io/ikmedia/rotation-blog/suv-image_CydtbqUYa.jpg

You can sign up on ImageKit for free forever and store your images and videos there. You can also deliver optimized content with a CDN directly on your website and apps using ImageKit URLs.

Using the img tag, we can embed this image on our website.

<img src="https://ik.imagekit.io/ikmedia/rotation-blog/suv-image_CydtbqUYa.jpg" alt="Flatiron Building" />

Let's use different CSS functions to achieve different visual effects on these images.

Image Rotation using rotate() Function

As the name suggests, you can use the rotate(arg) function to rotate an image in a two-dimensional space. The image is rotated based on the argument passed to this function in CSS-supported units, such as degree, gradian, turn, or radian.

The CSS sample below rotates the image by 180 degrees:

img {
    transform: rotate(180deg);
}

The resultant image is shown below -

180-degree clockwise rotation using CSS functions
180-degree clockwise rotation using CSS functions

We can also provide a negative value to rotate the image in a counter-clockwise direction. Here we are trying to rotate an image by 40 degrees in the counter-clockwise direction.

img {
	transform: rotate(-40deg)
}
40-degree counter-clockwise rotation using CSS rotate function
40-degree counter-clockwise rotation using CSS rotate function

Similarly, you can use other values in the rotate function to rotate the image according to your requirements.

Continuously rotating the image using CSS for an animated effect

We can also use CSS's animation and keyframes properties to create an animation without using any Javascript or other third-party library.

Let's look at a simple animation where we will rotate an image continuously and set the image to complete one rotation in 6 seconds. The keyframes definition defines the rotation, whereas the animation property defines the animation's timing and repetition.


img{
  width: 300px;
  animation: rotation 6s infinite linear;
}

@keyframes rotation {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

The resulting animation looks like this -

Flip an image using the CSS transform property

The scaleX and scaleY functions can be used to flip the image horizontally or vertically, respectively. To flip the image, we must pass a negative value to these functions. A negative value  -1 also preserves the original aspect ratio while flipping.

For example, the below CSS flips the image horizontally.

img {
  -webkit-transform: scaleX(-1);
  -moz-transform: scaleX(-1);
  -o-transform: scaleX(-1);
  transform: scaleX(-1);
}

The result is a horizontally-flipped mirror image of our original image.

Horizontally-flipped image using CSS
Horizontally-flipped image using CSS

Similarly, passing a value of -1 to the scaleY function will flip the image vertically.

Dynamic Image Rotation using ImageKit

In the above examples, we rotated the image using CSS properties. CSS is restricted to use in web browsers only.

Therefore, if we have to rotate an image on any other platform, send it out in an email that doesn't support advanced CSS functions, or do not rely on CSS in general, then we need an alternative way to rotate the image.

ImageKit is a real-time transformation, optimization, and storage service that allows you to manipulate images and videos in real-time using an easy-to-use URL-transformation API.

Rotating images in real-time with the rotate parameter

Using ImageKit's transformations is simple. You just need to specify the transformation in the specified format in the URL.

To rotate the image, ImageKit provides the rt parameter. To rotate the image by 180 degrees, we need to add rt-180 transformation parameter to the URL, as shown below.

https://ik.imagekit.io/ikmedia/rotation-blog/suv-image_CydtbqUYa.jpg?tr=rt-180

The resulting image is the same as passing 180deg to the rotate function in CSS.

Image rotated in real-time using ImageKit - https://ik.imagekit.io/ikmedia/rotation-blog/suv-image_CydtbqUYa.jpg?tr=rt-180
Image rotated in real-time using ImageKit - https://ik.imagekit.io/ikmedia/rotation-blog/suv-image_CydtbqUYa.jpg?tr=rt-180

We can then use this URL directly in our HTML, our apps, or an email without having to worry about whether the end device supports CSS or not.

<img src="https://ik.imagekit.io/ikmedia/rotation-blog/suv-image_CydtbqUYa.jpg?tr=rt-180" alt="180 degree rotated building" />

We can also pass a negative value to the rt parameter to rotate the image in a counter-clockwise direction.

To rotate the image by 40 degrees in the counter-clockwise direction, we need to add rt-N40 parameter to the URL. The resulting image is the same as that obtained by passing a negative value to the rotate function in CSS.

https://ik.imagekit.io/ikmedia/rotation-blog/suv-image_CydtbqUYa.jpg?tr=rt-N40

We can also resize the image in real-time using the same URL-based image transformation API. To resize the image to 500px width while rotating it, we need to add w-500 to the above URL.

https://ik.imagekit.io/ikmedia/rotation-blog/suv-image_CydtbqUYa.jpg?tr=rt-N40,w-500

Our resulting image is rotated by 40 degrees and is resized to 500px width.

Image resized to 500px width and rotated by 40 degrees
Image resized to 500px width and rotated by 40 degrees

Note: Resizing with ImageKit is different than resizing using the width property in CSS. With ImageKit's resizing, the image downloaded over the network is already resized and is hence smaller in size. With CSS-based resizing, the full resolution image is downloaded on the user's device resulting in unnecessary bandwidth consumption and then resized on the user's device.

Conclusion

Image rotation can come in handy when the original image needs to be modified to create the right visual effects on your website or app.

You can use CSS transformation functions to achieve this with minimal effort. But this makes the image rotation specific to web and mobile web platforms that support the required CSS.

ImageKit is a real-time image transformation, optimization, and management product that allows us to manipulate images in real-time using a URL-based API. It provides the rt parameter to rotate the image and more than 50 other URL-based parameters to manipulate images and videos on websites and apps in real-time.

It also offers ample media storage and optimized delivery bandwidth for free every month. You can get started with ImageKit by signing up for a free account and taking advantage of its real-time optimizations and transformations to deliver media on your website.