CSS Course for Beginners
CSS Course for Beginners
What is CSS?
CSS stands for Cascading Style Sheets. It is the language used to describe how HTML elements
should appear on the screen. While HTML is used to create the structure of a web page, CSS is
used to style and lay it out.
Why use CSS?
To make your website look attractive.
To apply consistent styles across multiple web pages.
To control layout and appearance for different screen sizes.
"Cascading" means that if more than one style rule applies to an element, the browser decides
which one to use based on specificity and order.
HTML (index.html):
<head>
<link rel="stylesheet" href="style.css">
</head>
CSS (style.css):
body {
background-color: #f4f4f4;
color: #333;
}
Use: Best practice for real websites. Keeps styling separate and organized.
CSS Syntax
CSS consists of selectors and declarations.
selector {
property: value;
}
Example:
h1 {
color: green;
font-size: 24px;
}
h1 is the selector (targets all <h1> elements).
color and font-size are properties.
green and 24px are values.
Multiple declarations are enclosed in {} and separated by ;.
Background Styling
Example:
body {
background-color: lightblue;
background-image: url('bg.jpg');
background-repeat: no-repeat;
background-size: cover;
background-position: center;
}
background-color: sets background color
background-image: sets image
background-repeat: repeat or no-repeat
background-size: contain, cover, etc.
background-position: top, center, etc.
Position Property
Used to place elements precisely.
Types:
static (default)
relative (relative to itself)
absolute (relative to parent)
fixed (relative to browser window)
div {
position: absolute;
top: 20px;
left: 50px;
}
.title {
color: darkblue;
font-size: 32px;
}
.desc {
font-size: 18px;
color: #555;
}
.photo {
width: 200px;
border-radius: 50%;
border: 3px solid navy;
}
Practice Tasks
Task 1:
Create a web page with:
Pink background
Heading in green, 36px
Paragraphs in italic and centered
Image with a border
Task 2:
Use media queries to:
Change background to lightgray on small screens
Increase font size of heading on large screens