CSS: Introduction to CSS

1. What is CSS?

CSS (Cascading Style Sheets) is a descriptive language used to control the styling and layout of web pages. With CSS, you can precisely control how HTML elements are displayed — including fonts, colors, backgrounds, borders, sizes, positions, and other visual properties. CSS is an indispensable core technology in modern web development.

Think of it this way: if HTML is the "skeleton" of a web page — determining what content appears on the page (headings, paragraphs, images, tables, etc.) — then CSS is the "clothes and makeup" — determining how that content looks (colors, sizes, positions, animations, etc.).

💡 Easy to understand: HTML is the "skeleton," CSS is the "clothes and makeup" — before learning CSS, it's recommended to understand HTML basics first, so you know what "skeleton" the "clothes" will be worn on.


2. What CSS Does

✅ Don't worry: CSS doesn't require any programming background to get started. You just need a browser and a text editor (Notepad works fine), and you can see results immediately.


3. Separating Structure from Style

One of CSS's greatest values is achieving "separation of content and presentation" — HTML handles structured content, CSS handles visual presentation. This separation brings many benefits:


4. How Browsers Work

When a browser loads a web page, it:

  1. Parses the HTML document to build a DOM (Document Object Model) tree
  2. Parses the CSS file/code to build a CSSOM (CSS Object Model) tree
  3. Merges the DOM and CSSOM into a render tree
  4. Layouts based on the render tree (calculates position and size of each element)
  5. Renders to the screen

Simply put, the browser first parses structure and styles separately, then merges and calculates, and finally paints the page you see.


5. A Brief History of CSS

📌 Did you know: When CSS was first released in 1996, browser support was very limited. Developers at that time even used nested tables for layout, until CSS3 truly changed the game.

▶ Example

CSS3 features: rounded corners and shadows:

CSS
.card {
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  padding: 20px;
}

.button {
  border-radius: 20px;
  background: linear-gradient(to right, #667eea, #764ba2);
  color: white;
  padding: 10px 24px;
}
▶ Try it Yourself

6. Core CSS Concepts

▶ Example

A simple HTML page with CSS styling:

HTML
<!DOCTYPE html>
<html>
<head>
  <style>
    body { font-family: Arial, sans-serif; }
    h1 { color: navy; }
  </style>
</head>
<body>
  <h1>Hello, CSS!</h1>
  <p>This is a styled paragraph.</p>
</body>
</html>
▶ Try it Yourself

The browser renders the heading in navy color, using the Arial font for all text. CSS in the <style> tag controls these visual properties.

▶ Example

Inline CSS vs. internal stylesheet:

HTML
<p style="color: red; font-size: 20px;">Inline-styled paragraph</p>

<style>
  .styled { color: blue; font-size: 20px; }
</style>
<p class="styled">Stylesheet-styled paragraph</p>
▶ Try it Yourself

Both produce similar visual results, but the stylesheet approach is reusable and easier to maintain.


❓ FAQ

Q What's the difference between CSS and HTML?
A HTML handles the "skeleton and content" of a web page (headings, paragraphs, images), while CSS handles the "appearance and layout" (colors, sizes, positions). HTML determines what's on the page; CSS determines how those things look.
Q Do I need to learn HTML before learning CSS?
A It's recommended to first master HTML basics (knowing common tags is enough), because CSS is used to style HTML elements. Without understanding HTML structure, CSS has nothing to work with.
Q Can CSS create animations?
A Yes. CSS3 provides transition, animation (keyframe animations), and transform features, enabling common web effects like button hover color changes, loading spinners, and card flips.

📖 Summary

📝 Exercises

  1. Create a css-intro.html file in your project folder. Think about web pages you've seen — which parts do you think CSS is responsible for?
  2. Open a website you like, use the browser's Developer Tools (F12) to view the Elements panel, and observe the Styles panel on the right side of the HTML structure to see which CSS rules are at work.
  3. Summarize the division of labor between CSS and HTML in your own words, and write it in your exercise notes.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