NEW POSTS
latest
CSS
CSS

Pages

Contact Form

Name

Email *

Message *

Latest Articles

CSS transform-style Property

Understanding the CSS transform-style Property

Rotating cards, spinning cubes, and layered scenes all rely on CSS 3D transforms. But applying a 3D transform to an element does not automatically make its nested elements behave like real 3D objects. Whether they do depends on a small property called transform-style. This article explains what it controls, how its two values differ, and why it is behind so many confusing 3D bugs. You can also experiment with everything in the live editor further down the page.



What is the transform-style Property?

Think of a transformed element as a sheet of glass and its children as stickers on that sheet. The transform-style property decides whether the children are treated as stickers that stay on the surface of the glass, or as separate objects that each keep their own depth in front of and behind it.

The sticker behavior is the default. If you rotate a child with rotateY() or push it forward with translateZ(), the browser still applies that transform, but the result is painted onto the parent's surface. The child can never sit in front of, behind, or through other elements in a shared 3D scene. Switching on the 3D behavior removes that limit.

Definition: transform-style is a CSS property that you set on a parent element to tell the browser how to render that element's children when 3D transforms are involved. With preserve-3d, the children keep their own positions in 3D space and share one scene with the parent. With flat, the children are drawn onto the parent's two-dimensional surface and lose their independent depth.

Core Property Values

The property accepts two keywords:

  • flat (Default): Children are drawn onto their parent's surface. Their own transforms still apply, but the parent is first rendered as a single flat picture, and only that picture takes part in the parent's rotation. Because every element starts this way, you rarely need to write transform-style: flat;, except to undo a preserve-3d declared by another rule.
  • preserve-3d: Children share a 3D scene with their parent. Each child keeps its own position and rotation in depth, so siblings can overlap correctly, intersect, or sit in front of and behind each other. Use it on any transformed element whose children must keep their depth, such as a card with two faces or a cube with six.

Note that preserve-3d is not needed to rotate a single element. A lone element can be turned with transform: rotateY(180deg) and no transform-style at all. The property only matters when an element has children that must keep their 3D relationship inside it.


Practical Example: 3D Card Container (Live Editor)

To see how this works in practice, consider a common card-flipping component. The editor below contains the HTML and CSS on the left and a live preview on the right. Hover over the card in the preview to flip it, and edit either code box to see the result instantly. Without preserve-3d on the rotating container, the two faces are flattened onto the container's plane instead of living in 3D space.

HTML Structure (editable)
CSS (editable)
Live Preview (hover to flip)

Things to Try in the Editor

  • Delete the transform-style: preserve-3d; line from .card. The browser falls back to flat, both faces are flattened onto the card's plane, and the back face (already turned 180 degrees) is drawn over the front face, so the flip effect is ruined.
  • Add overflow: hidden; or opacity: 0.9; to .card. This silently forces the used value back to flat and breaks the flip.
  • Remove perspective: 600px; from .scene. The rotation still happens, but it looks flat instead of having depth.
  • Remove backface-visibility: hidden; from .card-face. The face turned away from you now shows through as a mirrored image.

How perspective and transform-style Work Together

These two properties are often confused, but they do different jobs. perspective is set on a parent and gives its direct children a sense of depth: things closer to the viewer look larger. transform-style: preserve-3d keeps the deeper descendants in that same 3D space instead of flattening them. In the example, perspective on .scene creates the viewing distance for .card, and preserve-3d on .card lets the two faces inside it share that 3D space and be drawn with the same perspective. Without perspective, the rotation still happens but looks flat and orthographic; without preserve-3d, the faces collapse into a plane.

Why the Example Needs backface-visibility

The backface-visibility: hidden; rule is not part of transform-style, but the card flip depends on it. When the card turns, the front face ends up facing away from the viewer, and by default a face turned away is still drawn as a mirrored image. Hiding the back side of each face ensures that only the face currently pointing toward the viewer is visible.


