close
The Wayback Machine - https://web.archive.org/web/20240927181718/https://www.geeksforgeeks.org/css-3d-transforms/
Open In App

CSS 3D Transforms

Last Updated : 04 Aug, 2023
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

It allows changing elements using 3D transformations. In 3D transformation, the elements are rotated along X-axis, Y-axis, and Z-axis. There are three main types of transformation which are listed below:

  • rotateX()
  • rotateY()
  • rotateZ()

The rotateX() Method: This rotation is used to rotate an element around X-axis at a given degree. 

Example: This example shows the use of the rotateX() method.

html




<!DOCTYPE html>
<html>
 
<head>
    <title>3D Transformation</title>
    <style>
        .normal_div {
            width: 300px;
            height: 150px;
            color: white;
            font-size: 25px;
            background-color: green;
            border: 1px solid black;
            margin-bottom: 20px;
        }
 
        #rotateX {
            width: 300px;
            height: 150px;
            color: white;
            font-size: 25px;
            background-color: green;
            border: 1px solid black;
            -webkit-transform: rotateX(180deg);
            /* Safari */
            transform: rotateX(180deg);
            /* Standard syntax */
 
        }
 
        .gfg {
            font-size: 40px;
            font-weight: bold;
            color: #090;
        }
 
        .geeks {
            font-size: 25px;
            font-weight: bold;
            margin: 20px 0;
        }
    </style>
</head>
 
<body>
    <center>
        <div class="gfg">
            GeeksforGeeks
        </div>
        <div class="geeks">
            rotateX() Method
        </div>
        <div class="normal_div">
            Div Contents...
        </div>
        <div id="rotateX">
            180 degree rotated contents...
        </div>
    </center>
</body>
 
</html>


Output:

 rotate x 

The rotateY() Method: This method is used to rotate an element around Y-axis at given degrees. 

Example: This example shows the use of the rotateY() method.

html




<!DOCTYPE html>
<html>
 
<head>
    <title>3D Transformation</title>
    <style>
        .normal_div {
            width: 200px;
            color: white;
            font-size: 25px;
            height: 100px;
            background-color: green;
            border: 1px solid black;
            margin-bottom: 20px;
        }
 
        #rotateY {
            width: 200px;
            color: white;
            font-size: 25px;
            height: 100px;
            background-color: green;
            border: 1px solid black;
            -webkit-transform: rotateY(180deg);
            /* Safari */
            transform: rotateY(100deg);
            /* Standard syntax */
        }
 
        .gfg {
            font-size: 40px;
            font-weight: bold;
            color: #090;
        }
 
        .geeks {
            font-size: 25px;
            font-weight: bold;
            margin: 20px 0;
        }
    </style>
</head>
 
<body>
    <center>
        <div class="gfg">
            GeeksforGeeks
        </div>
        <div class="geeks">
            rotateY() Method
        </div>
        <div class="normal_div">
            Div Contents...
        </div>
        <div id="rotateY">
            180 degree rotated div contents...
        </div>
    </center>
</body>
 
</html>


Output:

 rotate y 

The rotateZ() Method: This method is used to rotate an element around Z-axis at a given degree. 

Example: This example shows the use of the rotateZ() method.

html




<!DOCTYPE html>
<html>
 
<head>
    <title>3D Transformation</title>
    <style>
        .normal_div {
            width: 200px;
            height: 100px;
            font-size: 25px;
            color: white;
            background-color: green;
            border: 1px solid black;
        }
 
        #rotateZ {
            width: 200px;
            height: 100px;
            color: white;
            font-size: 25px;
            background-color: green;
            border: 1px solid black;
            -webkit-transform: rotateZ(90deg);
            /* Safari */
            transform: rotateZ(90deg);
            /* Standard syntax */
        }
 
        .gfg {
            font-size: 40px;
            font-weight: bold;
            color: #090;
        }
 
        .geeks {
            font-size: 25px;
            font-weight: bold;
            margin: 20px 0;
        }
    </style>
</head>
 
<body>
    <center>
        <div class="gfg">
            GeeksforGeeks
        </div>
        <div class="geeks">
            rotateZ() Method
        </div>
        <div class="normal_div">
            Div Contents...
        </div>
        <div id="rotateZ">
            90 degree rotated contents...
        </div>
    </center>
</body>
 
</html>


Output:

 rotate z



Previous Article
Next Article

Similar Reads

