
- HTML Home
- HTML Roadmap
- HTML Introduction
- HTML History & Evolution
- HTML Editors
- HTML Basic Tags
- HTML Elements
- HTML Attributes
- HTML Headings
- HTML Paragraphs
- HTML Fonts
- HTML Blocks
- HTML Style Sheet
- HTML Formatting
- HTML Quotations
- HTML - Comments
- HTML - Colors
- HTML - Images
- HTML - Image Map
- HTML - Frames
- HTML - Iframes
- HTML - Phrase Elements
- HTML - Code Elements
- HTML - Meta Tags
- HTML - Classes
- HTML - IDs
- HTML - Backgrounds
- HTML Tables
- HTML - Tables
- HTML - Table Headers & Captions
- HTML - Table Styling
- HTML - Table Colgroup
- HTML - Nested Tables
- HTML Lists
- HTML - Lists
- HTML - Unordered Lists
- HTML - Ordered Lists
- HTML - Definition Lists
- HTML Links
- HTML - Text Links
- HTML - Image Links
- HTML - Email Links
- HTML Color Names & Values
- HTML - Color Names
- HTML - RGB & RGBA Colors
- HTML - HEX Colors
- HTML - HSL & HSLA Colors
- HTML - HSL Color Picker
- HTML Forms
- HTML - Forms
- HTML - Form Attributes
- HTML - Form Control
- HTML - Input Attributes
- HTML Media
- HTML - Video Element
- HTML - Audio Element
- HTML - Embed Multimedia
- HTML Header
- HTML - Head Element
- HTML - Adding Favicon
- HTML - Javascript
- HTML Layouts
- HTML - Layouts
- HTML - Layout Elements
- HTML - Layout using CSS
- HTML - Responsiveness
- HTML - Symbols
- HTML - Emojis
- HTML - Style Guide
- HTML Graphics
- HTML - SVG
- HTML - Canvas
- HTML APIs
- HTML - Geolocation API
- HTML - Drag & Drop API
- HTML - Web Workers API
- HTML - WebSocket
- HTML - Web Storage
- HTML - Server Sent Events
- HTML Miscellaneous
- HTML - Document Object Model (DOM)
- HTML - MathML
- HTML - Microdata
- HTML - IndexedDB
- HTML - Web Messaging
- HTML - Web CORS
- HTML - Web RTC
- HTML Demo
- HTML - Audio Player
- HTML - Video Player
- HTML - Web slide Desk
- HTML Tools
- HTML - Velocity Draw
- HTML - QR Code
- HTML - Modernizer
- HTML - Validation
- HTML - Color Picker
- HTML References
- HTML - Cheat Sheet
- HTML - Tags Reference
- HTML - Attributes Reference
- HTML - Events Reference
- HTML - Fonts Reference
- HTML - ASCII Codes
- ASCII Table Lookup
- HTML - Color Names
- HTML - Character Entities
- MIME Media Types
- HTML - URL Encoding
- Language ISO Codes
- HTML - Character Encodings
- HTML - Deprecated Tags
- HTML Resources
- HTML - Quick Guide
- HTML - Useful Resources
- HTML - Color Code Builder
- HTML - Online Editor
HTML - DOM Style Object transform Property
HTML DOM Style Object transform property is used to apply 2D or 3D transformation to transform the object. It lets us transform the object or element using matrix, skew, translate, rotate, scale properties.
Syntax
Set the transform property:object.style.transform= "none | transform-functions | initial | inherit";Get the transform property:
object.style.transform;
Property Values
Value | Description |
---|---|
none | It is the default value which specifies no transformation. |
matrix(x, x, x, x, x, x) | It specifies a 2D matrix transformation. It takes six values as input. |
matrix3d(x, x, x, x,..,x) | It specifies a 3D matrix transformation. It uses a 4x4 matrix of 16 values. |
translate(x, y) | It specifies a 2D translation. |
translate3d(x, y, z) | It specifies a 3D translation. |
translateX(x) | It specifies translation in one direction only that is along X-axis. |
translateY(y) | It specifies translation in one direction only that is along Y-axis. |
translateZ(z) | It specifies a 3D translation along Z-axis only. |
rotate(angle) | It specifies a 2D rotation using angle propvided in parameter. |
rotate3D(angle) | It specifies a 3D rotation. |
rotateX(angle) | It specifies a 3D rotation along X-axis only. |
rotateY(angle) | It specifies a 3D rotation along Y-axis only. |
rotateZ(angle) | It specifies a 3D rotation along Z-axis only. |
scale(x, y) | It specifies a 2D scale transformation. |
scale3d(x, y, z) | It specifies a 3D scale transformation. |
scaleX(x) | It specifies a scale transformation in one direction only that is along X-axis. |
scaleY(y) | It specifies a scale transformation in one direction only that is along Y-axis. |
scaleZ(z) | It specifies a scale transformation in one direction only that is along Z-axis. |
skew(angle, angle) | It specifies a 2D skew transformation along X and Y axis. |
skewX(angle) | It specifies a 2D skew transformation along X-axis. |
skewY(angle) | It specifies a 2D skew transformation along Y-axis. |
perspective(x) | It specifies a perspective view for 3D transformed element. |
initial | It is used to set this property to it's default value. |
inherit | It is used to inherit the property of it's parent element. |
Return Value
It returns a string value which represents the transform property of an element.
Examples of HTML DOM Style Object 'transform' Property
The following examples illustrates different transformation properties like translation, scale, rotation, skew and matrix to div element.
Apply matrix transform Property to div Element
The following example applies matrix and matrix3D transformation properties to div element.
<!DOCTYPE html>] <html lang="en"> <head> <title> HTML DOM Style Object transform Property </title> <style> #transform { border: 1px solid rgb(77, 73, 73); width: 200px; height: 50px; padding: 5px; background-color: #04af2f; color: white; } </style> </head> <body> <button onclick="fun()"> 2D Matrix </button> <button onclick="funTwo()"> 3D Matrix </button> <br><br><br> <br><br><br><br> <div id="transform"> <p> Welcome To Tutorials Point. </p> </div> <script> function fun() { document.getElementById("transform") .style.transform = "matrix(0, 1, 1, 0, 0, 0)"; } function funTwo() { document.getElementById("transform").style.transform = "matrix3d(0.5,0,0.8,0,0.6,1.2,-1,0,1,0,0.5,0,30,0,10,1)"; } </script> </body> </html>
Apply translate transform Property to div Element
The following example applies translate and translate3D transformation properties to div element.
<!DOCTYPE html> <html lang="en"> <head> <title> HTML DOM Style Object transform Property </title> <style> #transform { border: 1px solid rgb(77, 73, 73); width: 200px; height: 50px; padding: 5px; background-color: #04af2f; color: white; } </style> </head> <body> <p> Click to apply Translation. </p> <button onclick="fun()"> 2D Translate </button> <button onclick="translateThreeD()"> 3D Translate </button> <button onclick="translateX()"> Translate X </button> <button onclick="translateY()"> Translate Y </button> <button onclick="funTwo()"> Translate Z </button> <div id="transform"> <p> Welcome To Tutorials Point. </p> </div> <script> function fun() { document.getElementById("transform") .style.transform = "translate(100px, 15px)"; } function translateThreeD() { document.getElementById("transform") .style.transform = "translate3D(25px, 15px, 40px)"; } function translateX() { document.getElementById("transform") .style.transform = "translateX(40px)"; } function translateY() { document.getElementById("transform") .style.transform = "translateY(50px)"; } function funTwo() { document.getElementById("transform") .style.transform = "translateZ(80px)"; } </script> </body> </html>
Apply rotate transform Property to div Element
The following example applies rotate and rotate3D transformation properties to div element.
<!DOCTYPE html> <html lang="en"> <head> <title> HTML DOM Style Object transform Property </title> <style> #transform { border: 1px solid rgb(77, 73, 73); width: 200px; height: 50px; padding: 5px; background-color: #04af2f; color: white; } </style> </head> <body> <p> Click to rotate. </p> <button onclick="fun()"> 2D Rotate </button> <button onclick="rotateThreeD()"> 3D Rotate </button> <button onclick="rotateX()"> Rotate X </button> <button onclick="rotateY()"> Rotate Y </button> <button onclick="funTwo()"> Rotate Z </button> <div id="transform"> <p> Welcome To Tutorials Point. </p> </div> <script> function fun() { document.getElementById("transform") .style.transform = "rotate(40deg)"; } function rotateThreeD() { document.getElementById("transform") .style.transform = "rotate3D(1, 1, 1, 30deg)"; } function rotateX() { document.getElementById("transform") .style.transform = "rotateX(45deg)"; } function rotateY() { document.getElementById("transform") .style.transform = "rotateY(45deg)"; } function funTwo() { document.getElementById("transform") .style.transform = "rotateZ(80deg)"; } </script> </body> </html>
Apply scale transform Property to div Element
The following example applies scale and scale3D transformation properties to div element.
<!DOCTYPE html> <html lang="en"> <head> <title> HTML DOM Style Object transform Property </title> <style> #transform { border: 1px solid rgb(77, 73, 73); width: 200px; height: 50px; padding: 5px; background-color: #04af2f; color: white; } </style> </head> <body> <p> Click to scale. </p> <button onclick="fun()"> 2D Scale </button> <button onclick="scaleThreeD()"> 3D Scale </button> <button onclick="scaleX()"> Scale X </button> <button onclick="scaleY()"> Scale Y </button> <button onclick="funTwo()"> Scale Z </button> <br><br><br> <br><br><br><br> <div id="transform"> <p> Welcome To Tutorials Point. </p> </div> <script> function fun() { document.getElementById("transform") .style.transform = "scale(3, 2)"; } function scaleThreeD() { document.getElementById("transform") .style.transform = "scale3D(3, 2, 2)"; } function scaleX() { document.getElementById("transform") .style.transform = "scaleX(3)"; } function scaleY() { document.getElementById("transform") .style.transform = "scaleY(3)"; } function funTwo() { document.getElementById("transform") .style.transform = "scaleZ(2)"; } </script> </body> </html>
Apply skew transform Property to div Element
The following example applies skew transformation property to div element.
<!DOCTYPE html> <html lang="en"> <head> <title> HTML DOM Style Object transform Property </title> <style> #transform { border: 1px solid rgb(77, 73, 73); width: 200px; height: 50px; padding: 5px; background-color: #04af2f; color: white; } </style> </head> <body> <p> Click to apply skew transformation. </p> <button onclick="fun()"> 2D skew </button> <button onclick="skewX()"> skew X </button> <button onclick="skewY()"> skew Y </button> <div id="transform"> <p> Welcome To Tutorials Point. </p> </div> <script> function fun() { document.getElementById("transform") .style.transform = "skew(10deg, 15deg)"; } function skewX() { document.getElementById("transform") .style.transform = "skewX(45deg)"; } function skewY() { document.getElementById("transform") .style.transform = "skewY(25deg)"; } </script> </body> </html>
Supported Browsers
Property | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
transform | Yes 36 | Yes 12 | Yes 16 | Yes 9 | Yes 23 |