What To Know About Selectors, Properties And Values In CSS

Posted by TotalDC

In this article, you dive deeper and learn about selectors, properties, and values in CSS. Selectors are the names given to styles in internal and external CSS. For each selector, there are properties written inside curly brackets like – color, font-size, or background-color.

A value is given to the property after the colon and then semi-colons are used at the end to separate the properties. Like that:

body {
    font-size: 14px;
    color: lightgrey;

This will apply the given values to the font-size and color properties of body selector.

Length and Percentage

There are many specific units for values used in CSS, but there are some general units that are used by many properties and it is worth familiarizing yourself with these before going forward.

  • px  is the unit for pixels.
  • em  is the unit for the calculated size of a font.
  • pt  is the unit for points, for measurements typically in printed media.
  • %  is the unit for percentages.

Other units include pc (picas), cm (centimeters), mm (millimeters) and in (inches).

When a value is zero, you do not need to state a unit. For example, if you wanted to specify no border, it would be border: 0.