Web Development
79.1K subscribers
1.41K photos
1 video
2 files
754 links
Learn Web Development From Scratch

0️⃣ HTML / CSS
1️⃣ JavaScript
2️⃣ React / Vue / Angular
3️⃣ Node.js / Express
4️⃣ REST API
5️⃣ SQL / NoSQL Databases
6️⃣ UI / UX Design
7️⃣ Git / GitHub

Admin: @love_data
Download Telegram
𝟯 𝗙𝗥𝗘𝗘 𝗛𝘂𝗯𝗦𝗽𝗼𝘁 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻𝘀 𝗳𝗼𝗿 𝗦𝘁𝘂𝗱𝗲𝗻𝘁𝘀 & 𝗙𝗿𝗲𝘀𝗵𝗲𝗿𝘀 𝗶𝗻 𝟮𝟬𝟮𝟲🎓

💫HubSpot Academy offers three free online certifications that match these interests.

💫Pick one free course and try it out on your next college event and the certification is free.

🔗 𝗟𝗶𝗻𝗸 :- 👇

https://pdlink.in/4iM5xaQ

📲 *Save & Share with your friends! 🔥*
𝗙𝗥𝗘𝗘 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 𝗧𝗼 𝗚𝗲𝘁 𝗬𝗼𝘂𝗿 𝗗𝗿𝗲𝗮𝗺 𝗝𝗼𝗯 𝗜𝗡 𝗚𝗼𝗼𝗴𝗹𝗲🔥

Discover *4 FREE resources* to help you prepare for a career at Google!

✅ Improve Your Coding Skills
✅ Strengthen Interview Preparation
✅ Build Technical Knowledge
✅ Prepare for Top Tech Opportunities

🎓Perfect for Students, Freshers & Aspiring Software Engineers!

🔗 𝗟𝗶𝗻𝗸 👇:-

https://pdlink.in/4AwRPQy

📲 SAVE & SHARE with friends dreaming of working at Google!
❤1
𝗙𝗥𝗘𝗘 𝗩𝗜𝗥𝗧𝗨𝗔𝗟 𝗜𝗡𝗧𝗘𝗥𝗡𝗦𝗛𝗜𝗣𝗦 𝗪𝗜𝗧𝗛 𝗧𝗢𝗣 𝗖𝗢𝗠𝗣𝗔𝗡𝗜𝗘𝗦! 🎓

💻 Explore FREE Virtual Internship & Job Simulation Programs from leading companies!

✅ Learn Industry-Relevant Skills
✅ Work on Practical Tasks
✅ Self-Paced Online Learning
✅ Explore Completion Certificates
✅ Strengthen Your Resume & LinkedIn Profile

🎯 Perfect for Students, Freshers & Job Seekers

🔗 𝗟𝗶𝗻𝗸 👇:-

https://pdlink.in/4t8DRlq

📲 SAVE & SHARE with friends looking for career opportunities!
❤1
𝟰 𝗙𝗥𝗘𝗘 𝗖𝗼𝘂𝗿𝘀𝗲𝘀 𝗧𝗼 𝗠𝗮𝘀𝘁𝗲𝗿 𝗘𝘅𝗰𝗲𝗹 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘 📊

🎓 Explore 4 FREE Excel Courses to upgrade your skills!

✅ Excel Formulas & Functions
✅ Pivot Tables & Charts
✅ Data Cleaning & Analysis
✅ Dashboards & Reporting

🎯 Perfect for Students, Freshers & Aspiring Data Analysts!

🔗 𝗟𝗶𝗻𝗸 👇:-

https://pdlink.in/48mO4B2

📌 SAVE & SHARE with friends who want to master Excel! 🔥
🌐 Web Development Roadmap: Part 33

CSS Positioning (Static, Relative, Absolute, Fixed & Sticky)

CSS positioning controls where an HTML element appears on a webpage.

It allows you to place elements in specific locations, overlap elements, create floating buttons, and build sticky navigation bars.

There are five important CSS position values:

• static

• relative

