
- 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 - transform-origin Property
The CSS property transform-origin is helpful in setting the origin for the transformation of an element. It is the point around which transformation occurs. For instance, the center of rotation is the transform origin of the rotate() function.
The origin of a transform is center, by default.
Possible values
The CSS property transform-origin can have the following values:
x-offset: A <length> or <percentage> value that defines how far from the left side of the box, the transform-origin is set.
offset-keyword: Keyword specifying the corresponding offset value, i.e., left, right, top, bottom, or center.
y-offset: A <length> or <percentage> value that defines how far from the top side of the box, the transform-origin is set.
x-offset-keyword: Keyword specifying the corresponding offset value, i.e., left, right, or center. It defines how far from the left side of the box, the transform-origin is set.
y-offset-keyword: Keyword specifying the corresponding offset value, i.e., top, bottom, or center. It defines how far from the top side of the box, the transform-origin is set.
z-offset: A <length> value that defines how far from the user eye the z=0 origin is set. A <percentage> value is not acceptable, as that makes the statement invalid.
The following table lists the mapping of keyword and percentage value:
Keyword | Percentage value |
---|---|
left | 0% |
center | 50% |
right | 100% |
top | 0% |
bottom | 100% |
Applies to
All the transformable elements.
Syntax
transform-origin = x-axis y-axis z-axis;
Here x-axis, y-axis, z-axis values represent the horizontal, vertical, and depth positions, respectively, of the transformation origin. They can be specified in various units such as pixels, percentages, or keywords.
Following are the various ways in which the syntax can be written:
/* one-value syntax */ transform-origin = 20px; transform-origin = 30%; transform-origin = left; /* x-offset-keyword / y-offset-keyword */ transform-origin = left top; /* y-offset-keyword / x-offset-keyword */ transform-origin = bottom right; /* x-offset-keyword / y-offset */ transform-origin = left 5px; /* y-offset-keyword / x-offset-keyword */ transform-origin = bottom 10%; /* x-offset / y-offset */ transform-origin = 3cm 5px | 25% 30%; /* x-offset / y-offset / z-offset */ transform-origin = 3cm 5px -5px; /* x-offset-keyword / y-offset-keyword / z-offset */ transform-origin = left top 3cm; /* y-offset-keyword / x-offset-keyword / z-offset*/ transform-origin = bottom right 3cm;
The CSS property transform-origin can be specified in one of the ways, i.e., using the one, two, or three values, where each value signifies an offset value.
1. One-value syntax
Value must be either <length>, <percentage>, or one of the keywords left, center, right, top, and bottom.
When a single value, as <length>, or <percentage> is specified, it determines the horizontal offset (x-axis).
2. Two-value syntax
One value must be either <length>, <percentage>, or one of the keywords left, center,, and right.
Second value must be either <length>, <percentage>, or one of the keywords top, center,, and bottom.
When two, or more values are specified and either of the values is the keyword center, then first value determines the horizontal offset and the second determines the vertical offset.
3. Three-value syntax
First two values are same as that for two-value syntax.
Third value must always be a <length> value, representing the Z offset.
Note: For all SVG elements, the initial value of transform-origin is 0 0, except for root <svg> elements and <svg> elements that are direct descendant of an external XML namespace, and the elements whose transform-origin is 50% 50%.
CSS transform-origin - Example
Following example demonstrates the use of various values of transform-origin used along-side transform functions:
<html> <head> <style> #div1 { position: relative; height: 50px; width: 50px; margin: 30px; padding: 20px; border: 1px dotted black; } .sec-div { width: 30px; height: 30px; padding: 20px; position: absolute; border: 1px solid black; background-color: lightblue; } #initial-val { transform: rotate(30deg); transform-origin: 50% 50%; } #ykey-xkey-z { transform: rotate(45deg); transform-origin: top left 3cm; } #xkey-y { transform: scale(1.2); transform-origin: right 20%; } #x-y { transform: translate(10px 30px); transform-origin: 30px 10px; } #x-yNeg-percent{ transform: skewX(30deg); transform-origin: 80% -20%; } </style> </head> <body> <h1>The transform-origin Property</h1> <div id="div1"> <div class="sec-div" id="initial-val">50% 50%</div> </div> <p>transform: rotate(30deg); transform-origin: 50% 50%;</p> <div id="div1"> <div class="sec-div" id="ykey-xkey-z">top left 3cm</div> </div> <p>transform: rotate(45deg); transform-origin: top left 3cm;</p> <div id="div1"> <div class="sec-div" id="xkey-y">right 20%</div> </div> <p>transform: scale(1.2); transform-origin: right 20%;</p> <div id="div1"> <div class="sec-div" id="x-y">30px 10px</div> </div> <p>transform: translate(10px 30px); transform-origin: 30px 10px;</p> <div id="div1"> <div class="sec-div" id="x-yNeg-percent">100% -30%</div> </div> <p>transform: skewX(30deg); transform-origin: 80% -20%;</p> </body> </html>