-
Hajipur, Bihar, 844101
CSS comments are used to explain your code or to temporarily disable part of your CSS.
They do not affect how the CSS runs and are completely ignored by the browser.
/* This is a comment */
Starts with /*
Ends with */
Can be placed on a separate line or inline with code
/* Set background color */
body {
background-color: lightgray;
}
p {
color: blue; /* Make text blue */
}
/*
h1 {
color: red;
}
*/
✅ The above rule will not apply because it’s inside a comment block.
To explain sections of your code
To organize long stylesheets
To debug by temporarily turning styles off
Q1. Add a comment before setting the text color of all <h1>
elements.
Q2. Add a comment above a rule that changes the font size of paragraphs.
Q3. Write a CSS rule for <body>
with a comment explaining the background color.
Q4. Add an inline comment to a rule that sets the color of <h2>
to red.
Q5. Write a comment to describe the purpose of a .box
class.
Q6. Temporarily disable a CSS rule that adds a border to all images.
Q7. Add a comment inside the CSS file explaining that a section is for buttons.
Q8. Comment out the entire CSS block for .card
.
Q9. Add a comment stating that a section of CSS applies only to the homepage.
Q10. Add a comment to explain why box-sizing: border-box;
is being used.
Q1: What is the correct syntax for a CSS comment?
Q2: Which of these comments will work in CSS?
Q3: What happens to code inside a CSS comment?
Q4: Which of the following is NOT a valid use of comments?
Q5: Which symbol ends a CSS comment?
Q6: Where can you place a CSS comment?
Q7: How would you comment out a CSS rule?
Q8: Which comment style is correct for multiple lines in CSS?
Q9: What is the main benefit of using comments in CSS?
Q10: What happens if you forget to close a comment with */?