Important Usage Considerations for Developers

  • Not Inherited: transform-style is not an inherited property. If you have deep nesting, you must declare transform-style: preserve-3d on every intermediate ancestor that sits between the 3D parent and the 3D content. The 3D chain breaks at the first ancestor that is flat: everything below that element is flattened onto its plane, no matter what its own children declare. This is one of the most common reasons a 3D scene "stops working" after an extra wrapper element is added.
  • Some Properties Force flat: Certain properties require an element to be rendered as a single flattened group, and they force the used value of transform-style back to flat even if you wrote preserve-3d. This behavior is deterministic, not occasional. Common triggers include:
    • overflow set to any value other than visible or clip (for example hidden, auto, or scroll)
    • opacity with a value less than 1
    • filter and backdrop-filter with a value other than none
    • clip with a value other than auto, and clip-path with a value other than none
    • mask properties such as mask-image with a value other than none
    • isolation: isolate
    • mix-blend-mode with a value other than normal
    • contain: paint, and anything that implies it, such as content-visibility: hidden
    For example, adding overflow: hidden or opacity: 0.9 to the .card element in the live editor above would silently flatten it and break the flip. If a 3D effect stops working, check the element and its ancestors for these properties first. To fade or clip a 3D object, apply those properties to a wrapper outside the 3D structure, or to the individual faces, instead of to the element that has preserve-3d.

Conclusion

The transform-style property is small, but it decides whether nested elements behave like real 3D objects or like paint on a flat surface. When a 3D layout misbehaves, check three things in order: is preserve-3d set on every element in the chain, is perspective applied on an ancestor, and does any element in the chain use a property that forces flat?

The transform-style property also supports standard global CSS values such as inherit, initial, revert, revert-layer, and unset.

Further Reading

For the formal definition and browser support details, see the MDN Web Docs page for transform-style.

3D Laptop CSS Quiz

💻 3D Laptop CSS Quiz

Test our understanding of the CSS behind the laptop.

🎉 Quiz Complete!

3D Animated CSS Cube

Rotating 3D Cube CSS Animation

Pure CSS 3D Cube

How to Restore or Undo Windows Photo Viewer in Windows 10/11

How to Restore or Remove Windows Photo Viewer in Windows 10/11

Windows Photo Viewer was the default image viewer in Windows 7 and 8. Later, in Windows 10 and 11, Microsoft replaced it with a different photo viewer app. This might be because Windows Photo Viewer was unable to open certain image formats. For example, images received from apps like WeChat and Telegram are not supported. However, because of its simplicity, fast performance, and clean interface, many users still prefer the classic Windows Photo Viewer. So, if you like to use Windows Photo Viewer, you can download from this blogpost and use it for free.

Note: The registry file for activating Windows Photo Viewer works on both Windows 10 and 11. If you're not so sure, you can back up your registry before applying any changes. But don’t worry, it’s safe. If it causes any issues, you can download another registry file that can undo all the changes.

Restore Windows Photo Viewer

Download and Apply Registry File

Download the registry file to restore Windows Photo Viewer:

Follow the instructions below:

  1. 1. Click the download button above, which is labeled "Restore the Windows Photo Viewer file".
  2. 2. After downloading, double-click the registry file. Click on "Run" to continue.
  3. 3. Click "Yes" when prompted by User Account Control
  4. 4. Click "Yes" to confirm and add the information to the registry.
  5. 5. Click "OK" when you see the success message
  6. 6. If the changes are not taking effect, try refreshing your PC. If the problem still persists, restart your PC to apply the changes fully.

How to Set Windows Photo Viewer as Default

After applying the registry changes:

  1. ➣ Right-click any image file and select "Open with" > "Choose another app."
  2. ➣ Select "Windows Photo Viewer."
  3. ➣Choose "Always."
  4. ➣ Boom! "Windows Photo Viewer" is now your default photo veiwing app.

Undo Windows Photo Viewer (Remove It)

If you want to remove Windows Photo Viewer and revert to the default Photos app, follow these steps:

Option A: Download and Apply Registry File (Recommended)

Download the registry file to remove Windows Photo Viewer:

  1. Click the download button above to get the registry file
  2. Save the file to your computer
  3. Double-click the downloaded .reg file
  4. Click "Yes" when prompted by User Account Control
  5. Click "Yes" to confirm you want to add the information to the registry
  6. Click "OK" when you see the success message
  7. Restart your computer for changes to take full effect

Troubleshooting

If Windows Photo Viewer doesn't appear after applying the registry changes:

  • Make sure you restarted your computer
  • Try right-clicking an image file, select "Open with" > "Choose another app" and look for Windows Photo Viewer in the list
  • If you don't see it, browse to C:\Program Files\Windows Photo Viewer and select PhotoViewer.dll
  • Some Windows 11 builds may require additional steps - try running the registry file again after a reboot

