CSS HTML Javascript jQuery Ajax PHP Example Java MORE

CSS Syntax

CSS syntax or rule-set is consists of a selector and declaration block.

So let’s discuss one by one:

Selector: Selector indicates the HTML element you want to add style. It could be any HTML tag like <h1> , <p> , <title> etc.

Declaration Block: The declaration block can contain more than one declaration.One declaration contains one property and one value.

Property: A Property is a type of attribute of the HTML element. It could be color, border, etc.

Value: Values are assigned to CSS properties. In the above example, the value "yellow" is assigned to the color property.

CSS Comments:

CSS comments are used to specify what’s the code all about and for future understanding. When we see the code after some month or year we can easily understand the code through these comments.

CSS supports both single-line comments and multiple line comments. A CSS comment starts with /* and ends with */. Comments can also span multiple lines:

Example:
<!DOCTYPE html>
<html>
<head>
<style>
p {
  color: red;/* Define color red for all <p> tag */
  text-align: center;
} 

h1 {
  text-align: center;
  
/* color: red;
  font-wight: 500;*/
} 

</style>
</head>
<body>

<h1>Hello World!</h1>
<p>This paragraph is styled with CSS.</p>
<p>CSS comments are not shown in the output.</p>

</body>
</html>

Run it yourself