• absolute

• fixed

• sticky

1. Position: Static

static is the default positioning behavior of HTML elements.

Elements appear in the normal document flow.

.box {
position: static;
}


Important points:

• Elements follow the normal page layout.

• They appear one after another according to the document structure.

• top, right, bottom, and left do not reposition a static element.

2. Position: Relative

relative positions an element relative to its original position.

<div class="box">Hello World</div>


.box {
position: relative;
top: 20px;
left: 30px;
}


What happens?

• The element moves 20px down.

• The element moves 30px to the right.

• Its original space in the document flow remains reserved.

Real-world use: Making small adjustments to an element or creating a positioning reference for an absolutely positioned child.

3. Position: Absolute

absolute positions an element relative to its nearest positioned ancestor.

A positioned ancestor means an ancestor whose position is not static.

Example:

<div class="parent">
<div class="child">Hello</div>
</div>


.parent {
position: relative;
width: 300px;
height: 200px;
background-color: lightblue;
}

.child {
position: absolute;
top: 10px;
right: 10px;
background-color: orange;
}


Here:

• The parent acts as the positioning reference.

• The child appears 10px from the parent's top and right edges.

• The child is removed from the normal document flow.

Real-world use: Badges on product images, notification labels, and icons inside input fields.

4. Position: Fixed

fixed positions an element relative to the viewport.

It generally stays in the same position even when the user scrolls the webpage.

.chat-button {
position: fixed;
bottom: 20px;
right: 20px;
background-color: blue;
color: white;
padding: 15px;
}


Real-world use:

• Floating chat buttons

• Back-to-top buttons

• Fixed action buttons

5. Position: Sticky

sticky combines normal document flow with fixed-like behavior.

The element behaves normally until it reaches a specified scroll position, then sticks within its scrolling container.

nav {
position: sticky;
top: 0;
background-color: navy;
color: white;
}


Here, the navigation bar sticks to the top when the page is scrolled to it.

Common uses:

• Sticky navigation bars

• Table headers

• Section headings

6. Understanding Top, Right, Bottom & Left

These properties control the position of an element when used with a positioning mode that supports offsets.

.box {
position: absolute;
top: 20px;
right: 30px;
bottom: 10px;
left: 40px;
}
❤3
• top: Distance from the top

• right: Distance from the right

• bottom: Distance from the bottom

• left: Distance from the left

7. What Is Z-Index?
z-index

controls the stacking order of overlapping elements.

An element with a higher stacking level generally appears in front of one with a lower stacking level, when they belong to the same stacking context.
<div class="box box1">Box 1</div>
<div class="box box2">Box 2</div>

.box {
    position: absolute;
    width: 150px;
    height: 150px;
}

.box1 {
    background-color: blue;
    z-index: 1;
}

.box2 {
    background-color: red;
    left: 50px;
    top: 50px;
    z-index: 2;
}

Here, Box 2 appears in front of Box 1 where they overlap.

8. CSS Position Comparison

• static: Normal document flow

• relative: Moves relative to original position

• absolute: Positioned relative to nearest positioned ancestor

• fixed: Positioned relative to viewport

• sticky: Sticks after reaching a scroll threshold

9. Real-World Example: Product Image Badge

HTML:
<div class="product">
    <span class="badge">SALE</span>
    <img src="product.jpg" alt="Product">
    <h2>Wireless Headphones</h2>
    <p>Price: ₹2,499</p>
</div>

CSS:
.product {
    position: relative;
    width: 300px;
}

.product img {
    width: 100%;
}

.badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background-color: red;
    color: white;
    padding: 8px 12px;
    border-radius: 5px;
}


The SALE badge appears in the top-right corner of the product image.

Double Tap ❤️ For More
❤10
𝗠𝗜𝗖𝗥𝗢𝗦𝗢𝗙𝗧 𝗣𝗢𝗪𝗘𝗥 𝗕𝗜 – 𝗙𝗥𝗘𝗘 𝗖𝗢𝗨𝗥𝗦𝗘! 📊

