Three Ways to Add CSS
CSS is like dressing up your website. But just like fashion, there are different ways to apply styles! You can:
- Use Inline CSS (Quick but messy)
- Use Internal CSS (Organized but limited)
- Use External CSS (The best method!)
Let’s break them down so you can style your website like a true CSS guru!
Inline CSS: Quick Fixes, but Beware!
Inline CSS means adding styles directly inside an HTML element using the style
attribute.
Example:
<p style="color: red; font-size: 20px;">This text is red and 20px!</p>
- Good for quick changes.
- Hard to manage in big projects.
Use it sparingly! Inline CSS is like putting a band-aid on a design problem instead of fixing it properly.
Internal CSS: Keeping Styles in One Place
Internal CSS is written inside a <style>
tag in the <head>
section of your HTML file.
Example:
<head>
<style>
p {
color: blue;
font-size: 18px;
}
</style>
</head>
<body>
<p>This text is blue and 18px!</p>
</body>
- Works well for small projects.
- Still not great for big websites.
Internal CSS is like organizing your wardrobe in one room, but things can still get messy if you have too many clothes!
External CSS: The Professional Way!
External CSS is written in a separate .css
file and linked to the HTML file.
Example:
styles.css
p {
color: green;
font-size: 22px;
}
index.html
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p>This text is green and 22px!</p>
</body>
- Best for large websites.
- Keeps HTML and CSS separate and clean.
This method is like having a walk-in closet—everything is neat and easy to manage!
Conclusion: Which One Should You Use?
- Inline CSS – Only for emergency fixes.
- Internal CSS – Good for small projects.
- External CSS – The best choice for scalability.
If you want a professional, well-organized website, go with External CSS!
0 Comments