CSS Introduction
In this page:
What Is CSS?
CSS is the language that describes how HTML elements should look: their color, size, spacing, fonts, and position on the page. HTML says what something is (a heading, a paragraph, a button); CSS says how it should appear.
Example: What Is CSS?
<style>
p {
color: teal;
font-size: 18px;
}
</style>
<p>HTML says this is a paragraph; CSS says how it looks.</p>
Why CSS Matters
CSS is what turns a working webpage into a pleasant, readable, on-brand experience. Good CSS improves readability, guides a visitor's attention, and makes a site feel trustworthy and professional.
Example: Why CSS Matters
<style>
.card {
padding: 16px;
font-size: 16px;
color: #222;
background: lightyellow;
border: 1px solid #ddd;
}
</style>
<div class="card">Consistent spacing and readable text feel polished.</div>
How Browsers Use CSS
When a browser loads a page, it reads the HTML to build the page's structure, then reads any CSS to figure out how each piece of that structure should be drawn on screen, a process often called rendering.
Example: How Browsers Use CSS
<style>
p {
color: navy;
}
</style>
<p>The browser reads this HTML, then applies this CSS rule while rendering.</p>
CSS and HTML Working Together
HTML and CSS are two separate languages that work as a team: HTML elements act as the targets that CSS selectors point at, and CSS rules describe how those targeted elements should look.
Example: CSS and HTML Working Together
<style>
.headline {
color: darkred;
}
</style>
<h1 class="headline">CSS targets this element by its class</h1>
Where CSS Code Can Live
CSS can be written inline on a single element, inside a style tag in the page's head, or in a completely separate .css file linked to the page. Each approach has its place, and later chapters cover them in detail.
Example: Where CSS Code Can Live
<p style="color: red;">Inline CSS</p>
<style>
p.internal { color: blue; }
</style>
<p class="internal">Internal CSS, inside a style tag</p>
<link rel="stylesheet" href="styles.css">
- Believing CSS is optional polish rather than a core part of how the web actually looks and works.
- Mixing styling directly into HTML with inline styles everywhere instead of using a shared stylesheet.
- Assuming a browser will show unstyled HTML exactly the same way every browser has its own default styling.
- CSS stands for Cascading Style Sheets and controls how HTML content is visually presented.
- Separating structure (HTML) from presentation (CSS) makes a site easier to maintain and restyle.
- The cascade is the set of rules CSS uses to resolve conflicting styles from different sources.
CSS is supported by every browser in use today, though newer CSS features roll out at different speeds across browsers.
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: