CHAPTER 01
Beginner
CSS Basics for Beginners
Updated: May 10, 2026
15 min read
Introduction
What is CSS?
CSS stands for Cascading Style Sheets. If HTML is the skeleton of a webpage, CSS is the skin, clothing, and makeup. It dictates how the HTML elements are displayed on screen.How CSS Works
CSS works by selecting an HTML element (like an<h1> or a <div>) and declaring specific visual rules for it (like color: blue;).
Types of CSS
-
1.
Inline CSS:
<p style="color: red;">
-
2.
Internal CSS: Inside a
<style>tag in the HTML<head>.
-
3.
External CSS: Written in a separate
.cssfile and linked:<link rel="stylesheet" href="styles.css">.
CSS Syntax
css
Selectors
-
Element Selector:
p { color: gray; }
-
Class Selector:
.btn-primary { background-color: blue; }
-
ID Selector:
#main-header { font-size: 30px; }
-
Universal Selector:
* { margin: 0; }
Colors & Backgrounds
-
*Names*:
red,blue
-
*Hex Codes*:
#FF0000
-
*RGB*:
rgb(255, 0, 0)
Borders & The Box Model
Every HTML element is a box:- 1. Content: Actual text/image.
- 2. Padding: Transparent space *inside* the border.
- 3. Border: Outline around padding.
- 4. Margin: Transparent space *outside* the border.
css
Typography
css
Display & Positioning
-
display: block: Takes full width.
-
display: inline: Takes necessary width.
-
position: static: Default.
-
position: absolute: Pulled out of flow.
-
position: fixed: Sticks to viewport.
Flexbox
css
CSS Grid
css
Responsive Design
css
Transitions & Hover Effects
css
Best Practices
- 1. Group related rules.
- 2. Use Classes, Not IDs.
- 3. Use logical naming conventions.
-
4.
Reset CSS:
* { margin: 0; padding: 0; box-sizing: border-box; }
Common Beginner Mistakes
-
1.
Forgetting semicolons
;.
- 2. Confusing Margin and Padding.
- 3. Using Inline Styles.
-
4.
Overusing
!important.
- 5. Spelling errors.
-
6.
Forgetting units (
width: 100instead of100px).
- 7. Not building Mobile-First.
- 8. Targeting generic tags too much.
- 9. Misunderstanding Box Model.
- 10. Using absolute positioning for everything.