Course Content
CSS Basic
0/1
CSS Selectors
0/1
CSS Comments
0/1
CSS Backgrounds
0/1
CSS Borders
0/1
CSS Outline
0/1
CSS Fonts
0/1
CSS Height and Width
0/1
CSS Margins and Paddings
0/2
CSS Icons
0/1
CSS Links
0/1
CSS Lists
0/1
CSS Tables
0/1
CSS Display Properties
0/1
CSS Max-Width Property
0/1
CSS Positioning Elements
0/1
CSS Z-Index Property
0/1
CSS Overflow
0/1
CSS Float
0/1
CSS Opacity
0/1
CSS Forms
0/1
CSS Dropdowns
0/1
CSS Buttons
0/1
CSS Media Queries
0/1
About Lesson

In CSS, there are three main types of 3D transforms that allow you to manipulate elements in a three-dimensional space. These transforms are rotateX(), rotateY(), and rotateZ(). They enable you to rotate elements around their respective axes in three-dimensional space.

This transform rotates an element around its horizontal axis, also known as the x-axis.

transform: rotateX(angle)
HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple 3D Transform Example</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    
    <div class="element1">
        <h2>Transformed div</h2>
    </div>
    
    <div class="element2">
        <h2>Normal Div</h2>
    </div>
</body>

</body>

</html>
CSS
.element1 {
    transform: rotateX(45deg);
    background-color: blueviolet;
}
.element2 {
    background-color: blueviolet;
}

This transform rotates an element around its vertical axis, also known as the y-axis.

transform: rotateY(angle)
HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple 3D Transform Example</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    
    <div class="element1">
        <h2>Transformed div</h2>
    </div>
    
    <div class="element2">
        <h2>Normal Div</h2>
    </div>
</body>

</body>

</html>
CSS
.element1 {
    transform: rotateY(45deg);
    background-color: blueviolet;
}
.element2 {
    background-color: blueviolet;
}

This transform rotates an element around its z-axis, which is perpendicular to the plane of the screen.

transform: rotatez(angle)
HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple 3D Transform Example</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    
    <div class="element1">
        <h2>Transformed div</h2>
    </div>
    
    <div class="element2">
        <h2>Normal Div</h2>
    </div>
</body>

</body>

</html>
CSS
.element1 {
    transform: rotateZ(45deg);
    background-color: blueviolet;
    width: 100px;
    height: 100px;
    
}
.element2 {
    background-color: blueviolet;
    width: 100px;
    height: 100px;

}

The CSS applies all three rotations (rotateX(), rotateY(), and rotateZ()) directly to the square element using the transform property, creating a combined 3D effect.

transform: rotateX(angle) rotateY(angle) rotateZ(angle);
HTML
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple 3D Transform Example</title>
    <link rel="stylesheet" href="style.css">
</head>

<body>
    <div class="container">
        <div class="square1">This is transformed</div>
    </div>
    <div>
        <div class="square2">This is normal div</div>
    </div>
</body>

</html>
CSS
.container {
    width: 200px;
    height: 200px;
}
.square1 {
    width: 100px;
    height: 100px;
    background-color: #3498db;
    transform: rotateX(45deg) rotateY(45deg) rotateZ(45deg);
    /* Apply all three rotations */
}
.square2 {
    width: 100px;
    height: 100px;
    background-color: #3498db;
}