If you get errors when running the registry files:

  • Make sure you're logged in as an administrator
  • Right-click the .reg file and select "Run as administrator"
  • Check if your antivirus is blocking registry changes

Conclusion

Last but not least, I still use Windows Photo Viewer because it is very user-friendly and my favorite app for viewing images. So the two registry files above are very important: one is used to activate Windows Photo Viewer, and the other is used to undo the changes in Windows 10 and 11. Please note that Microsoft may completely remove Windows Photo Viewer in the future, so nothing is guaranteed. While it’s uncertain what will happen later, for now, at least in Windows 10 and 11, we can still use Windows Photo Viewer, and we’re quite lucky, actually.

Credits: This guide and registry files were created by Sey8. Visit our homepage at https://sey8.blogspot.com for more Windows tips and tricks.

Display flex - Responsive Layouts

My Responsive Flexbox Layout

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras a aliquet erat. Pellentesque sodales tortor massa, non facilisis sem sollicitudin sit amet. Curabitur vestibulum consectetur enim. Donec sit amet tincidunt justo. Praesent lacinia eros nec dictum cursus. Donec tempus, eros nec viverra fringilla, erat orci vestibulum diam, vitae tristique eros ex et est. Pellentesque venenatis, turpis quis suscipit consequat, lectus mi auctor odio, nec fermentum dolor nulla in odio. Duis fringilla, libero quis tristique suscipit, risus nisi tincidunt mauris, vitae efficitur leo quam id odio. Praesent diam ligula, consequat vel aliquet vitae, vestibulum eu neque.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras a aliquet erat. Pellentesque sodales tortor massa, non facilisis sem sollicitudin sit amet. Curabitur vestibulum consectetur enim. Donec sit amet tincidunt justo. Praesent lacinia eros nec dictum cursus. Donec tempus, eros nec viverra fringilla, erat orci vestibulum diam, vitae tristique eros ex et est. Pellentesque venenatis, turpis quis suscipit consequat, lectus mi auctor odio, nec fermentum dolor nulla in odio. Duis fringilla, libero quis tristique suscipit, risus nisi tincidunt mauris, vitae efficitur leo quam id odio. Praesent diam ligula, consequat vel aliquet vitae, vestibulum eu neque.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras a aliquet erat. Pellentesque sodales tortor massa, non facilisis sem sollicitudin sit amet. Curabitur vestibulum consectetur enim. Donec sit amet tincidunt justo. Praesent lacinia eros nec dictum cursus. Donec tempus, eros nec viverra fringilla, erat orci vestibulum diam, vitae tristique eros ex et est. Pellentesque venenatis, turpis quis suscipit consequat, lectus mi auctor odio, nec fermentum dolor nulla in odio. Duis fringilla, libero quis tristique suscipit, risus nisi tincidunt mauris, vitae efficitur leo quam id odio. Praesent diam ligula, consequat vel aliquet vitae, vestibulum eu neque.

Add HTML Document and CCS to New Context Menu

Watch the video at  https://youtu.be/1ubdy1cL2PI for the instruction:-

HTML and CSS at New context menu

1. For HTML File


2. For CSS File

Transform-origin In CSS

The CSS property transform-origin defines the point around which a transformation is applied to an element. It is the point or origin of the transform property which can change the point of transformations like rotation, scaling, skewing, etc. By default, the transform-origin of an element is relative to the center of an element.

Transform-origon CSS

-

Video Tutoral at https://youtu.be/-MZvSn6pOyg

The transform-origin property is used along with the transform property. For example, if we use, transform: rotateZ(30deg); and transform-origin: top;, the point of transformation or rotation starts from the top center.

If you want to keep the transform-origin at the center, then there is no need to use the transform-origin property. This is because the transform-origin is at the center by default. However, if you want to shift your transform-origin, then you have to use it.

If we set here the transform-origin: bottom;, then the transform-origin is at the bottom center. Similarly, you can set transform-origin: left;, transform-origin: right;, transform-origin: top;, transform-origin: top right;, transform-origin: bottom left;, etc.

transform-origin: top right; Here the transform-origin has shifted to the top right corner.

