Skip to content
LOCEN/Ontario · CAStandbyOK/--:--:--EST
M4M4RK_YUportfolio
  • Projects
    ProjectsOverview
    • WorkSelected case studies and write-ups
    • GamesPlayable prototypes and game-dev logs
  • Gallery
    GalleryOverview
    • ArchivePhoto collections and visual experiments
    • ShopPrints, posters, and one-off objects
  • Logs
    LogsOverview
    • BlogLong-form devlogs and field notes
    • NotesShort observations, links, snippets
  • Resources
    ResourcesOverview
    • Tools38 in-browser developer utilities
    • LinksDaily-use dev and design bookmarks
  • About
  • Contact
中文

syndicated · dev.to / @markyu

Quick Guide To 3D Transformations in CSS3 😎

Introduction Creating dynamic 3D scenes in web development can elevate your design, making...

Published
May 20 '24
·
Reading time
3 min read
·
Reactions
4
webdevcss3dfrontendchallenge
View on dev.to

Introduction

Creating dynamic 3D scenes in web development can elevate your design, making it more engaging and interactive. In this guide, we'll explore the fundamentals of 3D transformations using CSS3. You'll learn about coordinate axes, perspective views, rotations, and scaling, and how to effectively apply these techniques to your web projects.

Coordinate Axes

Image description

Understanding 3D Scenes

In 2D scenes, we work with the x-axis (horizontal) and y-axis (vertical). In 3D scenes, we introduce a third axis: the z-axis, which is perpendicular to the screen.

  • Z-axis: Positive values move the element closer to the viewer, while negative values move it further away.

In CSS3, 3D transformations include several key functions:

  1. 3D Translation: translateZ() and translate3d(x, y, z)
  2. 3D Rotation: rotateX(), rotateY(), rotateZ(), and rotate3d()
  3. 3D Scaling: scaleZ() and scale3d()
  4. 3D Perspective View: perspective(n) function or perspective property

CSS3 3D Transform Functions

3D Translation

CSS3 provides the translateZ() and translate3d(x, y, z) functions for 3D translation. These functions allow you to move elements along the z-axis, giving the illusion of depth.

.element {
  transform: translate3d(10px, 20px, 30px);
}

In this example, the element is moved 10 pixels along the x-axis, 20 pixels along the y-axis, and 30 pixels along the z-axis.

3D Rotation

For 3D rotations, CSS3 offers rotateX(), rotateY(), rotateZ(), and rotate3d(). These functions enable you to rotate elements around the x, y, or z axes, respectively.

.element {
  transform: rotateX(30deg);
}

This rotates the element 30 degrees around the x-axis. You can combine rotations around multiple axes for complex effects.

Perspective View

Defining Perspective

Perspective view, also known as depth of field, gives a sense of depth to 3D elements. Without perspective, elements will appear uniformly sized regardless of their distance from the viewer.

Image description

To create a sense of depth:

  1. Set the perspective distance.
  2. Apply transformations along the z-axis.
.container {
  perspective: 1200px;
}

.element {
  transform: perspective(1200px) translateZ(200px);
}

Setting the perspective distance adjusts how the viewer perceives depth. The closer the perspective value (e.g., 900px), the more pronounced the depth effect.

Perspective-Origin

Image description

The perspective-origin property defines the viewpoint of the observer. By default, the z-axis is positioned at the center of the parent element.

.container {
  perspective-origin: 50% 50%;
}

You can adjust this property to change the observer's angle:

.container {
  perspective-origin: left top;
}

3D Rotation

The rotateX(), rotateY(), and rotateZ() methods rotate an element around the respective axis.

.element {
  transform: rotateX(30deg);
}

For complex rotations, use rotate3d():

.element {
  transform: rotate3d(1, 1, 1, 30deg);
}

This rotates the element 30 degrees around a vector (1, 1, 1).

Transform Style

The transform-style property determines whether child elements maintain their 3D position.

.container {
  transform-style: preserve-3d;
}

This ensures that nested elements retain their 3D transformations.

Transform Origin

The transform-origin property sets the point of origin for transformations.

.element {
  transform-origin: 50% 50% 50px;
}

This sets the transformation origin to the center of the element at 50px along the z-axis.

3D Scaling

The scaleZ() and scale3d() functions scale an element in 3D space. Note that scaleZ() requires additional transformations to be visible.

.element {
  transform: perspective(100px) scaleZ(2) translateZ(1px);
}

This scales the element along the z-axis, making it appear larger or smaller.

Practical Example

To create a 3D effect, combine multiple transformations:

.box {
  transform-style: preserve-3d;
  perspective: 800px;
}

.center {
  transform: scaleZ(10) rotateX(45deg);
}

Or:

.box {
  transform-style: preserve-3d;
}

.center {
  transform: perspective(800px) scaleZ(10) rotateX(45deg);
}

These examples demonstrate how to combine perspective, scaling, and rotation to create complex 3D effects.

Conclusion

Image description

Mastering CSS3 3D transformations allows you to create visually appealing and interactive web designs. By understanding and applying these techniques, you can add depth and dimension to your projects, enhancing the user experience.

Related reading

react

3 Ways To Create Engaging React Loading Screens with Hooks

Creating engaging loading screens for your React applications can greatly enhance the user...

html

Create a Heart Shaped Animation with CSS3

Introduction Creating a personalized love confession page can be a fun and heartfelt way...

webdev

Implementing 3D Graphics in React

3D is an exciting area in computer science, and it could range from creating 3D shapes, vectors,...

originally published

This post first ran on dev.to. Comments and reactions live there.

Continue on dev.to
PreviousNavigating the Clouds: A Comprehensive Guide to Modern Cloud InfrastructuresIntroduction: ​ As a full-stack developer, understanding cloud architecture is crucial...
Back to archive
NextMySQL Performance Monitoring and Query AnalysisMySQL Performance Monitoring and Query Analysis In this guide, we will explore various...
Back to archive
open channel·say hi anytime · 2026
--:--:--EST
get in touch

Saw something here?Tell me about it.

It's a portfolio, not a service · but I read every note — drop a line if anything here resonated, or just to say hi.

Start a conversation

Newsletter

Get the occasional dispatch

Notes and logs from m4rkyu.com — short, dated, no noise. Unsubscribe anytime.

Work

Production builds, games, and visual archives.

  • Projects
  • Games
  • Archive
  • Logs

Resources

Daily-use tools and a personal link library.

  • Search
  • Latest
  • Tools
  • Links
  • Notes
  • Topics
  • RSS
  • JSON feed
  • Shop

Studio

Background, contact, and channels for collaboration.

  • About
  • Contact
  • Changelog
  • Colophon
  • Resumepending

Socials

Find me on the usual feeds.

  • Facebooksoon
  • Instagramsoon
  • YouTubesoon
  • LinkedInsoon
M4RKYUM4RKYUM4RKYUM4RKYUM4RKYUM4RKYUM4RKYUM4RKYU
Crafted since 2024
ZhenXiao Mark YuZhenXiao Mark Yu
© 2026 ZhenXiao Mark Yu·Ontario, Canada
  • Email
  • GitHub
  • dev.to
  • LinkedIn (soon)
  • Twitter / X (soon)
  • Instagram (soon)
Built with Next.js 16 · React 19 · Tailwind 4

Built with Next.js 16 · React 19 · Tailwind 4