- CSS - Home
- CSS - Roadmap
- CSS - Introduction
- CSS - Syntax
- CSS - Inclusion
- CSS - Types
- CSS - Measurement Units
- CSS - Selectors
- CSS - Colors
- CSS - Backgrounds
- CSS - Fonts
- CSS - Text
- CSS - Images
- CSS - Links
- CSS - Tables
- CSS - Borders
- CSS - Border Block
- CSS - Border Inline
- CSS - Margins
- CSS - Lists
- CSS - Padding
- CSS - Cursor
- CSS - Outlines
- CSS - Dimension
- CSS - Scrollbars
- CSS - Inline Block
- CSS - Dropdowns
- CSS - Visibility
- CSS - Overflow
- CSS - Clearfix
- CSS - Float
- CSS - Arrows
- CSS - Resize
- CSS - Quotes
- CSS - Order
- CSS - Position
- CSS - Hyphens
- CSS - Hover
- CSS - Display
- CSS - Focus
- CSS - Zoom
- CSS - Translate
- CSS - Height
- CSS - Hyphenate Character
- CSS - Width
- CSS - Opacity
- CSS - Z-Index
- CSS - Bottom
- CSS - Navbar
- CSS - Overlay
- CSS - Forms
- CSS - Align
- CSS - Icons
- CSS - Image Gallery
- CSS - Comments
- CSS - Loaders
- CSS - Attr Selectors
- CSS - Combinators
- CSS - Root
- CSS - Box Model
- CSS - Counters
- CSS - Clip
- CSS - Writing Mode
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - Inset
- CSS - Isolation
- CSS - Overscroll
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - Pointer Events
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - Max Block Size
- CSS - Min Block Size
- CSS - Mix Blend Mode
- CSS - Max Inline Size
- CSS - Min Inline Size
- CSS - Offset
- CSS - Accent Color
- CSS - User Select
- CSS - Cascading
- CSS - Universal Selectors
- CSS - ID Selectors
- CSS - Group Selectors
- CSS - Class Selectors
- CSS - Child Selectors
- CSS - Element Selectors
- CSS - Descendant Selectors
- CSS - General Sibling Selectors
- CSS - Adjacent Sibling Selectors
- CSS Advanced
- CSS - Grid
- CSS - Grid Layout
- CSS - Flexbox
- CSS - Visibility
- CSS - Positioning
- CSS - Layers
- CSS - Pseudo Classes
- CSS - Pseudo Elements
- CSS - @ Rules
- CSS - Text Effects
- CSS - Paged Media
- CSS - Printing
- CSS - Layouts
- CSS - Validations
- CSS - Image Sprites
- CSS - Important
- CSS - Data Types
- CSS3 Advanced Features
- CSS - Rounded Corner
- CSS - Border Images
- CSS - Multi Background
- CSS - Color
- CSS - Gradients
- CSS - Box Shadow
- CSS - Box Decoration Break
- CSS - Caret Color
- CSS - Text Shadow
- CSS - Text
- CSS - 2d transform
- CSS - 3d transform
- CSS - Transition
- CSS - Animation
- CSS - Multi columns
- CSS - Box Sizing
- CSS - Tooltips
- CSS - Buttons
- CSS - Pagination
- CSS - Variables
- CSS - Media Queries
- CSS - Functions
- CSS - Math Functions
- CSS - Masking
- CSS - Shapes
- CSS - Style Images
- CSS - Specificity
- CSS - Custom Properties
- CSS Responsive
- CSS RWD - Introduction
- CSS RWD - Viewport
- CSS RWD - Grid View
- CSS RWD - Media Queries
- CSS RWD - Images
- CSS RWD - Videos
- CSS RWD - Frameworks
- CSS References
- CSS Interview Questions
- CSS Online Quiz
- CSS Online Test
- CSS Mock Test
- CSS - Quick Guide
- CSS - Cheatsheet
- CSS - Properties References
- CSS - Functions References
- CSS - Color References
- CSS - Web Browser References
- CSS - Web Safe Fonts
- CSS - Units
- CSS - Animation
- CSS Resources
- CSS - Useful Resources
- CSS - Discussion
CSS - 3D Transforms
CSS transform are used to animate elements in three-dimensional space by using properties like translate, scale and rotate. In other words, these functions let you rotate, scale, and move elements along the X, Y, and Z axes, adding depth and perspective to your designs.
Table of Contents
CSS 3D Translate()
CSS translate3d() function moves an element in 3D space by specifying offsets along the X, Y, and Z axes, where the Z-axis controls depth (distance towards or away from the viewer). The following example shows a box that moves in 3D space when hovered over. The perspective property is used to give a sense of depth for 3d effect.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
height: 300px;
display: flex;
justify-content: center;
align-items: center;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
/* Container with Perspective */
.container {
perspective: 800px;
}
/* The Box Element */
.box {
width: 200px;
height: 200px;
background-color: #4CAF50;
color: white;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5em;
border-radius: 10px;
/* Initial 3D Transformation */
transform: translate3d(50px, 50px, 100px)
rotateX(15deg) rotateY(25deg);
transition: transform 0.6s ease;
}
/* Hover State with Different 3D Transformation */
.box:hover {
transform: translate3d(-50px, -50px, -100px);
background-color: #2ecc71;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<div class="box">
3D Box
</div>
</div>
</body>
</html>
CSS 3D Rotate()
CSS rotate3d() function allows you to rotate an element around a specified axis in 3D space by defining the X, Y, and Z components of the rotation vector and the angle of rotation. Here is an example showing a box that rotates in 3D space when we hover over it, creating a dynamic visual effect.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
height: 300px;
display: flex;
justify-content: center;
align-items: center;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
/* Container with Perspective */
.container {
perspective: 800px;
}
/* The Box Element */
.box {
width: 200px;
height: 200px;
background-color: #4CAF50;
color: white;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5em;
border-radius: 10px;
/* Initial 3D Rotation */
transform: rotate3d(1, 1, 1, 45deg);
transition: transform 0.6s ease;
}
/* Hover State with Different 3D Rotation */
.box:hover {
transform: rotate3d(1, 1, 0, -45deg);
background-color: #2ecc71;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<div class="box">
3D Box
</div>
</div>
</body>
</html>
CSS 3D Scale()
CSS scale3d() function scales an element in 3D space by specifying scaling factors along the X, Y, and Z axes, allowing for uniform or non-uniform scaling. The following example shows a box that scales in 3D space when hovered over, creating a visually appealing zoom effect.
Example
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
height: 300px;
display: flex;
justify-content: center;
align-items: center;
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
/* Container with Perspective */
.container {
perspective: 800px;
}
/* The Box Element */
.box {
width: 150px;
height: 150px;
background-color: #4CAF50;
color: white;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.5em;
border-radius: 10px;
/* Initial 3D Scaling */
transform: scale3d(1, 1, 1) rotate3d(1, 1, 0, -45deg);
transition: transform 0.6s ease;
}
/* Hover State with Different 3D Scaling */
.box:hover {
transform: scale3d(1.5, 1.5, 0.5);
background-color: #2ecc71;
cursor: pointer;
}
</style>
</head>
<body>
<div class="container">
<div class="box">
3D Box
</div>
</div>
</body>
</html>
CSS 3D Transform Related Properties
The following table lists all the various properties that are used to transform the elements in the three-dimensional space.
| Property | Description | Example |
|---|---|---|
| backface-visibility | CSS backface-visibility property sets the visibility of back face of an element to the user. | |
| perspective | CSS perspective property determines the distance between the z=0 plane and the user. | |
| perspective-origin | CSS perspective-origin property determines the position at which the user is looking at the 3D-positioned element. | |
| rotate3d() | CSS rotate3d() function rotates an element in the three-dimensional space. | |
| scale3d() | CSS scale3d() function scales an element in the three-dimensional space. | |
| transform | CSS transform property transforms an element in the three-dimensional space. | |
| translate | css translate property translates an element in three-dimensional space. | |
| rotateZ() | CSS rotateZ() function rotates an element around the z-axis. | |
| scaleZ() | CSS scaleZ() function scales an element up or down along the z-axis. | |
| translateZ() | CSS translateZ() function translates an element up or down along the z-axis. |