π¨ Introduction to CSS β Styling the Web

When you open a beautiful, colorful, and well-aligned website, it's all thanks to CSS β Cascading Style Sheets. While HTML provides the structure of a webpage, CSS controls how that structure looks. In this post, weβll explore the key concepts of CSS in a way thatβs easy to understand for beginners.
What is CSS?
CSS (Cascading Style Sheets) is a language used to style HTML elements. It allows you to control the colors, layouts, fonts, sizes, and much more on your webpage.
Example:
<p style="color: blue;">This text is blue.</p>
You can change styles without modifying the HTML structure, keeping content and design separate.
Ways to Add CSS
There are three main ways to use CSS in your HTML document:
- β Inline CSS β Inside the HTML tag (not recommended for large projects)
<h1 style="color: red;">Hello</h1>
- β
Internal CSS β Inside a
<style>
tag in the<head>
section
<style>
p {
color: green;
}
</style>
- β External CSS β Linked from an external file (recommended)
<link rel="stylesheet" href="styles.css">
CSS Selectors
Selectors are used to target HTML elements you want to style.
Element Selector:
p { }
targets all<p>
tagsClass Selector:
.box { }
targets elements with class "box"ID Selector:
#header { }
targets an element with ID "header"
.box {
background-color: yellow;
}
CSS Properties
CSS uses property-value pairs to style elements.
Common properties:
color
: Text colorbackground-color
: Background colorfont-size
: Size of textmargin
: Space outside the elementpadding
: Space inside the elementborder
: Outline around the element
h1{
color: purple;
font-size: 32px;
}
Box Model
Everything in CSS is a box! The box model consists of:
Content β Text or image
Padding β Space around content
Border β Line around the padding
Margin β Space outside the border
Understanding this helps in designing neat layouts.
Positioning Elements
CSS lets you control where elements appear using:
static
(default)relative
absolute
fixed
sticky
Each has different behavior in how it interacts with the document flow.
Responsive Design
To make your site look good on all devices, CSS includes tools like:
- Media Queries
@media (max-width: 600px) {
body {
background-color: lightblue;
}
}
- Flexbox and Grid for layouts that adapt to screen size.
CSS is what brings life to HTML pages. It makes your website not only functional but also visually appealing and user-friendly. As you dive deeper, you'll discover powerful features like animations, transitions, and layout systems that make modern web design possible.
So go ahead, experiment with styles, and create something beautiful! π¨π»
Subscribe to my newsletter
Read articles from Vaishnavi Sanjay Desai directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
