Academic Block

CSS Introduction

What is CSS?

CSS (Cascading Style Sheets) is a stylesheet language used to control the appearance and layout of HTML documents. HTML provides the structure of a webpage, while CSS controls colors, fonts, spacing, borders, backgrounds, layouts, animations, and responsive design.

Why CSS is Used

CSS separates design from content, making websites easier to maintain, faster to update, and consistent across multiple pages.

Features of CSS

  • Easy styling
  • Responsive layouts
  • Flexbox and Grid
  • Animations and transitions
  • Reusable external stylesheets
  • Cross-browser support

Advantages of CSS

  • Cleaner HTML
  • Improved maintainability
  • Faster loading
  • Consistent design
  • Better user experience

How CSS Works with HTML

CSS uses selectors to target HTML elements and applies property-value pairs to style them.

CSS Syntax

h1{
    color:blue;
    font-size:36px;
}

Ways to Add CSS

  1. Inline CSS
  2. Internal CSS
  3. External CSS (Recommended)

CSS Version History

Version
Year
Highlights
CSS1
1996
Basic styling
CSS2
1998
Positioning, media types
CSS2.1
2011
Compatibility improvements
CSS3+
Present
Flexbox, Grid, Animations, Container Queries

Example: My First CSS

<style>
h1{
 color:#0d6efd;
}
p{
 color:#444;
}
</style>

<h1>Welcome to CSS</h1>
<p>This page is styled using CSS.</p>

Best Practices

  • Use external CSS.
  • Write meaningful class names.
  • Keep code organized.
  • Avoid duplicate rules.
  • Use responsive units.

Web Resources on CSS (Cascading Style Sheets)

1. MDN Web Docs : What is CSS and How is CSS applied to HTML?
2. Web.dev : Welcome to Learn CSS!

๐Ÿงช Test Your CSS Code

Edit the CSS code on the left and click “Run Code” to see the result on the right.

๐Ÿ“ CSS Code
๐Ÿ‘๏ธ Preview (HTML rendered with your CSS)

Click “Run Code” to see the result here.