Introduction to CSS

What is CSS?

CSS (Cascading Style Sheets) is a language used to describe the style of an HTML document. It allows you to control the layout, colors, fonts, spacing, and more of your web pages.

1. How to Apply CSS

CSS can be applied to HTML in three different ways:

2. Basic CSS Syntax

The basic syntax of CSS is as follows:

            
                selector {
                    property: value;
                }
            
        

Example:

            
                p {
                    color: red;
                }
            
        

This CSS rule will change the text color of all <p> tags to red.

3. CSS Selectors

CSS uses selectors to target HTML elements. Some common types of selectors are:

4. Styling Text and Boxes

Here are a few common properties:

5. Example: Basic CSS Styling

Below is an example of how we can use CSS to style a box:

Styled Box

This box is styled with CSS.

6. CSS Box Model

The CSS Box Model consists of the following parts:

Quiz: Test Your Knowledge

1. What is CSS used for?




2. Which of the following is the correct syntax to change the text color of a paragraph?




3. What does the margin property do?