Chapter 1 of 14
~11 minCSS Introduction & Syntax
CSS (Cascading Style Sheets) is the language that controls how HTML content looks - colors, spacing, fonts, layout. HTML says what something is; CSS says how it should appear.
Why CSS Is Separate From HTML
Keeping structure (HTML) and presentation (CSS) apart means you can restyle an entire site by editing one file, instead of hunting through every page's markup. It also lets browsers, screen readers, and search engines read the content on its own terms, unaffected by how it looks.
Three Ways to Add CSS
Inline styles use the style attribute directly on an element - fast for a one-off tweak, but it doesn't scale and can't be reused. An internal <style> block inside <head> keeps CSS in the same file as the HTML - fine for a single small page or a quick demo.
An external stylesheet, linked with <link rel="stylesheet" href="styles.css">, is preferred for any real project: the browser caches it once and reuses it across every page, and your HTML and CSS stay cleanly separated.
All three methods, same visual result
Basic Rule Syntax
A CSS rule pairs a selector (what to style) with a declaration block wrapped in curly braces: selector { property: value; }. Each declaration ends with a semicolon, and multiple selectors can share one rule by separating them with commas.
Try it yourself
CSS Comments
Comments use /* ... */ and can span multiple lines. Unlike HTML comments, there is no shorthand // or # form - always use the slash-star syntax. Comments are stripped before the browser renders anything, so they're purely for the people reading the code.
Try it yourself
Coding Challenge
Add an internal <style> block that makes every <p> element have blue text and a comment explaining why.
Answer every question below to mark this chapter as complete.
Quiz Yourself
Score: 0/41. What does CSS stand for?
2. Which method of adding CSS is generally preferred for real projects?
3. What is the correct syntax for a CSS rule?
4. How do you write a CSS comment?