😍 Want to master Power BI & Data Analytics without spending ₹1?

🎓 Explore Microsoft's FREE Power BI learning resources!

✅ Data Visualization & Dashboards
✅ Power Query & Data Cleaning
✅ DAX Formulas & Data Modeling
✅ Business Intelligence Skills

🎯 Perfect for Students, Freshers & Aspiring Data Analysts!

🔗 𝗟𝗶𝗻𝗸 👇:-

https://pdlink.in/4t3Jl0E

📌 SAVE & SHARE with friends interested in Data Analytics! 🔥
❤1
🌐 Web Development Roadmap : Part 34

CSS Flexbox : Building Flexible Website Layouts

CSS Flexbox (Flexible Box Layout) is a CSS layout system used to arrange elements inside a container.

It makes it easier to align, distribute, and organize elements horizontally or vertically.

Flexbox is especially useful for:

• Navigation bars

• Website headers

• Product cards

• Buttons

• Centering content

• Responsive layouts

1. What Is Flexbox?

To use Flexbox, apply display: flex to a parent element.

Example:

<div class="container">
<div class="box">Box 1</div>
<div class="box">Box 2</div>
<div class="box">Box 3</div>
</div>


CSS:

.container {
display: flex;
}

.box {
background-color: lightblue;
padding: 20px;
margin: 10px;
}


The boxes will appear next to each other in a row.

2. Flex Container and Flex Items

Flexbox has two important concepts:

Flex Container: The parent element with display: flex.

Flex Items: The direct child elements inside the flex container.

       Flex Container
┌─────────────────────┐
│ │
│ Box 1 Box 2 Box 3 │
│ │
└─────────────────────┘
↑ ↑ ↑
Flex Items


3. Flex Direction

The flex-direction property controls the direction of flex items.

.container {
display: flex;
flex-direction: row;
}


Common values:

A. row

Arranges items horizontally from left to right.

flex-direction: row;


B. row-reverse

Arranges items horizontally in reverse order.

flex-direction: row-reverse;


C. column

Arranges items vertically from top to bottom.

flex-direction: column;


D. column-reverse

Arranges items vertically in reverse order.

flex-direction: column-reverse;


4. Justify Content

The justify-content property controls how flex items are distributed along the main axis.

.container {
display: flex;
justify-content: center;
}


Important values:

• flex-start: Items at the beginning

• flex-end: Items at the end

• center: Items in the center

• space-between: Equal space between items

• space-around: Space around each item

• space-evenly: Equal spacing between and around items

.container {
display: flex;
justify-content: space-between;
}


This distributes items with equal space between them.

5. Align Items

The align-items property controls alignment along the cross axis.

.container {
display: flex;
align-items: center;
}


• stretch: Stretches items by default when possible.

• flex-start: Aligns items at the start.

• flex-end: Aligns items at the end.

• center: Aligns items in the center.

• baseline: Aligns items according to their text baselines.

Remember:

• justify-content = Main axis alignment.

• align-items = Cross axis alignment.

The main axis depends on the flex-direction.

6. Flex Wrap

By default, flex items try to fit on one line.

The flex-wrap property controls whether items can move onto another line.

.container {
display: flex;
flex-wrap: wrap;
}


flex-wrap: nowrap;
flex-wrap: wrap;
flex-wrap: wrap-reverse;
This is useful when displaying product cards on different screen sizes.

7. Gap

The gap property adds spacing between flex items.

.container {
display: flex;
gap: 20px;
}


You can also define row and column gaps separately:

.container {
display: flex;
row-gap: 10px;
column-gap: 20px;
flex-wrap: wrap;
}


8. Flex Grow

flex-grow determines how much an item can grow relative to other flex items when extra space is available.

.box1 {
flex-grow: 1;
}

.box2 {
flex-grow: 2;
}


Box 2 receives twice as much of the available extra space as Box 1.

9. Flex Shrink

flex-shrink controls how much an item shrinks when there isn't enough space.

.box1 {
flex-shrink: 1;
}

