CSS Syntax

CSS (Cascading Style Sheets) is used to style and layout web pages. Here’s an overview of the basic syntax and how to use it:

Basic Structure

A CSS rule consists of a selector and a declaration block:


selector {
    property: value;
    property: value;
    ...
}

Example:- In this example, I created class container and defined property background-color which has value #ff0000 (It is a red color) and property color which has #FFFF00 ( it is a yellow color)


.container {
 background-color: "#ff0000";  /*red color*/
 color: "#FFFF00";   /*yellow color*/
} 

Try it Yourself

CSS Syntax – Interview Questions

Q 1: It separates multiple CSS declarations.
Ans:
" . 
                htmlspecialchars(
                "selector {
                 property: value;} . 
                "
",
Q 2: What is a selector in CSS?
Ans: A selector targets the HTML element to apply styles.
Q 3: What is a property in CSS?
Ans: A property defines what aspect of an element is being styled.
Q 4: What is a value in CSS?
Ans: A value specifies the style for a property.
Q 5: Why is semicolon used in CSS?
Ans: It separates multiple CSS declarations.

CSS Syntax – Objective Questions (MCQs)

Q1. What is the correct CSS syntax?






Q2. Which symbol is used to separate property and value?






Q3. Which symbol ends a CSS declaration?






Q4. In p {color:red;}, what is p?






Q5. In p {color:red;}, what is red?






Related CSS Syntax Topics