-
Hajipur, Bihar, 844101
CSS syntax is the way we write rules to style HTML elements. Each rule consists of:
A Selector – targets the HTML element.
A Declaration Block – contains one or more declarations inside curly braces {}
.
A Declaration – consists of a property and a value, separated by a colon :
.
selector {
property: value;
}
p {
color: red;
font-size: 18px;
}
p
is the selector.
color
and font-size
are properties.
red
and 18px
are values.
Declarations are separated by semicolons and wrapped in {}
.
CSS comments are used to explain the code. They are not displayed in the browser.
/* This is a CSS comment */
body {
background-color: lightblue;
}
Part | Example | Description |
---|---|---|
Selector | p |
Targets paragraph elements |
Property | color |
Style to apply |
Value | red |
Setting of the property |
Declaration | color: red; |
Full style instruction |
Rule | p { color: red; } |
Complete CSS rule |
Q1. Write a CSS rule to set the color of all <h1>
elements to red.
Q2. Write a CSS rule to change the background color of the <body>
to yellow.
Q3. Write a CSS rule to make all <p>
elements bold.
Q4. Write a CSS rule to assign 300px width to all <div>
elements.
Q5. Add a comment above a rule that styles <h2>
headings.
Q6. Write a CSS rule to set Arial font for the <body>
.
Q7. Write a CSS rule to center-align all <h3>
text.
Q8. Write a CSS rule to give 20px padding to all <div>
elements.
Q9. Write a CSS rule to set blue color and italic style for <p>
elements.
Q10. Write a CSS rule to set grey background and 18px font size to the <body>
.
Q1: What symbol is used to define a block of CSS rules?
Q2: How do you write a comment in CSS?
Q3: What does this rule do: p { color: red; }?
Q4: What is the correct CSS syntax to set font size?
Q5: How are multiple declarations separated?
Q6: Which is the correct selector for all <p> elements?
Q7: What is the purpose of a selector in CSS?
Q8: Which part of the rule is font-size?
Q9: What is the correct syntax to change background color?
Q10: Which file extension is used for CSS files?