CSS Property Functions
This chapter describes the functions you can use with supported CSS properties.
Gradient Functions
Gradient functions can be passed to the background
and background-image
properties.
color-stop
Specifies an intermediary color value for a gradient.
color-stop(stop, color) |
The point in the gradient that should have the specified color value. Represented as a percentage or a decimal value between
0
and1
.The color of the gradient at the stop.
stop
color
For more information, see
-webkit-gradient
.Available in Safari 4.0 and later.
- Parameters
- Discussion
- Availability
from
A convenience function for the color-stop
function that specifies the first color stop in a gradient.
from(color) |
The color of the gradient at the stop.
color
Equivalent to calling
color-stop()
with astop
value of0%
.Available in Safari 4.0 and later.
- Parameters
- Discussion
- Availability
to
A convenience function for the color-stop
function that specifies the last color stop in a gradient.
to(color) |
The color of the gradient at the stop.
color
Equivalent to calling
color-stop()
with astop
value of100%
.Available in Safari 4.0 and later.
- Parameters
- Discussion
- Availability
-webkit-gradient
Generates a gradient image.
-webkit-gradient(type, start_point, end_point, / stop...) |
-webkit-gradient(type, inner_center, inner_radius, outer_center, outer_radius, / stop...) |
The type of gradient. Can be
linear
orradial
.The point in the image at which the linear gradient begins.
The point in the image at which the linear gradient ends.
A
color-stop()
function indicating the desired color for the gradient at a particular point in its progression.The center point of the inner, starting circle in a radial gradient.
The radius of the inner, starting circle in a radial gradient.
The center point of the outer, ending circle in a radial gradient.
The radius of the outer, ending circle in a radial gradient.
type
start_point
end_point
stop
inner_center
inner_radius
outer_center
outer_radius
The point corresponding to the top left corner of the image.
The point corresponding to the bottom left corner of the image.
The point corresponding to the top right corner of the image.
The point corresponding to the bottom right corner of the image.
left top
left bottom
right top
right bottom
-webkit-gradient()
can be used in any place an image URL is used.A linear gradient determines its color by interpolating between values specified by the
color-stop()
functions provided. Eachcolor-stop()
function specifies a percentage or a decimal between0
and1
and a color, indicating that the gradient should have the specified color value at the specified fraction of the gradient’s length. The shorthand functionsfrom()
andto()
are supported as special-casecolor-stop()
functions. The following example creates a linear gradient that shifts from yellow to orange in its first half and from orange to red in its second half, moving from the top left of the image to the bottom right of the image:-webkit-gradient(linear, left top, right bottom, from(#ff0), color-stop(0.5, orange), to(rgb(255, 0, 0));
A radial gradient specifies its start and end with two (typically concentric) circles, each identified by a center point and radius. The color value at a point between the circumference of the inner circle and the circumference of the outer circle is determined by interpolating between
color-stop()
functions. The color value inside the inner circle is the color value of the firstcolor-stop()
function.Available in Safari 4.0 and later.
- Parameters
- Constants
- Discussion
- Availability
-webkit-linear-gradient
Generates a linear gradient image.
-webkit-linear-gradient(direction | angle, color_stop,... ) |
Specifies the gradient line which gives the gradient a direction and determines how color stops are positioned. Possible values are described in “Constants.” The default value is
top
.Optionally, specifies the gradient line as an angle value where
0
degrees is east,90
degrees is north, and positive angles are counter-clockwise.A color for the gradient at a particular point in its progression. You can specify multiple color stops including a start and end color.
Color stops are expressed as two values with the following syntax: color | stop.
The color of the gradient at the stop. This parameter is mandatory.
The point in the gradient that should have the specified color value. The position can be specified in pixels or as a percentage of the gradient line. When a position is not specified, the browser distributes the color stop evenly between the adjacent color stops. Color stops at the same position result in sharp color changes.
color
stop
direction
angle
color_stop
The bottom side of the image.
The bottom left corner of the image.
The bottom right corner of the image.
The left side of the image.
The top side of the image.
The top left corner of the image.
The top right corner of the image.
The right side of the image.
bottom
bottom left
bottom right
left
top
top left
top right
right
Parameters that have default values are optional. However, two or more color stops are required to render a gradient.
For example, you can create a paper roll effect on one side:
.ribbon {
background-image:
-webkit-linear-gradient(
left, #900, #F33 10px, red 50px);
}
This can be combined with another gradient to create a ribbon with a diagonal edge:
.ribbon {
background-image:
-webkit-linear-gradient(
left, #900, #F33 10px, rgba(255, 0, 0, 0) 50px),
-webkit-linear-gradient(135deg, transparent 25%, red 25%);
}
Available in Safari 5.1 and later.
Available in iOS 5.0 and later.
- Parameters
- Constants
- Discussion
- Availability
-webkit-radial-gradient
Generates a radial gradient image.
-webkit-radial-gradient(center, [shape || size] | [length | percentage], color_stop,...) |
The center point of the cirlce or ellipse. This parameter allows you to move the origin of the shape. The position can be specified in terms of pixels or percentages of the image or using the keywords
top
,left
,center
,right
, orbottom
. The default iscenter
.The shape of the radient. Possible values are
circle
andellipse
. The default isellipse
.The size of the radient. Possible values are
closest-side
,closest-corner
,farthest-side
,farthest-corner
,contain
, andcover
. The default iscover
.Optionally, specifies the shape of an eclipse by providing two lengths: the length of the horizontal and vertical axes of the ellipse. The axis length is the length from the center of the ellipse to the edge, not the diameter. The lengths must be non-negative.
Optionally, specifies the shape of an eclipse by providing two percentage values: the percentage of the horizontal and vertical axes of the eclipse relative to the width and height of the box. The percentages must be non-negative.
A color for the gradient at a particular point in its progression. You can specify multiple color stops including a start and end color.
Color stops are expressed as two values with the following syntax: color | stop.
The color of the gradient at the stop. This parameter is mandatory.
The point in the gradient that should have the specified color value. The position can be specified in pixels or as a percentage of the gradient line. When a position is not specified, the browser distributes the color stop evenly between the adjacent color stops. Color stops at the same position result in sharp color changes.
color
stop
For example, specify a gradient that progresses equally from red to green and then green to blue as follows:
-webkit-linear-gradient(left, red, green, blue)
Specify a gradient where red starts at
20px
and blue starts at90%
with other colors distributed between as follows:-webkit-linear-gradient(bottom left, red 20px, yellow, green, blue 90%)
Create a sharp color change between green and purple as follows:
-webkit-linear-gradient(top left, red, yellow, green 60%, purple 60%, blue)
center
shape
size
length
percentage
color_stop
Parameters that have default values are optional. However, one or more color stops are required to render a gradient. If only one parameter is provided before the color stops and it could be interpreted as either a position or an explicit size, it is assumed to be a position.
For example, the following gradient is centered in the box and is large enough to fill it to the corners:
-webkit-radial-gradient(white, black)
This is equivalent to:
-webkit-radial-gradient(center, ellipse cover, white, black)
You can also specify an alternate origin than
center
as follows:-webkit-radial-gradient(10% 30%, white, black)
Examples of specifying the shape and size of the gradient are:
-webkit-radial-gradient(30% 30%, closest-corner, white, black)
-webkit-radial-gradient(30% 30%, circle closest-corner, white, black)
where
circle
specifies the shape andclosest-corner
specifies the size.You can also specify the ending radius of the gradient explicitly and separately for the horizontal and vertical axes:
-webkit-radial-gradient(center, 5em 40px, white, black)
where
5em
is the x-value and40px
is the y-value.If only percentages appear before color stops, the parameters are interpreted as a starting point, not the size of the ellipse:
-webkit-radial-gradient(10% 10%, red, blue)
Available in Safari 5.1 and later.
Available in iOS 5.0 and later.
- Parameters
- Discussion
- Availability
-webkit-repeating-linear-gradient
Generates a linear gradient where the specified color stops repeat in both directions to fill the image.
-webkit-linear-gradient(direction | angle, color_stop,... ) |
Specifies the gradient line which gives the gradient a direction and determines how color stops are positioned. Possible values are described in “Constants.” The default value is
top
.Specifies the gradient line as an angle value where
0
degrees is east,90
degrees is north, and positive angles are counter-clockwise.A color for the gradient at a particular point in its progression. You can specify multiple color stops including a start and end color.
Color stops are expressed as two values with the following syntax: color | stop.
The color of the gradient at the stop. This parameter is mandatory.
The point in the gradient that should have the specified color value. The position can be specified in pixels or as a percentage of the gradient line. When a position is not specified, the browser distributes the color stop evenly between the adjacent color stops. Color stops at the same position result in sharp color changes.
color
stop
direction
angle
color_stop
The bottom side of the image.
The bottom left corner of the image.
The bottom right corner of the image.
The left side of the image.
The top side of the image.
The top left corner of the image.
The top right corner of the image.
The right side of the image.
bottom
bottom left
bottom right
left
top
top left
top right
right
The parameters are the same as
-webkit-linear-gradient
except the color stops are repeated. If a parameter is omitted, the default value is used.The specified color stops are repeated infinitely in both directions by aligning them end-to-end. For example, this gradient:
-webkit-repeating-linear-gradient(red 10px, blue 50px)
is interpreted as:
-webkit-repeating-linear-gradient(..., red -30px, blue 10px, red 10px, blue 50px, red 50px, blue 90px, ...)
Note that the boundary between the last color stop and the first color stop may result in a sharp color change. To avoid this, use the same color in the first and last color stop as in:
-webkit-repeating-linear-gradient(red, blue 10%, red 20%)
Available in Safari 5.1 and later.
Available in iOS 5.0 and later.
- Parameters
- Constants
- Discussion
- Availability
-webkit-repeating-radial-gradient
Generates a radial gradient where the specified color stops repeat in both directions to fill the image.
-webkit-radial-gradient(start_position, [shape || size] | [length | percentage], color_stop,...) |
The starting point of the radial gradient. This parameter allows you to move the origin of the shape. The position can be specified in terms of pixels or percentages of the image or using the keywords
top
,left
,center
,right
, orbottom
. The default iscenter
.The shape of the radient. Possible values are
circle
andellipse
. The default isellipse
.The size of the radient. Possible values are
closest-side
,closest-corner
,farthest-side
,farthest-corner
,contain
, andcover
. The default iscover
.Specifies the shape of an eclipse by providing two lengths: the length of the horizontal and vertical axes of the ellipse. The axis length is the length from the center of the ellipse to the edge, not the diameter. The lengths must be non-negative.
Specifies the shape of an eclipse by providing two percentage values: the percentage of the horizontal and vertical axes of the eclipse relative to the width and height of the box. The percentages must be non-negative.
A color for the gradient at a particular point in its progression. You can specify multiple color stops including a start and end color.
Color stops are expressed as two values with the following syntax: color | stop.
The color of the gradient at the stop. This parameter is mandatory.
The point in the gradient that should have the specified color value. The position can be specified in pixels or as a percentage of the gradient line. When a position is not specified, the browser distributes the color stop evenly between the adjacent color stops. Color stops at the same position result in sharp color changes.
color
stop
start_position
shape
size
length
percentage
color_stop
The parameters are the same as
-webkit-radial-gradient
except the color stops are repeated. If a parameter is omitted, the default value is used.For example, you can create a bulls-eye effect as follows:
-webkit-repeating-radial-gradient(
transparent, rgba(0, 0, 0, 0.3) 50px);
Available in Safari 5.1 and later.
Available in iOS 5.0 and later.
- Parameters
- Discussion
- Availability
Timing Functions
Timing functions specify the easing technique for animations.
cubic-bezier
Specifies a cubic Bézier curve.
cubic-bezier(P1x,P1y,P2x,P2y)
First point in the Bézier curve.
Second point in the Bézier curve.
P1x, P1y
P2x, P2y
A cubic Bézier curve is defined by four control points,
P0
throughP3
.P0
andP3
are always set to(0,0)
and(1,1)
. This function is used to set the values for the points in between, pointsP1
andP2
. Each point is specified by both an x and y value.Available in Safari 3.1 and later.
Available in iOS 2.0 and later.
- Parameters
- Discussion
- Availability
steps
Defines steps from one frame to another, not a smooth transition.
steps(number, point)
The number of intervals in the function. Must be greater than
0
.The point at which the change of values occur within the interval. Possible values are
start
orend
. The default value isend
.
number
point
Stepping functions are appropriate for progress indicators. A stepping function is defined by a number of equal duration intervals and whether the change in output percentage happens at the start or end of the interval.
Available in iOS 5.0 and later.
- Parameters
- Discussion
- Availability
Transform Functions
Transform functions can be passed to the -webkit-transform
property.
matrix
Specifies a 2D transformation in the form of a transformation matrix of six values.
matrix(m11, m12, m21, m22, tX, tY)
Elements of a 2 x 2 matrix in column-major order.
1,1
2,1
1,2
2,2
- m11, m12, m21, m22
The x and y translation elements.
- tX, tY
Passing
matrix(a,b,c,d,e,f)
is equivalent to applying the transformation matrix[a b c d e f]
.Available in Safari 3.1 and later.
Available in iOS 2.0 and later.
- Parameters
- Discussion
- Availability
matrix3d
Specifies a 3D transformation as a 4 x 4 matrix.
matrix3d(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m31, m33)
Defines a 4 x 4 homogeneous matrix of 16 values in column-major order (
0,0
;0,1
;0,2
; ...).0,0
1,0
2,0
3,0
0,1
1,1
2,1
3,1
0,2
1,2
2,2
3,2
0,3
1,3
2,3
3,3
- m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m31, m33
Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later.
Available in iOS 2.0 and later.
- Parameters
- Availability
perspective
Specifies a perspective projection matrix.
perspective(depth)
The distance, in pixels, of the z=0 plane from the viewer.
- depth
This matrix maps a viewing cube onto a pyramid whose base is infinitely far away from the viewer and whose peak represents the viewer's position.
The viewable area is the region bounded by the four edges of the viewport (the portion of the browser window used for rendering the webpage between the viewer’s position and a point at a distance of infinity from the viewer).
Lower values for this property give a more flattened pyramid and therefore a more pronounced perspective effect. A value of 1000 pixels gives a moderate amount of foreshortening, and a value of 200 pixels gives an extreme amount.
Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later.
Available in iOS 2.0 and later.
- Parameters
- Discussion
- Availability
rotate
Specifies a 2D rotation around the origin of the element.
rotate(angle)
The rotation angle. The angle may be specified using
deg
,rad
orgrad
units.
- angle
The rotation operation corresponds to the matrix
[cos(angle) sin(angle) -sin(angle) cos(angle) 0 0]
. The origin of the element is specified using the-webkit-transform-origin
property.Available in Safari 3.1 and later.
Available in iOS 2.0 and later.
- Parameters
- Discussion
- Availability
rotate3d
Specifies a clockwise 3D rotation.
rotate3d(x, y, z, angle)
The
[x,y,z]
direction vector for the rotation.If the direction vector is not of unit length, it will be normalized. If the direction vector cannot be normalized, such as
[0, 0, 0]
, the rotation will not be applied.
- x, y, z
The rotation angle. The angle may be specified using
deg
,rad
orgrad
units.
- angle
Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later.
Available in iOS 2.0 and later.
- Parameters
- Availability
rotateX
Specifies a clockwise rotation by the given angle about the x-axis.
rotateX(angle)
The rotation angle. The angle may be specified using
deg
,rad
orgrad
units.
- angle
Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later. Available in iOS 2.0 and later.
- Parameters
- Availability
rotateY
Specifies a clockwise rotation by the given angle about the y-axis.
rotateY(angle)
The rotation angle. The angle may be specified using
deg
,rad
orgrad
units.
- angle
Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later.
Available in iOS 2.0 and later.
- Parameters
- Availability
rotateZ
Specifies a clockwise rotation by the given angle about the z-axis.
rotateZ(angle)
The angle of the rotation. The angle may be specified using
deg
,rad
orgrad
units.
- angle
Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later.
Available in iOS 2.0 and later.
- Parameters
- Availability
scale
Specifies a 2D scale operation.
scale(scaleX [, scaleY])
The scaling factor to apply in the x direction.
- scaleX
The scaling factor to apply in the y direction. If not specified, defaults to scaleX.
- scaleY
Available in Safari 3.1 and later.
Available in iOS 2.0 and later.
- Parameters
- Availability
scale3d
Specifies a 3D scale operation.
scale3d(scaleX, scaleY, scaleZ)
The scaling factor to apply in the x direction.
- scaleX
The scaling factor to apply in the y direction.
- scaleY
The scaling factor to apply in the z direction.
- scaleZ
Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later.
Available in iOS 2.0 and later.
- Parameters
- Availability
scaleX
Scales in the x direction.
scaleX(sx)
The scaling factor to apply to the x direction.
- sx
This function specifies a scale operation using the
[sx, 1, 1]
scaling vector.Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later.
Available in iOS 2.0 and later.
- Parameters
- Discussion
- Availability
scaleY
Scales in the y direction.
scaleY(sy)
The scaling factor to apply to the y direction.
- sy
This function specifies a scale operation using the
[1,sy,1]
scaling vector.Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later.
Available in iOS 2.0 and later.
- Parameters
- Discussion
- Availability
scaleZ
Scales in the z direction.
scaleZ(sz)
The scaling factor to apply to the z direction.
- sz
This function specifies a scale operation using the
[1,1,sz]
scaling vector.Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later.
Available in iOS 2.0 and later.
- Parameters
- Discussion
- Availability
skew
Specifies a skew transformation along the x and y axes by given angles.
skew(angleX [, angleY])
The angle of the skew along the x-axis. The angle may be specified using
deg
,rad
orgrad
units.The angle of the skew along the y-axis. The angle may be specified using
deg
,rad
orgrad
units. If not specified, defaults to0
.
- angleX
- angleY
Available in Safari 3.1 and later.
Available in iOS 2.0 and later.
- Parameters
- Availability
skewX
Specifies a skew transformation along the x-axis by the given angle.
skewX(angle)
The angle of the skew. The angle may be specified using
deg
,rad
orgrad
units.
- angle
Available in Safari 3.1 and later. Available in iOS 2.0 and later.
- Parameters
- Availability
skewY
Specifies a skew transformation along the x-axis by the given angle.
skewY(angle)
The angle of the skew. The angle may be specified using
deg
,rad
orgrad
units.
- angle
Available in Safari 3.1 and later.
Available in iOS 2.0 and later.
- Parameters
- Availability
translate
Specifies a 2D translation vector.
translate(deltaX [, deltaY])
The number of units to translate along the x-axis. This value may be a percentage or a length.
- deltaX
The number of units to translate along the y-axis. If not specified, the y translation defaults to
0
. This value may be a percentage or a length.
- deltaY
Available in Safari 3.1 and later.
Available in iOS 2.0 and later.
- Parameters
- Availability
translate3d
Specifies a 3D translation vector.
translate3d(deltaX, deltaY, deltaZ)
The number of units to translate along the x-axis. This value may be a percentage or a length.
- deltaX
The number of units to translate along the y-axis. This value may be a percentage or a length.
- deltaY
The number of units to translate along the z-axis. This value may be a percentage or a length.
- deltaZ
Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later. Available in iOS 2.0 and later.
- Parameters
- Availability
translateX
Specifies a translation in the x direction.
translateX(deltaX)
The number of units to translate along the x-axis. This value may be a percentage or a length.
- deltaX
Available in Safari 3.1 and later.
Available in iOS 2.0 and later.
- Parameters
- Availability
translateY
Specifies a translation in the y direction.
translateY(deltaY)
The number of units to translate along the y-axis. This value may be a percentage or a length.
- deltaY
Available in Safari 3.1 and later. Available in iOS 2.0 and later.
- Parameters
- Availability
translateZ
Specifies a translation in the z direction.
translateZ(deltaZ)
The number of units to translate along the z-axis. This value may be a percentage or a length.
- deltaZ
Available in Safari 4.0.3 and later running on Mac OS X v10.6 and later.
Available in iOS 2.0 and later.
- Parameters
- Availability
Filter Functions
Filters are visual effects that can be applied to images and other HTML elements. These functions can be concatenated in any order as parameters to the -webkit-filter
property. These functions can be animated over time with the -webkit-animation
property.
blur
Applies a Gaussian blur to the element.
blur(radius) |
The blur radius, in pixels.
radius
The radius is a specific CSS length and does not accept percentage values.
Available in Safari 6.0 and later.
- Parameters
- Discussion
- Availability
brightness
Applies a linear multiplier to the image, making it brighter or darker.
brightness(amount) |
The amount of brightness, as a percentage.
amount
An amount of
-100%
will create an image that is completely black. An amount of100%
will create an image that is completely white. An amount of0%
leaves the input unchanged.Available in Safari 6.0 and later.
- Parameters
- Discussion
- Availability
contrast
Adjusts the contrast of the element.
contrast(amount) |
The amount of contrast, as a percentage.
amount
An amount of
0%
will create an image that is completely gray. An amount of100%
leaves the image unchanged. Amounts in between linearly affect the contrast.Available in Safari 6.0 and later.
- Parameters
- Discussion
- Availability
drop-shadow
Applies a drop shadow effect to the image.
drop-shadow(h-off v-off blur color) |
The horizontal offset of the shadow, in pixels.
The vertical offset of the shadow, in pixels.
The blur radius of the shadow, in pixels.
The color of the shadow.
h-off
v-off
blur
color
The function accepts the same parameters as the
-webkit-box-shadow
property, with the exception that theinset
keyword is not allowed.Available in Safari 6.0 and later.
- Parameters
- Discussion
- Availability
grayscale
Desaturates the image.
grayscale(amount) |
The percentage of desaturation.
amount
An amount of
100%
is completely grayscale. An amount of0%
leaves the image unchanged.Available in Safari 6.0 and later.
- Parameters
- Discussion
- Availability
hue-rotate
Desaturates the image.
hue-rotate(angle) |
The number of degrees around the color circle the image’s color samples will be adjusted.
angle
An angle of
0deg
leaves the image unchanged.Available in Safari 6.0 and later.
- Parameters
- Discussion
- Availability
invert
Inverts the colors of the image.
invert(amount) |
The percentage of inversion.
amount
An amount of
100%
is completely inverted. An amount of0%
leaves the image unchanged. Amounts in between are linear multipliers on the effect.Available in Safari 6.0 and later.
- Parameters
- Discussion
- Availability
opacity
Applies transparency to the image.
opacity(amount) |
The percentage of opacity.
amount
An amount of
0%
is completely transparent. An amount of100%
leaves the image unchanged.Available in Safari 6.0 and later.
- Parameters
- Discussion
- Availability
saturate
Saturates the image.
saturate(amount) |
The percentage of saturation.
amount
An amount of
0%
is completely unsaturated. An amount of100%
leaves the image unchanged. Amounts over100%
are allowed, providing super-saturated results.Available in Safari 6.0 and later.
- Parameters
- Discussion
- Availability
sepia
Applies a sepia effect to the image.
sepia(amount) |
The percentage of sepia effect to apply.
amount
An amount of
100%
is completely sepia. An amount of0%
leaves the input unchanged. Amounts in between are linear multipliers on the effect.Available in Safari 6.0 and later.
- Parameters
- Discussion
- Availability
JavaScript Helper Functions
-webkit-canvas
Specifies a canvas for drawing programmatically with Javascript.
-webkit-canvas(canvas) |
The name of the canvas.
canvas
The
-webkit-canvas()
function can be used in any place an image URL is used.Canvases specified with the
-webkit-canvas()
function can be accessed in Javascript with the methodgetCSSCanvasContext()
, which returns aCanvasRenderingContext
object. The identifier passed togetCSSCanvasContext()
should be the same as the value forcanvas
.Specifying a new width or height for the canvas in subsequent calls to
getCSSCanvasContext()
clears the canvas buffer.Available in Safari 4.0 and later.
- Parameters
- Discussion
- Availability
Copyright © 2016 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2016-10-27