CSS Function - matrix()



The CSS function matrix() defines a 2D transformation matrix with homogeneous coordinates, resulting in a data type of transform().

Possible Values

Syntax

The matrix() is a 4x4 matrix, but only the first 6 values are used for 2D transformations. The function has the following syntax:

 matrix(a, b, c, d, tx, ty) 
  • a (m11): Horizontal scaling.

  • b (m12): Vertical skewing.

  • c (m21): Horizontal skewing.

  • d (m22): Vertical scaling.

  • e (dx): Horizontal translation.

  • f (dy): Vertical translation.

The matrix() function is used to combine multiple transformations into a single transform property.

CSS matrix() - Basic example

The following example demonstrates the usage of matrix():

 <html> <head> <style> .matrix-demo { transform: matrix(1, -0.2, 0, 1, 0, 0); background-color: #000; color: #fff; padding: 20px; font-size: 24px; text-align: center; } .normal-demo { background-color: #ccc; color: #000; padding: 20px; font-size: 24px; text-align: center; } </style> </head> <body> <div class="matrix-demo">This is a matrix div</div> <div class="normal-demo">This is a normal div</div> </body> </html> 
Advertisements