Instead of using transform-origin: right bottom;, we can use transform-origin: 100% 100%;. Here, the first value is x, and the second value is y. Both x and y move 100% away from 0, intersecting at the right bottom corner. So, transform-origin: 100% 100%; is the same as transform-origin: right bottom;.

transform-origin: 50%; : Here, 50% represents the X value. Even though nothing is mentioned for Y, it still means that the Y value is 50% by default.

transform-origin: 50% 50%; : In this case, we find that both the x and y values are each specified as 50%.

transform-origin: 50% 0; : Here, the x value is 50% and the y value is 0, which sets the transform-origin to the top center.

Here are some examples of transform-origin values that give the same effects. Please go through all of these:


/* Left transform-origin */
transform-origin: 0;
transform-origin: left;
transform-origin: center left;
transform-origin: left center;
transform-origin: 0 50%;

/* Top left transform-origin */
transform-origin: top left;
transform-origin: left top
transform-origin: 0 0;

/* Top transform-origin */
transform-origin: top; 
transform-origin: top center;
transform-origin: center top;
transform-origin: 50% 0;

/* Top right transform-origin */
transform-origin: top right;
transform-origin: right top;
transform-origin: 100% 0;

/* Right transform-origin */
transform-origin: right;
transform-origin: 100%;
transform-origin: center right;
transform-origin: right center;
ransform-origin: 100% 50%;

/* Bottom right transform-origin */
transform-origin: bottom right;
transform-origin: right bottom;
transform-origin: 100% 100%;

/* Bottom transform-origin */
transform-origin: bottom;
transform-origin: bottom center;
transform-origin: center bottom;
transform-origin: 50% 100%;

/* Bottom left transform-origin */
transform-origin: bottom left;
transform-origin: left bottom;
transform-origin: 0 100%;

Index

CSS

Result
transform-origin: 50% 100%;

Hover your mouse on the above square.

Transform-origin: x-offset value, y-offset value, z-offset value; This is the main syntax for transform-origin values. We have x-offset value which defines the horizontal position of the origin. The second one is y-offset value which defines the vertical position of the origin and the third is z-offset value which defines the position along the z-axis (depth) when using 3D transformations.

Transform-origin value can be one-value syntax, two-value syntax and three-value syntax. The three-value syntax can be used specially in a 3D element. Here are examples of one-value syntax, two-value syntax, and three-value syntax. Please go through all of these. Please note that z-offset cannot be used in percentage because there is no measurable or clear size on the z-axis.

Examples:


/* 1. One-value syntax */
transform-origin: 3px;
transform-origin: top;

/* 2. Two-value syntax */
transform-origin: 5cm 3px;
transform-origin: 80% 30%;
transform-origin: left 2px;
transform-origin: right top;
transform-origin: top right;

/* 3. Three-value syntax */
transform-origin: 2px 30% 10px;
transform-origin: left 5px -4px;
transform-origin: right bottom 5cm;
transform-origin: bottom right 9cm;

We can also use Global Values in transform-origin. Here, we have:


/* Global values: */
transform-origin: inherit; 
transform-origin: initial; 
transform-origin: revert; 
transform-origin: revert-layer; 
transform-origin: unset; 

In CSS, global values control how properties are applied or reset by inheriting values, using default settings, or reverting to previous or default states.

So in conclusion, the transform origin is very useful when we animate or style our transformations. By changing the transform origin, we can make the visual effect of an element look much better.

.

Creating A Vertical Scrollbar with CSS in HTML

If you look at every website, you will find the vertical scrollbar on the right side of the webpage. The vertical scrollbar is showing by default yet we can design it into a better scrollbar on our website.

Vertical scrollbar
-

Video Tutoral at https://youtu.be/jB20Qhzt3dU


To improve the user experience when dealing with lengthy content or with a limited space, it's important to add a vertical scrollbar to a web page. By using the code provided below, you can create a vertical scrollbar with a unique style. CSS properties such as ::-webkit-scrollbar, ::-webkit-scrollbar-track, and ::-webkit-scrollbar-thumb allow you to define the width, color, and shape of the scrollbar. Feel free to experiment with different values to achieve the desired visual effect. It may also enhance your website's readability and aesthetics by implementing a customized vertical scrollbar in HTML using CSS.

US Flag
play button