Transform Origin
Tailwind CSS version
v1.2.0+
Utilities for specifying the origin for an element’s transformations.
Class reference
Class | Properties |
---|---|
.origin-center | transform-origin: center; |
.origin-top | transform-origin: top; |
.origin-top-right | transform-origin: top right; |
.origin-right | transform-origin: right; |
.origin-bottom-right | transform-origin: bottom right; |
.origin-bottom | transform-origin: bottom; |
.origin-bottom-left | transform-origin: bottom left; |
.origin-left | transform-origin: left; |
.origin-top-left | transform-origin: top left; |
Usage
Specify an element’s transform origin using the origin-{keyword}
utilities.
<img class="origin-center transform rotate-45 ...">
<img class="origin-top-left transform rotate-45 ...">
<img class="origin-bottom-right transform rotate-45 ...">
<img class="origin-left transform rotate-45 ...">
Responsive
To control the transform-origin of an element at a specific breakpoint, add a {screen}:
prefix to any existing transform-origin utility. For example, use md:origin-top
to apply the origin-top
utility at only medium screen sizes and above.
For more information about Tailwind’s responsive design features, check out the Responsive Design documentation.
all
sm
md
lg
xl
<img class="origin-center sm:origin-top-left md:origin-top-right lg:origin-bottom-right xl:origin-bottom-left ...">
Customizing
Origin values
By default Tailwind provides transform-origin utilities for all of the built-in browser keyword options. You change, add, or remove these by customizing the transformOrigin
section of your Tailwind theme config.
// tailwind.config.js
module.exports = {
theme: {
extend: {
transformOrigin: {
+ '24': '6rem',
+ 'full': '100%',
}
}
}
}
Learn more about customizing the default theme in the theme customization documentation.
Responsive and pseudo-class variants
By default, only responsive variants are generated for transform-origin utilities.
You can control which variants are generated for the transform-origin utilities by modifying the transformOrigin
property in the variants
section of your tailwind.config.js
file.
For example, this config will also generate hover and focus variants:
// tailwind.config.js
module.exports = {
variants: {
// ...
- transformOrigin: ['responsive'],
+ transformOrigin: ['responsive', 'hover', 'focus'],
}
}
Disabling
If you don’t plan to use the transform-origin utilities in your project, you can disable them entirely by setting the transformOrigin
property to false
in the corePlugins
section of your config file:
// tailwind.config.js
module.exports = {
corePlugins: {
// ...
+ transformOrigin: false,
}
}