Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Rules  ›  Lesson

Properties and Values

Properties & Values 12 minEach declaration needs a real property and a value of the type that property accepts, or the browser silently ignores it.

Properties and Values

You write colour: green; and the prices stay black. No warning, no error, just nothing. CSS is forgiving in a way that hides mistakes: if the browser does not recognise a property or a value, it ignores that declaration and moves on.

The rule

Known property, valid value, or the browser quietly skips it.

Properties come from a fixed list defined by the CSS standards: color, background-color, font-size, margin, width and several hundred more. They are lower case, use hyphens between words, and use American spelling. You cannot invent one.

Values must fit the property. The common kinds are:

  • Keywords: plain words the property understands, such as bold, center, none, auto.
  • Lengths: a number glued to a unit, such as 16px, 1.5rem, 2em, 50%.
  • Numbers with no unit, for properties that take them, such as font-weight: 700 or line-height: 1.5.
  • Colours, as names (teal), hex (#0a7f5a), or functions such as rgb(10 127 90).

Two unit rules catch almost everyone:

  • No space between number and unit. 16px is a length; 16 px is invalid.
  • Zero needs no unit. margin: 0 is fine, but any other bare number where a length is needed, like width: 20, is invalid.
.dish h3 {
  font-size: 1.25rem;  /* length */
  font-weight: 600;    /* number */
  text-align: center;  /* keyword */
  color: #1d3557;      /* colour */
}

The shortcut

When a style "does nothing", check three things, in order: spelling of the property, validity of the value, and the unit. Browser developer tools help: a declaration they do not understand is usually shown struck through or with a warning icon.

Why is the heading not bigger?Step 1 of 4
  1. The rule

    .dish h3 { font-size: 24 px; }, and the heading is unchanged.

Drills

Answer fast — trust the rule.

quick drill

What happens to colour: green; in a stylesheet?

quick drill

Which declaration is valid?

quick drill

In font-weight: bold;, what kind of value is bold?

quick drill

A rule has color: green; width: 20; font-weight: 700;. Which declarations apply?

Remember

  • Properties come from a fixed list; values must suit the property.
  • Debug in order: property spelling, value, unit.
  • No space before a unit, and only zero may drop its unit.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainDebug the silent failure

The rule .price { colour: green; font-size: 18 px; font-weight: 700; } only makes the prices bold. Explain why each of the other two declarations failed and how to fix them.