Syntax / Rules

CSS is made up of rules consisting of three parts:

  • Selector
    • HTML element that the style will be applied to
    • e.g. <h1>
  • Property
    • Style attribute of the element
    • e.g. color
  • Value
    • Corresponding value for the property
    • e.g. blue

 

 

The selector specifies which elements to style, and is followed by a declaration block that begins with a left curly brace { closes with a right curly brace } that contains the property/value pair declarations.

 

The property/value pair are separated by a colon and end with a semi colon.

 

Example:

h1color: blue; font-size: 2em; }

 

<!DOCTYPE html>
<html>
	<head>
		<meta></meta>
		<link></link>
		<title>Document Title</title>
		<style>
			h1 { color: blue; font-size: 2em; }
		</style>
	</head>
	<body>
		<h1>A very simple page</h1>
	</body>
</html>

Save & refresh browser:

A very simple page

 

 

The syntax rules depicted using code:

iframe source*

Leave a Reply