.box2 {
flex-shrink: 0;
}


• 1 = Can shrink.

• 0 = Will not shrink due to the flex-shrink calculation.

10. Flex Basis

flex-basis defines an item's initial main size before remaining space is distributed.

.box {
flex-basis: 200px;
}


It is similar to setting an initial width in a row layout or height in a column layout.

11. Flex Shorthand

You can combine three properties into one:

.box {
flex: 1 1 200px;
}


The order is:

flex: grow shrink basis;

For example:

.box {
flex: 1;
}


This is a common shorthand that allows an item to grow and shrink, with a zero-percent flex basis.

12. Align Self

align-self allows you to override the alignment of an individual flex item.

.box2 {
align-self: flex-end;
}


Other values include:

• auto

• flex-start

• flex-end

• center

• baseline

• stretch

13. Real-World Example: Navigation Bar

HTML:

<nav class="navbar">
<h2>MyWebsite</h2>

<div class="links">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Services</a>
<a href="#">Contact</a>
</div>
</nav>


CSS:

.navbar {
display: flex;
justify-content: space-between;
align-items: center;
padding: 15px 30px;
background-color: navy;
color: white;
}

.links {
display: flex;
gap: 20px;
}

.links a {
color: white;
text-decoration: none;
}


This creates a navigation bar where the website name appears on the left and navigation links appear on the right.

Key Takeaways

• Flexbox makes website layouts easier to build.

• The parent is called the flex container.

• Its direct children are flex items.

• justify-content controls the main axis.

• align-items controls the cross axis.

• flex-wrap helps items move onto multiple lines.

Double Tap ❤️ For Part-35
❤5🔥1🤔1
𝗧𝗢𝗣 𝟱 𝗣𝗟𝗔𝗧𝗙𝗢𝗥𝗠𝗦 𝗧𝗢 𝗙𝗜𝗡𝗗 𝗛𝗜𝗚𝗛-𝗣𝗔𝗬𝗜𝗡𝗚 𝗥𝗘𝗠𝗢𝗧𝗘 𝗧𝗘𝗖𝗛 𝗝𝗢𝗕𝗦!

Explore 5 platforms to discover remote opportunities in:

💻 Software Development
📊 Data Analytics
🤖 AI & Machine Learning
☁️ Cloud Computing
🔐 Cybersecurity

✅ Work-From-Home Opportunities
✅ Explore Global Tech Companies
✅ Find Jobs Matching Your Skills

🔗 𝗟𝗶𝗻𝗸 👇:-

https://pdlink.in/4C6fqci

📌 SAVE & SHARE with friends looking for remote jobs! 🔥
❤4
𝗙𝗥𝗘𝗘 𝗢𝗻𝗹𝗶𝗻𝗲 𝗠𝗮𝘀𝘁𝗲𝗿𝗰𝗹𝗮𝘀𝘀 𝗢𝗻 𝗔𝗜 | 𝗕𝘂𝗶𝗹𝗱 𝗔𝗜-𝗡𝗮𝘁𝗶𝘃𝗲 𝗧𝗲𝗰𝗵 𝗖𝗮𝗿𝗲𝗲𝗿😍

- Get Exclusive 90-Day MAANG Career Roadmap

- Identify Which AI-Era Roles Companies Are Hiring For Now

🎓Eligibility :- Students ,Freshers & Working Professionals

𝗥𝗲𝗴𝗶𝘀𝘁𝗲𝗿 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇 :-

https://pdlink.in/4zQvjC2

Date:- 21st Nov 2026 Time:- 5:00 PM (IST)
❤1
🌐 Web Development Roadmap, Part 35

CSS Grid, Building Two-Dimensional Layouts

CSS Grid is a powerful CSS layout system used to create rows and columns on a webpage.

While Flexbox is mainly designed for one-dimensional layouts (row or column), CSS Grid handles two-dimensional layouts (rows and columns together).

CSS Grid is commonly used for:

• Website layouts

• Image galleries

• Product grids

• Dashboards

• Card layouts

