What is Cascading Style Sheets (CSS)

Cascading Style Sheets (CSS) specifies the appearance and the formatting of an HTML document.

Defining and Applying a Style

A CSS style is made up of one or more declarations separated by a semi-colon. Each declaration consists of a CSS property and a value separated by a colon.


background-color:grey; 
color:white;

In the code above, the style has two declarations. background-color and color are called properties. The first sets the value grey for the background-color property. The second sets the value white for the color property.

 
<!DOCTYPE HTML> 
<html> 
    <head> 
        <title>Example</title> 
        <style type="text/css"> 
        a { 
            background-color:grey; 
            color:white 
        } 
        </style> 
    </head> 
    <body> 
        <a href="http://java2s.com">Visit the website</a> 
        <a href="http://java2s.com">Visit the website</a> 
    </body> 
</html>
  
Click to view the demo

The declaration block is always enclosed in curly brackets. A declaration block can contain several declarations.

Each declaration must be terminated with a semicolon (;). The semicolon for the final declaration in a declaration block is optional.

Each property is separated from its value by a colon (:). Property names in CSS are not case-sensitive.

Home 
  HTML CSS Book 
    CSS  

Introduction:
  1. What is Cascading Style Sheets (CSS)
  2. Adding Styles to HTML
  3. Specifying the Character Encoding of a Stylesheet
  4. How Styles Cascade and Inherit
  5. Element Classification
  6. Cascading Style Sheets prefixes for the most popular browsers
Related: