Recent Post

Friday, 28 August 2026

Complete CSS Notes By Pratap Sanjay Sir

Complete CSS Notes - Basic to Advanced | Pratap Sanjay Sir
🎨 Web Styling Mastery

Complete CSS Notes

Master Cascading Style Sheets with Comprehensive Notes, Clean CSS Syntax & Live Rendered Outputs for Every Property.

📖 48+ CSS Properties 🎯 Flexbox & Modern Grid ✨ Animations & Transforms 👨‍🏫 Prepared by Pratap Sanjay Sir

🎨 Introduction to CSS

CSS stands for Cascading Style Sheets. It is a styling language used to describe the presentation, colors, formatting, and responsive layout of a web document written in HTML.

3 Ways to Apply CSS:

1. Inline CSS: Written directly inside an HTML tag using the style attribute.

2. Internal CSS: Written inside the <style> tag within the HTML <head> section.

3. External CSS: Written in a separate .css file and linked using <link rel="stylesheet" href="style.css">.

1. CSS Selectors & Syntax

selector { property: value; } Core Rule
📝 Theory & Notes:

A CSS rule consists of a Selector and a Declaration Block.

The selector targets the HTML element you want to design, while each declaration contains a CSS property name and its value separated by a colon.

💻 CSS Code:
/* Element Selector */ p { color: #2563eb; font-size: 18px; } /* Class Selector */ .highlight { background-color: #fef08a; padding: 4px 8px; border-radius: 4px; }
🌐 Output Preview:

This paragraph is styled using an element & class selector.

2. CSS Color & Background

color, background-color Styling
📝 Theory & Notes:

The color property sets foreground text color, while background-color defines the background fill color of any element.

Colors can be set with color names, Hex codes (#dc2626), or RGB/RGBA functions.

💻 CSS Code:
.color-box { color: #dc2626; background-color: #fef08a; padding: 12px; border-radius: 6px; font-weight: bold; }
🌐 Output Preview:
This box has red text on a bright yellow background.

3. CSS Font Properties

font-size, font-family, font-weight Typography
📝 Theory & Notes:

font-size controls text size, font-family specifies the font face, and font-weight adjusts thickness (e.g., bold, 600, normal).

💻 CSS Code:
.custom-font { font-family: 'Segoe UI', Tahoma, sans-serif; font-size: 22px; font-weight: 700; font-style: italic; color: #1e3a8a; }
🌐 Output Preview:

Bold, Italic 22px Segoe UI Font Example

4. Text Alignment, Decoration & Transform

text-align, text-decoration, text-transform Typography
📝 Theory & Notes:

text-align aligns text horizontally (center, left, right).

text-decoration adds lines like underlines, and text-transform changes capitalization (uppercase, lowercase, capitalize).

💻 CSS Code:
.text-formatting { text-align: center; text-decoration: underline; text-transform: uppercase; color: #0f172a; }
🌐 Output Preview:

Centered Underlined Uppercase Heading

5. Letter Spacing, Word Spacing & Line Height

letter-spacing, word-spacing, line-height Spacing
📝 Theory & Notes:

letter-spacing adjusts character spacing, word-spacing controls spaces between words, and line-height sets vertical line height for comfortable reading.

💻 CSS Code:
.spaced-text { letter-spacing: 2px; word-spacing: 6px; line-height: 1.9; }
🌐 Output Preview:

CSS provides fine-grained control over letter spacing, word separation, and comfortable line heights for clean typography.

6. CSS Border & Border Radius

border, border-radius Box Styling
📝 Theory & Notes:

border defines the stroke width, style (solid, dashed, dotted), and color around an element.

border-radius softens box sharp corners into rounded edges.

💻 CSS Code:
.rounded-box { border: 3px solid #2563eb; border-radius: 16px; padding: 16px; background-color: #eff6ff; }
🌐 Output Preview:
Box with 3px solid blue border and 16px rounded corners.

7. Width & Height Dimensions

width, height Dimensions
📝 Theory & Notes:

width and height explicitly set the dimensional bounds of elements using units like px, %, vw, or vh.

💻 CSS Code:
.dimension-box { width: 280px; height: 80px; background-color: #bbf7d0; border: 1px solid #4ade80; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
🌐 Output Preview:
Width: 280px | Height: 80px

8. Margin & Padding

margin, padding Spacing
📝 Theory & Notes:

Margin creates space outside the border, pushing nearby elements away.

Padding creates breathing room inside the border around the content.

💻 CSS Code:
.spacing-box { margin: 15px 0; padding: 20px; background-color: #fed7aa; border: 2px solid #ea580c; border-radius: 8px; }
🌐 Output Preview:
Padding is the inner space around this text; Margin keeps other elements outside.

9. The CSS Box Model

Content, Padding, Border, Margin Core Architecture
📝 Theory & Notes:

Every element is rendered as a box composed of four concentric layers:

1. Content: Text and media inside the element.

2. Padding: Transparent space around content.

3. Border: Outline enclosing the padding.

4. Margin: Transparent space separating the box from neighbors.

💻 CSS Code:
.box-model-container { box-sizing: border-box; padding: 15px; border: 4px solid #1e293b; margin: 15px; }
🌐 Output Preview:
MARGIN LAYER
BORDER LAYER
PADDING LAYER
CONTENT AREA

10. CSS Display & Visibility

display, visibility Layout Flow
📝 Theory & Notes:

display: block begins on a new line and takes full width.

display: inline-block flows inline while retaining custom width and height.

display: none removes an element from the flow entirely, whereas visibility: hidden hides it while reserving its layout space.

💻 CSS Code:
.block-item { display: block; background: #e0f2fe; margin-bottom: 8px; } .inline-item { display: inline-block; background: #fef08a; padding: 6px 12px; }
🌐 Output Preview:
Block Element (Takes full row width)
Inline-Block 1 Inline-Block 2

11. CSS Opacity & Overflow

opacity, overflow Visual & Scroll
📝 Theory & Notes:

opacity sets transparency from 0.0 (transparent) to 1.0 (solid).

overflow: auto or scroll adds scrollbars when content exceeds container boundaries.

💻 CSS Code:
.translucent-box { opacity: 0.5; } .scroll-container { width: 260px; height: 80px; overflow: auto; border: 1px solid #cbd5e1; }
🌐 Output Preview:
50% Opacity Box
This box has overflow: auto enabled. Scroll inside this container to read all overflow text easily.

12. CSS Lists & Table Styling

list-style-type, border-collapse Structure
📝 Theory & Notes:

list-style-type: square; changes list bullet markers.

border-collapse: collapse; combines table borders into a single clean border grid.

💻 CSS Code:
table { border-collapse: collapse; width: 100%; } th, td { border: 1px solid #cbd5e1; padding: 8px 12px; }
🌐 Output Preview:
Subject Score
Computer Science 100

13. Links & Pseudo Classes / Elements

:hover, ::first-letter Interactivity
📝 Theory & Notes:

:hover applies styles when a user points their mouse cursor over an element.

::first-letter styles the first character of a block of text specifically.

💻 CSS Code:
a.custom-link { color: #2563eb; text-decoration: none; font-weight: bold; } a.custom-link:hover { color: #dc2626; text-decoration: underline; }
🌐 Output Preview:

14. CSS Positioning & Z-Index

position: relative / absolute, z-index Layout Control
📝 Theory & Notes:

position: relative anchors child elements positioned with position: absolute.

z-index controls the layering order of overlapping elements (higher numbers appear in front).

💻 CSS Code:
.parent-box { position: relative; width: 100%; height: 100px; background-color: #e0f2fe; } .child-badge { position: absolute; top: 12px; right: 12px; background-color: #ef4444; color: white; z-index: 10; }
🌐 Output Preview:
Parent Box (position: relative)
Child Badge (absolute)

15. CSS Float & Clear

float: left, clear Legacy Flow
📝 Theory & Notes:

float: left pushes an element to the left side and allows following text to wrap neatly around it.

💻 CSS Code:
.float-box { float: left; width: 110px; margin-right: 15px; background: #bfdbfe; padding: 10px; }
🌐 Output Preview:
Floated Box

This paragraph text naturally wraps around the floated box element on its left side. This technique was widely used for magazine-style layouts.

16. CSS Flexbox (1D Layout System)

display: flex, justify-content, gap Modern Layout
📝 Theory & Notes:

Flexbox simplifies distributing space and aligning items horizontally and vertically along a single direction (row or column).

💻 CSS Code:
.flex-container { display: flex; justify-content: center; align-items: center; gap: 15px; background-color: #f1f5f9; padding: 16px; } .flex-item { background-color: #2563eb; color: white; padding: 12px 20px; border-radius: 6px; }
🌐 Output Preview:
Flex 1
Flex 2
Flex 3

17. Flex Direction & Column Layout

flex-direction: column Modern Layout
📝 Theory & Notes:

flex-direction: column; stacks flex children vertically while maintaining alignment control.

💻 CSS Code:
.flex-column { display: flex; flex-direction: column; gap: 10px; }
🌐 Output Preview:
Column Item 1
Column Item 2

18. CSS Grid (2D Layout System)

display: grid, repeat(3, 1fr) Modern Layout
📝 Theory & Notes:

CSS Grid handles both columns and rows simultaneously, allowing complex two-dimensional structured web layouts.

💻 CSS Code:
.grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; } .grid-item { background-color: #7c3aed; color: white; padding: 16px; text-align: center; border-radius: 6px; }
🌐 Output Preview:
1
2
3

19. Linear & Radial Gradients

linear-gradient, radial-gradient Color FX
📝 Theory & Notes:

linear-gradient blends colors along a directional angle.

radial-gradient radiates color transitions outward from a central circular or elliptical point.

💻 CSS Code:
.linear-box { background: linear-gradient(135deg, #2563eb, #9333ea); color: white; padding: 18px; } .radial-box { background: radial-gradient(circle, #f59e0b, #ef4444); color: white; padding: 18px; }
🌐 Output Preview:
Linear Gradient
Radial Gradient

20. Box Shadow & Text Shadow

box-shadow, text-shadow Elevation FX
📝 Theory & Notes:

box-shadow adds elevation depth behind containers.

text-shadow renders subtle shadows underneath typography.

💻 CSS Code:
.shadow-card { box-shadow: 0 10px 25px rgba(37, 99, 235, 0.25); padding: 16px; background: white; } .shadow-text { text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3); }
🌐 Output Preview:
Box Shadow Elevation

21. CSS 2D Transforms

transform: rotate(), scale() Geometry FX
📝 Theory & Notes:

The transform property rotates, scales, moves (translate), and skews elements without disrupting surrounding document layout.

💻 CSS Code:
.rotated-box { transform: rotate(4deg); background: #fef08a; padding: 12px; }
🌐 Output Preview:
Rotated by 3 Degrees

22. CSS Transitions

transition: all 0.3s ease Motion
📝 Theory & Notes:

CSS Transitions allow smooth property animations over time instead of abrupt jumps when hovering or changing states.

💻 CSS Code:
.smooth-btn { background: #2563eb; color: white; padding: 12px 24px; transition: all 0.3s ease; } .smooth-btn:hover { background: #1d4ed8; transform: scale(1.05); }
🌐 Output Preview:

23. Keyframe Animations

@keyframes, animation Dynamic Motion
📝 Theory & Notes:

@keyframes creates complex multi-step animated sequences. The animation shorthand defines name, duration, and iteration count.

💻 CSS Code:
@keyframes moveBox { 0% { transform: translateX(0); } 50% { transform: translateX(160px) rotate(180deg); } 100% { transform: translateX(0); } } .animated-box { animation: moveBox 3s infinite ease-in-out; }
🌐 Output Preview:

24. CSS Custom Properties (Variables)

:root, --brand-color, var() Modern CSS
📝 Theory & Notes:

Variables store reusable values declared with double dashes (--primary-color) and accessed with var(--primary-color).

💻 CSS Code:
:root { --main-blue: #2563eb; --bg-tint: #eff6ff; } .themed-box { color: var(--main-blue); background-color: var(--bg-tint); border: 1px solid var(--main-blue); }
🌐 Output Preview:
This box dynamically applies colors from CSS custom variables.

25. CSS calc() Function

calc(100% - 40px) Math Function
📝 Theory & Notes:

calc() enables mathematical computations directly in CSS properties, blending relative and absolute units freely.

💻 CSS Code:
.calc-width-box { width: calc(100% - 40px); background-color: #bbf7d0; padding: 12px; }
🌐 Output Preview:
Width dynamically evaluated to calc(100% - 30px)

26. CSS Media Queries (Responsive Design)

@media screen and (max-width: ...) Responsive
📝 Theory & Notes:

Media queries apply conditional styles depending on viewport width, adapting layouts across mobile phones, tablets, and desktop displays.

💻 CSS Code:
@media screen and (max-width: 600px) { .responsive-box { width: 100%; background-color: #fef08a; } }
🌐 Output Preview:
Resize your browser window to test responsive CSS media query breakpoints in real time.

27. CSS Cursor Styles

cursor: pointer, grab, not-allowed UX Styling
📝 Theory & Notes:

The cursor property defines what mouse pointer icon is displayed when hovering over an element (pointer, grab, not-allowed).

💻 CSS Code:
.cursor-pointer { cursor: pointer; } .cursor-grab { cursor: grab; } .cursor-disabled { cursor: not-allowed; }
🌐 Output Preview:
cursor: pointer cursor: grab cursor: not-allowed

28. CSS Object-Fit & Image Filters

object-fit: cover, filter: grayscale() Media FX
📝 Theory & Notes:

object-fit: cover scales an image to fill its parent without stretching distortion.

filter applies effects like grayscale(), blur(), and brightness().

💻 CSS Code:
img.filtered { width: 220px; height: 100px; object-fit: cover; filter: grayscale(100%); }
🌐 Output Preview:
Grayscale Filter Preview

29. CSS Clip-Path (Geometric Masking)

clip-path: circle(50%) Masking
📝 Theory & Notes:

clip-path cuts an element into custom geometric forms such as circles, polygons, or stars.

💻 CSS Code:
.circle-mask { width: 80px; height: 80px; background: linear-gradient(135deg, #ef4444, #f97316); clip-path: circle(50%); }
🌐 Output Preview:
Circle

30. CSS Glassmorphism Effect

backdrop-filter: blur(10px) Modern UI
📝 Theory & Notes:

Glassmorphism produces a translucent frosted glass aesthetic by combining semi-transparent background alpha values with backdrop-filter: blur().

💻 CSS Code:
.glass-card { background: rgba(255, 255, 255, 0.4); backdrop-filter: blur(10px); border: 1px solid rgba(255, 255, 255, 0.5); border-radius: 12px; padding: 20px; }
🌐 Output Preview:
✨ Frosted Glassmorphic Surface

31. Modern Card UI Component

UI Component Design Pattern
📝 Theory & Notes:

Combining padding, subtle border-radius, elevation box shadows, and hover transitions produces modern interactive card components.

💻 CSS Code:
.card { background: white; border-radius: 12px; padding: 20px; box-shadow: 0 4px 15px rgba(0,0,0,0.06); transition: transform 0.3s ease; } .card:hover { transform: translateY(-6px); }
🌐 Output Preview:

Interactive Card

Hover over this card to observe elevation and lifting motion.

32. Modern Button Design

.modern-btn:hover UI Control
📝 Theory & Notes:

Clean button designs utilize custom padding, active transitions, rounded borders, and cursor styling for superior user experience.

💻 CSS Code:
.modern-button { background-color: #2563eb; color: white; border: none; border-radius: 8px; padding: 12px 25px; cursor: pointer; transition: 0.3s; } .modern-button:hover { background-color: #1d4ed8; transform: scale(1.05); }
🌐 Output Preview:

33. Responsive Navigation Bar

display: flex, justify-content: space-between Navigation
📝 Theory & Notes:

Navigation bars leverage Flexbox with space-between to position branding and navigation links cleanly along opposite ends.

💻 CSS Code:
.navbar { display: flex; justify-content: space-between; align-items: center; background-color: #0f172a; padding: 14px 20px; border-radius: 8px; } .navbar a { color: white; text-decoration: none; margin-left: 14px; }
🌐 Output Preview:

34. Responsive Auto-Fit Grid

repeat(auto-fit, minmax(180px, 1fr)) Responsive Layout
📝 Theory & Notes:

The auto-fit with minmax() technique generates responsive grid columns that adapt without requiring manual media query breakpoints.

💻 CSS Code:
.responsive-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
🌐 Output Preview:
Auto 1
Auto 2
Auto 3

35. CSS Summary & Key Takeaways

🎓 Revision Box
📝 Key Exam & Practical Rules:

Syntax Formula: selector { property: value; }

Box Model Order: Content $\rightarrow$ Padding $\rightarrow$ Border $\rightarrow$ Margin

Layout Selection: Use Flexbox for 1D rows/columns and CSS Grid for 2D matrix layouts.

Responsive Principle: Always use * { box-sizing: border-box; } and media queries for mobile-friendly designs.

🎉 Message for Students:

Congratulations! 🚀

You have mastered CSS styling fundamentals, Flexbox & Grid systems, animations, variables, and responsive layout designs.

Keep building creative web pages and practicing CSS regularly! 🎨💻

Complete CSS Notes • Web Design & Coding

Prepared by Pratap Sanjay Sir | Learn CSS with Theory, Pure Syntax & Live Previews

No comments:

"कोशिश करो तो सब कुछ हो सकता है, न करो तो कुछ नहीं हो सकता।"