• Responsive web pages

1. What Is CSS Grid?

CSS Grid allows you to divide a webpage into rows and columns and position elements inside that structure.

To activate Grid, use:

.container {
display: grid;
}


Example:

<div class="container">
<div>Box 1</div>
<div>Box 2</div>
<div>Box 3</div>
<div>Box 4</div>
</div>


.container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
}


This creates two equal-width columns.

2. Grid Container and Grid Items

CSS Grid has two important concepts.

Grid Container: The parent element with display: grid.

Grid Items: The direct children inside the grid container.

       Grid Container
┌─────────────┬─────────────┐
│ Box 1 │ Box 2 │
├─────────────┼─────────────┤
│ Box 3 │ Box 4 │
└─────────────┴─────────────┘
Grid Items


3. grid-template-columns

The grid-template-columns property defines the number and size of columns.

.container {
display: grid;
grid-template-columns: 200px 200px;
}


This creates two columns, each 200px wide.

You can also use fractional units:

.container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
}


This creates three equal-width columns.

Another example:

.container {
display: grid;
grid-template-columns: 2fr 1fr;
}


The first column receives twice the available space of the second column.

4. grid-template-rows

The grid-template-rows property defines the height of rows.

.container {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 100px 200px;
}


This creates:

• First row: 100px high

• Second row: 200px high

5. The Gap Property

The gap property adds space between grid rows and columns.

.container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}


You can also control spacing separately:

.container {
row-gap: 20px;
column-gap: 30px;
}


6. grid-template-areas

Grid areas allow you to name different sections of a layout.

.container {
display: grid;
grid-template-areas:
"header header"
"sidebar main"
"footer footer";

grid-template-columns: 200px 1fr;
gap: 10px;
}

.header {
grid-area: header;
}

.sidebar {
grid-area: sidebar;
}

.main {
grid-area: main;
}

.footer {
grid-area: footer;
}


Visual structure:

┌──────────────────────┐
│ HEADER │
├─────────┬────────────┤
│ SIDEBAR │ MAIN │
├─────────┴────────────┤
│ FOOTER │
└──────────────────────┘


This is useful for creating complete website layouts.

7. Grid Column and Row Spanning

You can make an element occupy multiple columns or rows.

Column spanning:

.item1 {
grid-column: span 2;
}


This makes the item occupy two columns.

Row spanning:

.item2 {
grid-row: span 2;
}
❤1
This makes the item occupy two rows.

8. repeat() Function

The repeat() function reduces repetitive CSS.

Instead of writing:

.container {
grid-template-columns: 1fr 1fr 1fr;
}


You can write:

.container {
grid-template-columns: repeat(3, 1fr);
}


Both create three equal-width columns.

9. minmax() Function

The minmax() function defines a minimum and maximum size for a grid track.

.container {
display: grid;
grid-template-columns: repeat(3, minmax(150px, 1fr));
}


Each column has a minimum size of 150px and can grow to share available space.

10. auto-fit and auto-fill

These keywords help create flexible grid layouts.

.container {
display: grid;
grid-template-columns:
repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
}


• auto-fit fits columns into available space and can expand existing columns.

• auto-fill creates as many tracks as fit, preserving empty tracks when space allows.

These are especially useful for responsive card layouts.

11. Real-World Example: Product Grid

HTML:

<div class="products">
<div class="card">Laptop</div>
<div class="card">Mobile</div>
<div class="card">Headphones</div>
<div class="card">Keyboard</div>
</div>


CSS:

.products {
display: grid;
grid-template-columns:
repeat(auto-fit, minmax(200px, 1fr));
gap: 20px;
}

.card {
padding: 30px;
background-color: lightblue;
border-radius: 10px;
text-align: center;
}


This creates a responsive product grid that adjusts the number of columns based on available space.

12. Flexbox vs CSS Grid
❤2
13. Quick Revision
Key Takeaways

• CSS Grid creates two-dimensional layouts.

• Use grid-template-columns to define columns.

• Use grid-template-rows to define rows.

