<alpha-value> CSS type

The <alpha-value> CSS data type represents a value that can be either a <number> or a <percentage>, specifying the alpha channel or transparency of a color.

Associated functions

This data type is accepted as a parameter in the following CSS functions:

Syntax

css
/* <number> values */
0
0.125
0.5
1

/* <percentage> values */
0%
12.5%
50%
100%

Values

This data type is specified as one of the following values:

<number>

A positive value between 0 and 1, inclusive

<percentage>

A <percentage> between 0% and 100%, inclusive.

Values outside the ranges, though valid, are clamped to the nearest limit in the range.

Description

An <alpha-value> is given as either a <number> or a <percentage>.

If given as a number, the useful range is 0 (fully transparent) to 1.0 (fully opaque), with decimal values in between. For example, 0.5 indicates that half of the foreground color is used and half of the background color is used. Values outside the range of 0 to 1 are permitted, but are clamped to the range of 0 to 1.

If the alpha value is given as a percentage, 0% corresponds to fully transparent while 100% indicates fully opaque.

Interpolation

When animated, values of the <alpha-value> CSS data type are interpolated as real, floating-point numbers. The speed of the interpolation is determined by the easing function associated with the animation.

Formal syntax

<alpha-value> = 
<number> |
<percentage>

Examples

Setting text color opacity

The example demonstrates applying a color with 60% opacity using the <alpha-value> as a parameter within an rgb() function, which accepts an optional fourth parameter specifying an alpha value:

css
/* <rgb()> */
color: rgb(34 12 64 / 60%);

Specifications

Specification
CSS Color Module Level 4
# typedef-color-alpha-value

See also