Introduction

CSS (Cascading Style Sheets) allows you to style HTML elements, defining how they should look like.

CSS Syntax

Each CSS rule has the following:

  • one or more selectors (these indicate which HTML elements should be affected by the rule)
  • one or more declarations in the form of property-value pairs (these define what the rule does)
Basic CSS syntax: selector, property, and value.
Basic CSS syntax: selector, property, and value.

Anything between /* and */ are comments and do nothing.

Example

<!-- Style -->
<style>
  /* Make all <b> with class "example" red and 24px */
  b.example {
    color: red;
    font-size: 24px;
  }
  /* Make all <em> and <u> with class "example" green */
  i.example, u.example {
    color: green;
  }
</style>

<!-- Content -->
<b class="example">one</b>
<i class="example">two</i>
<u class="example">three</u>
| LIVE PREVIEW
one two three