1.3 🎨 CSS Basics – Styling the Web

Table of Contents

Hey there! I’m Vikas Sankhla, your friendly full-stack dev bro 😎 and founder of Web Codder. Today, let’s talk about how to make websites beautiful using CSS β€” in the easiest way possible.

Imagine HTML as the skeleton of a web page. CSS is like the clothes, colors, and makeup that make it look cool and stylish. πŸ’…


🧡 What is CSS?

CSS stands for Cascading Style Sheets.

It controls how elements look on a web page β€” like colors, spacing, fonts, sizes, and layout.

Think of HTML as what you see, and CSS as how you see it.

Example:

<p>This is a paragraph.</p>

With CSS:

p {
  color: blue;
  font-size: 18px;
}

Now the paragraph is blue and bigger! πŸ’™


πŸ“¦ CSS Box Model – Layout Magic

Every HTML element is a box. This box has 4 layers:

  1. Content – The actual text or image
  2. Padding – Space inside the box, around the content
  3. Border – The line around the box
  4. Margin – Space outside the box

Box Model Diagram πŸ“¦

+-------------+
|   Margin    |
| +--------+ |
| | Border | |
| |+------+| |
| ||Padding|| |
| ||Content|| |
| |+------+| |
| +--------+ |
+-------------+

Example:

div {
  margin: 10px;
  padding: 20px;
  border: 2px solid black;
}

✍️ Styling Text and Fonts

You can make your text beautiful with CSS.

Basic Properties:

h1 {
  color: red;
  font-size: 32px;
  font-family: Arial, sans-serif;
  line-height: 1.5;
}
  • color: Text color
  • font-size: Size of the text
  • font-family: Style of the font
  • line-height: Space between lines

πŸ‘€ Tip: Use Google Fonts to explore cool fonts!


🧠 CSS Selectors – Target Like a Pro

Selectors help us decide which element to style.

SelectorExampleMeaning
Elementp {}All <p> tags
Class.title {}Elements with class=”title”
ID#main {}Element with id=”main”

Example:

<p class="info">This is blue text.</p>
.info {
  color: blue;
}

βš–οΈ Specificity – Who Wins the Style Fight?

Sometimes, multiple styles apply to the same element. Who wins?

🎯 Specificity decides which CSS rule is stronger.

Specificity Ranking:

  1. Inline styles β†’ style="color:red"
  2. ID selectors β†’ #id
  3. Class selectors β†’ .class
  4. Element selectors β†’ p, h1

πŸ“Œ Higher specificity wins!


🧰 Inline, Internal, and External CSS

There are 3 ways to apply CSS:

MethodWhere it goesExample
InlineInside an HTML tag<p style="color: red">
InternalIn a <style> block<style>p {color: blue;}</style>
ExternalLinked .css file<link href="style.css" rel="stylesheet">

πŸ’‘ Pro Tip: Always use external CSS for big projects.


πŸ§ͺ Try It Yourself!

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <h1 class="title">Hello World</h1>
  <p>This is a paragraph.</p>
</body>
</html>
/* styles.css */
.title {
  color: purple;
  font-size: 36px;
}
p {
  color: green;
  font-size: 18px;
}

πŸ“Œ Summary

  • CSS makes websites beautiful 🎨
  • Use box model to control layout
  • Style text with fonts, colors, and spacing
  • Use selectors to target elements
  • Specificity decides which style wins

πŸ“£ Final Tip from Vikas Bhaiya πŸ’¬

CSS is super fun once you play with it! Try changing colors, spacing, and fonts.

Build your own small project and style it like a boss. πŸ§‘β€πŸŽ¨πŸ’»

And hey, if you learned something new today:

βœ… Subscribe to Web Codder on YouTube
πŸ‘‰ https://www.youtube.com/@web_codder/?sub_confirmation=1

🧠 Read more articles on Automation & Web Dev
πŸ‘‰ https://webcodder.dev/category/automation/

πŸ’¬ Join our WhatsApp Community
πŸ‘‰ https://webcodder.dev/whatsapp

Let’s grow and code together! πŸš€

Share the Post:
Picture of Web Codder

Web Codder

Vikas Sankhla is a seasoned Full Stack Developer with over 7 years of experience in web development. He is the founder of Web Codder, a platform dedicated to providing comprehensive web development tutorials and resources. Vikas specializes in the MERN stack (MongoDB, Express.js, React.js, Node.js) and has been instrumental in mentoring aspiring developers through his online courses and content. His commitment to simplifying complex web technologies has made him a respected figure in the developer community.

Related Posts