• Use gap to create spacing.

• Use grid-template-areas for structured website layouts.

• Use repeat() and minmax() for flexible sizing.

• Use auto-fit to create responsive card layouts.

Double Tap ❤️ For More
❤5👍1
𝗙𝗥𝗘𝗘 𝗟𝗘𝗔𝗥𝗡𝗜𝗡𝗚 𝗔𝗡𝗗 𝗖𝗘𝗥𝗧𝗜𝗙𝗜𝗖𝗔𝗧𝗜𝗢𝗡 𝗥𝗘𝗦𝗢𝗨𝗥𝗖𝗘𝗦 𝗧𝗢 𝗕𝗨𝗜𝗟𝗗 𝗬𝗢𝗨𝗥 𝗖𝗢𝗗𝗜𝗡𝗚 𝗦𝗞𝗜𝗟𝗟𝗦😍

Explore free courses and resources to learn:

✅ Beginner-Friendly Resources
✅ Self-Paced Learning
✅ Build Practical Coding Skills
✅ Explore Certification Opportunities

🎯 Perfect for Students, Freshers & Aspiring Developers!

𝗟𝗶𝗻𝗸👇:-

https://pdlink.in/4fbyA6I

📌 SAVE & SHARE with friends looking for FREE courses🔥
❤1
✅ 20 Medium-Level Web Development Interview Questions (with Detailed Answers)

1. What is the difference between HTML, CSS, and JavaScript
• HTML: Structures content
• CSS: Styles content
• JavaScript: Adds interactivity and dynamic behavior

2. What is responsive web design
Designing websites that adapt to different screen sizes and devices using flexible grids, media queries, and fluid layouts.

3. What are semantic HTML elements
Elements that clearly describe their meaning (e.g., <article>, <section>, <nav>, <header>). Improves accessibility and SEO.

4. What is the DOM
Document Object Model — a tree-like structure representing HTML elements. JavaScript can manipulate it to update content dynamically.

5. What is the difference between GET and POST methods
• GET: Sends data via URL, used for fetching
• POST: Sends data in body, used for submitting forms securely

6. What is the box model in CSS
Every HTML element is a box:
Content → Padding → Border → Margin

7. What is the difference between relative, absolute, and fixed positioning in CSS
• Relative: Moves element relative to its normal position
• Absolute: Positions element relative to nearest positioned ancestor
• Fixed: Stays in place even when scrolling

8. What is the difference between == and === in JavaScript
• ==: Compares values with type coercion
• ===: Strict comparison (value and type)

9. What is event bubbling in JavaScript
Events propagate from child to parent elements. Can be controlled using stopPropagation().

10. What is the difference between localStorage and sessionStorage
• localStorage: Persistent across sessions
• sessionStorage: Cleared when tab is closed

11. What is a RESTful API
An architectural style for designing networked applications using HTTP methods (GET, POST, PUT, DELETE) and stateless communication.

12. What is the difference between frontend and backend development
• Frontend: Client-side (UI/UX, HTML/CSS/JS)
• Backend: Server-side (databases, APIs, authentication)

13. What are common HTTP status codes
• 200 OK
• 404 Not Found
• 500 Internal Server Error
• 403 Forbidden
• 301 Moved Permanently

14. What is a promise in JavaScript
An object representing the eventual completion or failure of an async operation.
States: pending, fulfilled, rejected

15. What is the difference between synchronous and asynchronous code
• Synchronous: Executes line by line
• Asynchronous: Executes independently, doesn’t block the main thread

16. What is a CSS preprocessor
Tools like SASS or LESS that add features to CSS (variables, nesting, mixins) and compile into standard CSS.

17. What is the role of frameworks like React, Angular, or Vue
They simplify building complex UIs with reusable components, state management, and routing.

18. What is the difference between SQL and NoSQL databases
• SQL: Structured, relational (e.g., MySQL)
• NoSQL: Flexible schema, document-based (e.g., MongoDB)

