CSS (Cascading Style Sheets) is a stylesheet language used to describe the presentation of a document written in HTML or XML. CSS describes how elements should be rendered on screen, on paper, in speech, or on other media.
Basic Structure of CSS
CSS is made up of rules. Each rule consists of a selector and a declaration block.
selector {
propertyName1: value1;
propertyName2: value2;
}
Selector: This is the HTML element you want to style.
Declaration block: This contains one or more declarations separated by semicolons. Each declaration includes a CSS property name and a value, separated by a colon.
Example: Here’s a simple example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Example</title>
<style>
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
</style>
</head>
<body>
<h1>Hello, world!</h1>
</body>
</html>
In this example:
The body selector styles the entire page’s background to be light blue.
The h1 selector changes the color of the heading to navy and adds a left margin.
CSS Tutorial – Questions and Answers
Q 1: What is CSS?
Ans: CSS (Cascading Style Sheets) is used to style and design HTML elements like colors, fonts, layouts, and spacing.
Q 2: Why is CSS important?
Ans: CSS separates content from design, improves website appearance, and makes pages easier to maintain.
Q 3: What are the different ways to add CSS?
Ans: Inline CSS, Internal CSS, and External CSS.
Q 4: What does “Cascading” mean in CSS?
Ans: It means styles are applied based on priority rules like specificity and order.
Q 5: Can CSS be used for responsive design?
Ans: Yes, CSS supports responsive design using media queries and flexible layouts.
CSS Tutorial– Objective Questions (MCQs)
Q1. What does CSS stand for?
Q2. Which tag is used to apply internal CSS?
Q3. Which HTML attribute is used for inline CSS?
Q4. Which CSS is applied directly inside an HTML element?
Q5. Which file extension is used for CSS?