# π§© CSS Fundamentals β Selectors, Properties & Basic Styling
**By <>DevSync
A perfect guide for beginners to understand how CSS works with real examples and outputs.
πΉ What is CSS?
CSS stands for Cascading Style Sheets. It defines the presentation of your HTML elements β colors, fonts, layouts, spacing, and more. While HTML gives structure, CSS brings it to life.
πΉ CSS Syntax & Structure
selector {
property: value;
}
β Example:
p {
color: red;
}
This styles all <p>
elements with red text.
π Output:
<p style="color: red;">This is a red paragraph.</p>
πΉ Types of CSS
1. Inline CSS
CSS written directly inside an HTML tag using the style
attribute.
<p style="color: green;">Iβm styled inline!</p>
2. Internal CSS
CSS written inside a <style>
block in the <head>
of the HTML document.
<head>
<style>
p {
color: blue;
}
</style>
</head>
3. External CSS
Linked to an external .css
file.
<link rel="stylesheet" href="styles.css">
Inside styles.css
:
p {
color: orange;
}
πΉ CSS Selectors
CSS selectors target HTML elements for styling. Here are the most common types:
Selector | Example | What it Selects |
---|---|---|
Universal | * |
All elements |
Type | p |
All <p> tags |
Class | .highlight |
Elements with class="highlight" |
ID | #title |
Element with id="title" |
Descendant | div p |
All <p> inside <div>
|
Child | div > p |
Direct <p> child of <div>
|
Adjacent Sibling | div + p |
<p> immediately after <div>
|
General Sibling | div ~ p |
All <p> siblings after <div>
|
πΉ Basic Styling Properties
Letβs style text and elements using core CSS properties.
π Text Styling
h1 {
color: purple;
font-size: 24px;
font-family: 'Arial', sans-serif;
text-align: center;
text-transform: uppercase;
}
β Output:
<h1 style="color: purple; font-size: 24px; text-transform: uppercase;">
CSS is Awesome!
</h1>
π Box Styling (Borders, Padding, Margin)
.box {
border: 2px solid black;
padding: 10px;
margin: 20px;
background-color: #f5f5f5;
}
β Output:
<div style="border: 2px solid black; padding: 10px; margin: 20px;">
I am a styled box!
</div>
π Color Styling
body {
background-color: #e0f7fa;
color: #333;
}
β Output:
This would make your webpage have a light cyan background and dark gray text.
β Summary
CSS gives your HTML structure style, spacing, layout, and personality. In this blog, youβve learned:
- What CSS is and how it works
- 3 Types of CSS usage
- Selectors to target elements
- Basic styling like fonts, colors, borders, and spacing
π Coming Up Next
In Blog 2(#) weβll cover the CSS Box Model, layout systems like Flexbox & Grid, and how to position your elements effectively!
Author : Yash Kalbhute
β¨ Brought to you by <>DevSync β Building powerful frontend knowledge, one line of CSS at a time.
Top comments (0)