19. What is version control and why is Git important
Version control tracks changes in code. Git allows collaboration, branching, and rollback. Platforms: GitHub, GitLab, Bitbucket

20. How do you optimize website performance
• Minify CSS/JS
• Use lazy loading
• Compress images
• Use CDN
• Reduce HTTP requests

👍 React for more Interview Resources
❤9👍1
𝗙𝗥𝗘𝗘 𝗠𝗮𝘀𝘁𝗲𝗿𝗰𝗹𝗮𝘀𝘀 𝗢𝗻 𝗟𝗮𝘁𝗲𝘀𝘁 𝗧𝗲𝗰𝗵𝗻𝗼𝗹𝗼𝗴𝗶𝗲𝘀 😍

Get the 90-Day Plan to Build 1% Tech Career

- AI
- GenAI
- Data Analytics
- Fullstack
- UI/UX

Use Coupon Code " 𝗛𝗖𝗟𝗚𝗨𝗩𝗜𝟭𝟬𝟬 " To Register For FREE

𝗥𝗲𝗴𝗶𝘀𝘁𝗲𝗿 𝗙𝗼𝗿 𝗙𝗥𝗘𝗘👇 :-

https://pdlink.in/4fFMe22

Date:- 21st Nov 2026 Time:- 5:00 PM (IST)
🌐 Web Development Roadmap: Part 36

CSS Pseudo-Classes (:hover, :focus, :active, :first-child & :nth-child)

CSS pseudo-classes allow you to style HTML elements based on their state, position, or interaction with users.

For example:

• Change a button's color when someone hovers over it.

• Highlight an input field when someone clicks it.

• Style the first item in a list differently.

• Apply different styles to even and odd rows in a table.

Let's understand the important pseudo-classes.

1. What Is a Pseudo-Class?

A pseudo-class is a keyword added to a CSS selector using a colon (:).

Syntax:

selector:pseudo-class {
property: value;
}


Example:

button:hover {
background-color: blue;
}


When the user moves the mouse over the button, its background becomes blue.

2. :hover

The :hover pseudo-class applies styles when the user points to an element with a mouse or another pointing device.

<button>Click Me</button>


button {
background-color: blue;
color: white;
padding: 12px 20px;
}

button:hover {
background-color: darkblue;
}


Real-world usage:

• Buttons

• Navigation links

• Product cards

• Image galleries

3. :active

The :active pseudo-class applies styles while an element is being activated, such as while a mouse button is held down on it.

button:active {
background-color: red;
transform: scale(0.95);
}


This makes the button slightly smaller while being pressed.

4. :focus

The :focus pseudo-class applies styles when an element receives focus.

For example, when a user clicks an input field or navigates to it using the keyboard.

<input type="text" placeholder="Enter your name">


input:focus {
border: 2px solid blue;
outline: none;
}


This highlights the input field when it receives focus.

Real-world usage: Login forms, search boxes, registration forms.

Note: Always provide a visible focus indicator so keyboard users can identify the currently focused element.

5. :first-child

Selects an element if it is the first child of its parent.

HTML:

<ul>
<li>HTML</li>
<li>CSS</li>
<li>JavaScript</li>
</ul>


CSS:

li:first-child {
color: red;
}


Only HTML becomes red.

6. :last-child

Selects an element if it is the last child of its parent.

li:last-child {
color: green;
}


Only JavaScript becomes green.

7. :nth-child()

The :nth-child() pseudo-class selects an element based on its position among its siblings.

li:nth-child(2) {
color: blue;
}


This selects the second child.

You can also select multiple positions.

Every second element:

li:nth-child(even) {
background-color: lightgray;
}


Odd-numbered elements:

li:nth-child(odd) {
background-color: lightblue;
}


Every third element:

li:nth-child(3n) {
color: red;
}


This selects the 3rd, 6th, 9th and subsequent multiples of three.

8. :checked

The :checked pseudo-class selects checked checkboxes and selected radio buttons.

<input type="checkbox" id="terms">
<label for="terms">Accept Terms</label>


input:checked {
accent-color: green;
}
❤1