Tailwind CSS Transforms Complete Reference
Tailwind CSS is a highly customizable, low-level CSS framework that gives you all of the buildings blocks that you need. Tailwind CSS Transform utilities are used to control the transform behavior of any element. This class is used to transform the element like rotation, scaling, translating the element. Tailwind CSS Class Description Example Trans
1 min read
CSS 2D Transforms
A transformation in CSS is used to modify an element by its shape, size and position. It transforms the elements along the X-axis and Y-axis. There are 6 main types of transformation which are listed below: translate()rotate()scale()skewX()skewY()matrix()We will implement all these functions & will understand their concepts through the examples
5 min read
How to transforms JSON object to pretty-printed JSON using Angular Pipe ?
JSON stands for JavaScript Object Notation. It is a format for structuring data. This format is used by different web applications to communicate with each other. In this article, we will see How to use pipe to transform a JSON object to pretty-printed JSON using Angular Pipe. It meaning that it will take a JSON object string and return it pretty-p
3 min read
Difference between bootstrap.css and bootstrap-theme.css
Bootstrap is an HTML, CSS and JS front-end-framework used for developing responsive and mobile-first projects on the web. It is the framework that comes up with predefined terms, thus giving you the ability to use these codes instead of having to create the codes from scratch. It is a collection of HTML, CSS and JS code that is designed to help bui
5 min read
Which CSS framework is better Tailwind CSS or Bootstrap ?
In this article, we will see which CSS framework is better tailwind CSS or bootstrap. Both are widely used CSS frameworks for styling the front end. We will understand each one of them in detail. Both frameworks have their own pros and cons so it depends upon the type of application you are going to build and accordingly you can choose the best fra
5 min read
CSS Cheat Sheet - A Basic Guide to CSS
What is CSS? CSS i.e. Cascading Style Sheets is a stylesheet language used to describe the presentation of a document written in a markup language such as HTML, XML, etc. CSS enhances the look and feel of the webpage by describing how elements should be rendered on screen or in other media. What is a CSS Cheat Sheet? CSS Cheat Sheet provides you wi
13 min read
How to identify unused CSS definitions from multiple CSS files in a project ?
In this article, we will learn how to identify unused CSS definitions from multiple CSS files in a project. What are unused CSS definitions? Unused CSS definitions are the stylesheets that are completely useless for rendering and loading the page. If you remove these unused CSS definitions then nothing will happen to your webpage. Why you should re
2 min read
Create a CSS Fireflies background using HTML/CSS
In this article, we will see how to create the CSS Fireflies background using HTML & CSS, along with understanding its implementation through the illustration. The CSS fireflies effect can be created by utilizing the CSS animation and we will implement 3 animations to achieve the fireflies effect. To create randomness, we used different animati
7 min read
Using Primer CSS - A Simple and Transparent CSS Library for Web Development
Cascading Style Sheets (CSS) is a style sheet language used to describe the presentation of a document written in HTML or XML. CSS helps you to control the layout and appearance of web pages. In this article, we will discuss the concept of Primer CSS, a CSS library that provides a simple and easy-to-use set of styles for web development. Obvious an
3 min read
How to Add a @tailwind CSS Rule for CSS Checker ?
Tailwind CSS is basically a Utility first CSS framework for building rapid custom UI. It is a highly customizable, low-level CSS framework that gives you all of the building blocks that you need. Also, it is a cool way to write inline styling and achieve an awesome interface without writing a single line of your own CSS. In this article, we will ex
4 min read
CSS pseudo elements every CSS developer should know
CSS pseudo-elements are used to add special effects/styles to a specific part of the selected elements. A CSS selector selects the HTML element(s) for styling purposes. CSS selectors select HTML elements according to its id, class, type, attribute etc. For example, the ::before and ::after pseudo-elements can be used to insert content before or aft
5 min read
CSS Complete Guide - A to Z CSS Concepts
What is CSS ? CSS stands for "Cascading Style Sheet". It is used to style HTML Documents. CSS simplifies the process of making web pages presentable. It describes how web pages should look it prescribes colors, fonts, spacing, and much more. What is CSS Complete Guide ? CSS Complete Guide is a list of A to Z CSS concepts from beginner to advanced l
5 min read
Styling React Components: CSS vs CSS-in-JS
When it comes to styling React components, developers often face the dilemma of choosing between traditional CSS and CSS-in-JS solutions. Both approaches offer unique advantages and drawbacks, influencing how developers design and maintain their application's user interface. In this article, we delve into the differences between CSS and CSS-in-JS,
5 min read
How to use CSS Animations with Tailwind CSS ?
Tailwind CSS classes are used to style elements and apply animations effortlessly. Utilize Tailwind's animation utility classes to add dynamic visual effects. Combine Tailwind CSS with custom CSS animations for versatile and engaging web designs. Table of Content Tailwind CSS Animation Utility ClassesCSS Animations with Tailwind CSS and JavaScriptT
3 min read
How to Play and Pause CSS Animations using CSS Custom Properties ?
In this article, we will see how to control CSS animations using custom properties, along with knowing their implementation through examples. CSS Animations are the automatic transitions that can be made on the web page which lets an element change from one style to another. CSS Custom Properties are variables defined by CSS developers that contain
5 min read
How to use CSS in different dimension (CSS-in-JS) ?
CSS is awesome and easy to get started with, but front-end applications have been scaling at a massive and complex rate that doesn't make the current CSS designed for the job. CSS-in-JS is a real deal and in many ways, is very much the best nowadays when it comes to building and styling applications on the web. What is CSS-in-JS: Just as the name i
6 min read
Difference between CSS Grid and CSS Flexbox
GridCSS Grid Layout, is a two-dimensional grid-based layout system with rows and columns, making it easier to design web pages without having to use floats and positioning. Like tables, grid layout allow us to align elements into columns and rows. To get started you have to define a container element as a grid with display: grid, set the column and
4 min read
How to Override the CSS Properties of a Class using another CSS Class?
To override CSS properties with another class, use the `!important` directive in CSS, emphasizing a style's importance, and overriding others. Applying a new class to an element replaces or modifies styles from its original class, allowing targeted adjustments to appearance, layout, or behavior. Below are the approaches to override CSS properties o
3 min read
Primer CSS Spacing
Primer CSS is a free open-source CSS framework that is built with the GitHub design system to provide support to the broad spectrum of Github websites. It creates the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approa
4 min read
CSS Selectors Complete Reference
CSS selectors are used to select HTML elements based on their element name, id, class, attribute, and many more. Example: Below the HTML/CSS code shows the functionality of ::after selector. C/C++ Code <!DOCTYPE html> <html> <head> <style> p::after { content: " - Remember this"; background-color: blue; } </style
4 min read
Foundation CSS Slider
Foundation CSS is an open-source and responsive front-end framework created by ZURB in September 2011 that makes it simple to create stunning responsive websites, apps, and emails that operate on any device. Many companies, like Facebook, eBay, Mozilla, Adobe, and even Disney, use it. The framework is based on bootstrap, which is similar to SaaS. T
3 min read
CSS | Percentage Value
It represents by <percentage > takes a number as a parameter. It is used to define the relative size to the parent size. With the help of this, you can adjust all the HTML-CSS elements. In CSS, many properties that take a percentage as parameters such as padding, width, height, margin, and font-size. Syntax: <Percentage> It takes a numb
2 min read
How to change cursor color using CSS ?
In this article, we will see how to change the cursor color in the input fields using CSS. To change the cursor color, we will use caret-color property. This property is used to set the color of the cursor for input fields, textarea, or other editable areas. Syntax: caret-color: auto|color; Parameters: auto: It has a default value. It uses the curr
2 min read
Onsen UI CSS Component Material Tabbar (Icon and Label)
Onsen UI CSS is used to create beautiful HTML components. It is one of the most efficient ways to create HTML5 hybrid components compatible with mobile and desktop. Onsen UI CSS Components are pre-built CSS components that may be used to create adaptive and attractive user interface layouts rapidly. Onsen UI CSS Component Material Tabbar (Icon and
3 min read
What is the difference between “word-break: break-all” versus “word-wrap: break-word” in CSS ?
The word-break property in CSS is used to specify how a word should be broken or split when reaching the end of a line. The word-wrap property is used to split/break long words and wrap them into the next line. Difference between the "word-break: break-all;" and "word-wrap: break-word;" word-break: break-all; It is used to break the words at any ch
2 min read
Primer CSS Flexbox Align Items
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Primer CSS Flexbox Align Items used to align items on the cross axis. The cross axis al
3 min read
Primer CSS Grow x Animation
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by Object-Oriented CSS principles, functional CSS, an
2 min read
How to hide an element when printing a web page using CSS?
The media query is used to hide an element when printing web pages. Use @media print query and set the visibility hidden to that element that needs to hide at printing. Example 1: In this example, hide the element h1 at printing time. To hide the element h1 use media query and set visibility:hidden. C/C++ Code <!DOCTYPE html> <html>
1 min read
Primer CSS Progress with multiple values
Primer CSS is a free open-source CSS framework that is built upon systems that create the foundation of the basic style elements such as spacing, typography, and color. This systematic method makes sure our patterns are steady and interoperable with every other. Its approach to CSS is influenced by Object-Oriented CSS principles, functional CSS, an
2 min read
How to specify the width of the border image using CSS?
In this article, we will set the width of the border image using CSS. To set the width of the border image, we use CSS border-image-width property. The border-image-width property is used to set the width of the border-image. It can be set by providing multiple values. If only one value is provided, it is applied to all four sides.When two values a
2 min read