Web Development
79.3K subscribers
1.39K photos
1 video
2 files
738 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
Which of the following is a valid HEX color code for red?
Anonymous Quiz
46%
20%
18%
Which CSS property adds an image as an element's background?
Anonymous Quiz
13%
A) background-color
18%
B) image-src
62%
C) background-image
7%
D) img-background
What is the alpha value for 50% opacity in RGBA?
Anonymous Quiz
5%
A) 0
80%
B) 0.5
7%
C) 1
8%
D) 50
❤2
𝗝.𝗣. 𝗠𝗢𝗥𝗚𝗔𝗡 𝗙𝗥𝗘𝗘 𝗩𝗜𝗥𝗧𝗨𝗔𝗟 𝗣𝗥𝗢𝗚𝗥𝗔𝗠𝗦 𝟮𝟬𝟮𝟲! 🎓

Explore J.P. Morgan's FREE Virtual Job Simulation Programs

✅ 100% FREE Virtual Learning
✅ Work on Practical, Industry-Based Tasks
✅ Learn at Your Own Pace
✅ Build Valuable Professional Skills

🎯 Perfect For:- College Students | Freshers | Graduates | Job Seekers

🔗 𝗟𝗶𝗻𝗸 👇:-

https://pdlink.in/3X8KJmE

⚡ Learn New Skills • Gain Practical Exposure • Boost Your Career!
❤5
🚀 𝗗𝗮𝘁𝗮 𝗔𝗻𝗮𝗹𝘆𝘁𝗶𝗰𝘀 𝗖𝗲𝗿𝘁𝗶𝗳𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗖𝗼𝘂𝗿𝘀𝗲 📊

Learn Excel, SQL, Python & Power BI Live Online Data Analytics Program

💰 Highest Salary: ₹12.6 LPA
📈 Average Salary: ₹5.7 LPA
🏢 500+ Partner Companies

𝗔𝗽𝗽𝗹𝘆 𝗡𝗼𝘄👇 :-

https://pdlink.in/45vk5ph

🔥 Turn your interest in data into practical, job-ready skills!
🌐 Web Development Roadmap, Part 27

CSS Units (px, %, em, rem, vh, vw and fr)

CSS units define the size of elements, text, spacing, widths, heights, and layouts.

For example, when you write:

h1 {
font-size: 32px;
}
The px defines the size of the heading.

CSS units are divided into two main categories:

• Absolute units
• Relative units

1. Pixels (px)

Pixels are commonly used to define fixed sizes.

.box {
width: 300px;
height: 200px;
padding: 20px;
}
Here:

• Width = 300 pixels
• Height = 200 pixels
• Padding = 20 pixels

Use pixels when you need a specific size.

2. Percentage (%)

Percentage defines a size relative to the parent element's corresponding dimension.

<div class="parent">
<div class="child">Hello</div>
</div>
`
.parent {
width: 600px;
}

.child {
width: 50%;
}

The child width will be 300px because it is 50% of its parent's 600px width.

3. EM (em)

em is a relative unit.

For font size, it is calculated relative to the inherited font size of the parent.

.parent {
font-size: 20px;
}

.child {
font-size: 2em;
}

The child font size becomes 40px.

Calculation:

20px × 2 = 40px

Note: For properties such as padding and margin, em is based on the font size of the element itself.

4. REM (rem)

rem stands for Root EM.

It is calculated relative to the font size of the root HTML element.

By default, browsers generally use 16px as the root font size.

html {
font-size: 16px;
}

h1 {
font-size: 2rem;
}


16px × 2 = 32px

So the heading will have a font size of 32px.

Difference between em and rem:

• em depends on the relevant element's inherited or own font size, depending on the property.
• rem depends on the root HTML font size.

5. Viewport Height (vh)

vh represents a percentage of the viewport height.

1vh = 1% of viewport height.

.hero {
height: 100vh;
}

This makes the element as tall as the viewport.

Useful for:

• Full-screen sections
• Landing pages
• Hero sections

6. Viewport Width (vw)

vw represents a percentage of the viewport width.

1vw = 1% of viewport width.

.container {
width: 80vw;
}

This makes the container 80% of the viewport width.

• Responsive layouts
• Full-width sections
• Flexible sizing

7. FR Unit

fr stands for fractional unit.

It is mainly used with CSS Grid to divide available space into fractions.

.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 gets twice the available space of the second column.

8. Other CSS Units

Some additional units you should know:

• cm, Centimeters
• mm, Millimeters
• in, Inches
• pt, Points
• pc, Picas
• vmin, 1% of the smaller viewport dimension
• vmax, 1% of the larger viewport dimension
• ch, Based on the width of the "0" character
• ex, Based on the x-height of the font

9. Practical Example

Let's create a responsive card using different CSS units.

HTML:

<div class="card">
<h2>Learn Web Development</h2>
<p>Start learning HTML, CSS and JavaScript.</p>
</div>

CSS:

.card {
width: 80%;
max-width: 500px;
padding: 2rem;
margin: 5vh auto;
background-color: lightblue;
border-radius: 1rem;
}

.card h2 {
font-size: 2rem;
}

.card p {
font-size: 1rem;
}

`

This example combines percentages, pixels, rem, and vh to create a flexible layout.

10. Quick Comparison

• px: Meaning Pixels · Common usage Fixed sizing
• %: Meaning Percentage · Common usage Relative sizing
• em: Meaning Relative to font size · Common usage Text and spacing
❤4
- rem: Meaning Relative to root font size · Common usage Consistent typography
- vh: Meaning Viewport height · Common usage Full-screen sections
- vw: Meaning Viewport width · Common usage Responsive widths
- fr: Meaning Fraction · Common usage CSS Grid layouts

Key Takeaways

- Use
px

for fixed dimensions.

- Use
%

for relative sizing.

- Use
em

and
rem

for scalable typography and spacing.

- Use
vh

and
vw

for viewport-based sizing.

- Use
fr

to divide available space in CSS Grid.

Understanding CSS units is essential for creating responsive websites that work across mobile phones, tablets, and desktops.

Double Tap ❤️ For More
❤13
Which CSS unit represents pixels?
Anonymous Quiz
4%
A) rem
89%
B) px
6%
C) em
1%
D) vh
❤2
By default, what is the root font size in most browsers?
Anonymous Quiz
14%
A) 10px
41%
B) 12px
39%
C) 16px
5%
D) 20px
Which unit is commonly used with CSS Grid to divide available space?
Anonymous Quiz
21%
A) px
16%
B) em
46%
C) fr
16%
D) rem
If the parent font size is 20px, what is 2em for a child’s font size?
Anonymous Quiz
18%
A) 20px
14%
B) 30px
63%
C) 40px
5%
D) 60px
If the root font size is 16px, what is 2rem?
Anonymous Quiz
8%
A) 16px
18%
B) 24px
71%
C) 32px
3%
D) 40px
Which CSS unit represents 1% of the viewport width?
Anonymous Quiz
19%
A) vh
56%
B) vw
19%
C) fr
7%
D) em
❤3