CSS values are used in conjunction with CSS properties to determine how elements are styled and displayed on a web page. They can be keywords, numbers, lengths, colors, URLs, and more. Here is a detailed overview of various CSS values categorized by their types:
Keywords are predefined constant values used in CSS properties.
color: inherit;
color: initial;
color: unset;
display: none;
Numbers can be integers or floating-point numbers used in various properties like z-index, opacity, etc.
-index: 10;
opacity: 0.75;
Lengths specify a distance measurement. They can be absolute or relative units.
Fixed units that are not relative to other elements.
3.1.1. px (pixels)
font-size: 16px;
3.1.2. cm (centimeters)
margin: 2cm;
3.1.3. mm (millimeters)
padding: 5mm;
3.1.4. in (inches)
border-width: 1in;
3.1.5. pt (points)
font-size: 12pt;
3.1.6. pc (picas)
margin: 1pc;
Units that are relative to other measurements.
3.2.1. em (relative to the font-size of the element)
padding: 2em;
3.2.2. rem (relative to the font-size of the root element)
margin: 1.5rem;
3.2.3. % (percentage, relative to the parent element)
width: 50%;
3.2.4. vw (viewport width)
width: 50vw;
3.2.5. vh (viewport height)
height: 50vh;
3.2.6. vmin (minimum of viewport width or height)
font-size: 2vmin;
3.2.7. vmax (maximum of viewport width or height)
font-size: 2vmax;
Colors define the color of text, borders, backgrounds, etc. They can be specified using color names, hexadecimal values, RGB, RGBA, HSL, and HSLA.
color: blue;
color: #ff0000;
color: rgb(255, 0, 0);
color: rgba(255, 0, 0, 0.5);
color: hsl(120, 100%, 50%);
color: hsla(120, 100%, 50%, 0.3);
URLs are used in properties that reference external resources like images, fonts, etc.
background-image: url('image.jpg');
CSS functions are used to calculate values, define color transformations, etc.
width: calc(100% - 50px);
color: var(--main-color);
color: rgb(255, 0, 0);
color: rgba(255, 0, 0, 0.5);
color: hsl(120, 100%, 50%);
color: hsla(120, 100%, 50%, 0.3);
background-image: url('image.jpg');