Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / CSS

skew(): two-axis shearing in one transform

Understand this compatibility function and why it differs from composing skewX() and skewY().

Version: CSS Modules

Syntax

transform: skew(45deg, 30deg);

skew(ax, ay) shears an element in two dimensions. The second angle is optional and defaults to zero. Relative to the transform origin, the coordinate equations are x′ = x + tan(ax) × y and y′ = y + tan(ay) × x. This is not a rotation: lengths and angles can change. Nonzero angles need an angle unit; unitless zero is allowed for compatibility.

The specification retains skew() for compatibility and recommends skewX() or skewY() for new content. However, blindly replacing a two-angle skew() with both functions changes the matrix: their composition also contains a cross term. transform-origin matters, and a visual transform does not change the dimensions used by normal layout. Avoid angles near 90deg where the tangent becomes very large.

With origin 0 0, the example maps point (10,20) to (30,20) using skew(45deg), and an 80×40 box has a visual bounding width of 120. skew(45deg,30deg) maps the point to approximately (30,25.77), while skewX(45deg) skewY(30deg) gives (35.77,25.77). Layout stays 80×40. The rounded output is based on the browser’s serialized transform matrix.

Examples

const box=document.createElement('div');box.style.cssText='position:fixed;left:0;top:0;width:80px;height:40px;transform-origin:0 0';document.body.append(box);
const point=value=>{box.style.transform=value;const p=new DOMMatrixReadOnly(getComputedStyle(box).transform).transformPoint({x:10,y:20});return p.x.toFixed(2)+','+p.y.toFixed(2)};
const single=point('skew(45deg)'),bounds=box.getBoundingClientRect();
const both=point('skew(45deg,30deg)'),product=point('skewX(45deg) skewY(30deg)');
console.log('single='+single+'; bounds='+bounds.width.toFixed(0)+'x'+bounds.height.toFixed(0)+'; both='+both+'; product='+product+'; layout='+box.offsetWidth+'x'+box.offsetHeight+'; unitless-angle='+CSS.supports('transform','skew(45)'));

Result

single=30.00,20.00; bounds=120x40; both=30.00,25.77; product=35.77,25.77; layout=80x40; unitless-angle=false

Verified in Chromium 157.0.8103.51. The example documents existing skew() code, not a recommendation to use it in new designs. Choose a single-axis function when that is the intended effect; do not assume a two-function replacement is equivalent.

Sources