MGU Computer Science Series — Web Development: HTML, CSS, and JavaScript
Part III: CSS: Style and Layout
Selectors · Cascade · Typography · Layout · Responsive Design
Chapter 11 of 30
11
MGU Computer Science Series  ·  Web Development: HTML, CSS, and JavaScript  ·  Library Textbook Edition

Chapter 11:
What CSS Does

A first look at how CSS controls presentation — rules, selectors, properties, values, stylesheets, and the habit of separating structure from style

■ Part III of VII ■

■ 10 Sections  •  Chapter 11 of 30 ■

Builds directly on the HTML structure from Part II — no prior CSS experience required

Chapter Introduction and Learning Objectives

Open any well-designed website and you are looking at the work of two languages at once. HTML gave the page its bones — headings, paragraphs, lists, links, images, and landmarks that carry meaning. But none of that explains why the heading is large and dark blue, why the navigation bar sits neatly across the top of the screen, why the body text is easy to read, or why the page looks calm and organized rather than like a plain, unstyled document. That second job — controlling how a page looks — belongs to CSS.

In Part II of this book, you learned to write HTML that is structured, semantic, and meaningful. You wrote pages that a browser, a screen reader, and a search engine could all understand. But if you opened those pages in a browser, they probably looked plain: black text, blue underlined links, default spacing, no color scheme. That plainness was deliberate. It let you focus entirely on structure without being distracted by appearance. Now it is time to add appearance back in — carefully, and on purpose.

Opening Question

Two different websites can use the exact same HTML markup — the same headings, the same paragraphs, the same navigation links — and still look completely different from one another: different colors, different fonts, different spacing, different layouts. How is that possible if the underlying structure never changes? The answer is CSS. By the end of this chapter, you will understand what CSS is, how a CSS rule is built, where CSS can be written, and how to connect a stylesheet to an HTML page so that structure and style work together without being tangled into one another.

10Sections
12Objectives
17Key Terms
30Total Chapters

Learning Objectives

By the end of this chapter, you should be able to:

  1. 1Explain what CSS does and why it exists as a language separate from HTML.
  2. 2Distinguish between structure and presentation, and explain why keeping them separate matters.
  3. 3Identify the parts of a CSS rule: selector, declaration block, property, and value.
  4. 4Use type selectors, class selectors, and ID selectors at an introductory level.
  5. 5Explain the difference between inline styles, internal stylesheets, and external stylesheets.
  6. 6Correctly link an external CSS file to an HTML document using the link element.
  7. 7Apply basic properties for styling text and simple boxes.
  8. 8Explain what browser default styles are and why an unstyled page is not actually styleless.
  9. 9Explain why CSS works as a reusable system rather than page-by-page decoration.
  10. 10Build a simple external stylesheet from scratch and link it to a page.
  11. 11Recognize common beginner CSS mistakes, including missing semicolons and broken links to stylesheets.
  12. 12Read a short CSS file and explain, in plain language, what it does to a page.

Sections at a Glance

Sections 11.1 – 11.3
The Idea: Presentation, Separation, and Rules
What CSS Is · Structure vs. Presentation · CSS Rules

What CSS Is

CSS stands for Cascading Style Sheets. It is the language browsers use to determine how an HTML document should look. Where HTML says what something is — a heading, a paragraph, a list, a link — CSS says how it should appear: what color, what size, what spacing, what position on the screen.

Without CSS, every web page would look like a plain typed document: black text, default spacing, blue underlined links, and elements stacked one after another from top to bottom in the order they appear in the HTML. CSS is what allows the same underlying content to become a polished newspaper layout, a colorful product page, a minimalist portfolio, or a dense data dashboard.

The word "cascading" refers to how CSS rules combine and compete when more than one rule could apply to the same element. Several different style rules — from the browser, from the page author, and sometimes from the user — can all apply to one element at once, and CSS has a consistent set of rules for deciding which one wins. Chapter 12 explores the cascade in detail. For now, it is enough to know that the name describes a layered, rule-based system rather than a single flat list of instructions.

CSS Controls
Presentation
Color, background, typography, spacing, borders, size, position, layout, and visual behavior such as hover effects and transitions.
CSS Does Not Control
Meaning
CSS cannot turn a div into a heading for assistive technology, and it cannot make unstructured markup meaningful. Meaning is HTML's job, not CSS's.
CSS Cannot Replace
Good HTML
Styling a span to look like a button does not make it behave like a button for keyboard or screen-reader users. Semantic HTML, from Part II, remains the foundation.
Study Note

It helps to think of HTML as the architecture of a building and CSS as the interior design, paint, and lighting. The architecture determines what rooms exist and how they connect. The design determines how those rooms feel. You cannot fix bad architecture with good paint — and in the same way, you cannot fix poor HTML structure with clever CSS.

Structure Versus Presentation

Early in the history of the web, developers often mixed structure and presentation directly inside HTML — using tags and attributes meant purely to control appearance, such as font tags and color attributes scattered through the markup. This approach created pages that were difficult to update, inconsistent across sites, and hostile to assistive technology. CSS was created specifically to separate these two concerns: HTML should describe what content is, and CSS should describe how that content looks.

This separation is not a stylistic preference. It produces real, practical benefits that you will feel throughout the rest of this book.

BenefitWhy Separation Makes It Possible
Easier maintenanceChanging a color or font in one CSS file updates every page that links to it, instead of editing color values inside dozens of HTML files.
ConsistencyA shared stylesheet keeps headings, buttons, and spacing visually consistent across an entire website automatically.
Reusable designThe same stylesheet can be applied to many pages, and a new stylesheet can give old, unchanged HTML a completely new appearance.
Cleaner HTMLHTML stays focused on meaning and structure, which keeps it easier to read, easier to debug, and friendlier to screen readers and search engines.
Independent updatesA designer can update visual style without touching content, and a writer can update content without touching layout.
Worked Example
One page, two completely different looks
  • Same HTMLImagine a simple page with a heading, a short paragraph, and a navigation list. The HTML never changes in this example.
  • Stylesheet AA stylesheet sets a dark background, a light serif heading font, and wide spacing — the page reads like a quiet, formal article.
  • Stylesheet BA second stylesheet, linked instead of the first, sets a bright background, a bold sans-serif heading, and tight spacing — the same page now feels energetic and modern.
  • The lessonThe content and meaning never changed. Only the linked stylesheet changed. This is the entire point of separating structure from presentation.

CSS Rules

CSS is written as a series of rules. Each rule tells the browser: "find these elements, and apply these styles to them." A rule has two main parts: a selector, which chooses which elements the rule applies to, and a declaration block, which lists the styles to apply.

The Anatomy of a CSS Rule

p { color: navy; font-size: 18px; }

Here, p is the selector — it selects every paragraph element. The part inside the curly braces is the declaration block. Each line inside it, such as color: navy;, is a declaration, made up of a property (color) and a value (navy), separated by a colon and ended with a semicolon.

p { color: navy; font-size: 18px; line-height: 1.6; }

Every declaration ends with a semicolon. While the very last declaration in a block technically works without one in most browsers, leaving it off is a common source of errors once you add another declaration later and forget to add the missing semicolon first. The habit of always ending every declaration with a semicolon — no exceptions — will save you from one of the most frequent beginner CSS mistakes.

A stylesheet is simply a collection of rules like this one, written one after another. The browser reads every rule, figures out which elements each selector matches, and applies the resulting styles to the page.

Common Mistake

Forgetting the semicolon between declarations is one of the most common beginner errors. Without it, the browser may misread where one declaration ends and the next begins, causing styles to silently fail. Unlike many programming languages, CSS does not always show an error message — a broken rule may simply be ignored, leaving you to wonder why a style "isn't working."

Sections 11.4 – 11.6
The Vocabulary: Selecting Elements and Connecting Files
Selectors · Properties · Values · Stylesheet Locations · Linking CSS

Selectors, Properties, and Values

A selector is the part of a CSS rule that decides which HTML elements the rule applies to. CSS offers many kinds of selectors — Chapter 12 covers them in depth — but three are essential to know from the start: type selectors, class selectors, and ID selectors.

Selector TypeSyntaxWhat It Matches
Type selectorp, h1, navEvery element of that HTML type on the page
Class selector.cardEvery element with class="card", regardless of its HTML type
ID selector#site-headerThe single element with id="site-header" — an ID should appear once per page

Once a selector chooses its elements, the declaration block describes how those elements should look using properties and values. A property names an aspect of appearance you want to control — color, background-color, font-size, margin — and a value specifies the setting for that property — navy, 16px, center.

Selector
Who gets styled
Chooses one or more elements on the page — by HTML type, by class, by ID, or by other rules covered in Chapter 12.
Property
What aspect is styled
Names a specific visual characteristic, such as text color, background color, font size, or spacing.
Value
How it is styled
Specifies the exact setting for the property — a color name, a measurement, a keyword, or another supported format.
Looking Ahead

This section introduces selectors only enough to get you writing useful CSS right away. Chapter 12 returns to selectors in much greater depth, including grouping selectors, descendant selectors, pseudo-classes, inheritance, specificity, and the full cascade — the rules that decide which style wins when several rules could apply to the same element.

Inline Styles, Internal Styles, and External Stylesheets

CSS can be written in three different places. Each one has a different scope and a different recommended use.

MethodWhere It Is WrittenScopeRecommended Use
Inline styleInside a style attribute on a single elementThat one element onlyQuick testing or rare one-off cases; avoid as a habit
Internal stylesheetInside a <style> element in the headThat one HTML documentSmall, single-page examples or isolated demonstrations
External stylesheetIn a separate .css file, linked from the headEvery page that links to the fileThe standard professional habit for real projects
<!-- Inline style — applies only to this one paragraph --> <p style="color: navy; font-size: 18px;">Hello</p> <!-- Internal stylesheet — applies only within this document --> <head> <style> p { color: navy; } </style> </head> <!-- External stylesheet — applies to every page that links it --> <head> <link rel="stylesheet" href="css/main.css"> </head>
Why Avoid Inline Styles

Inline styles affect only one element, cannot be reused, and are difficult to override consistently, since they normally take priority over rules in stylesheets. A page built with many inline styles quickly becomes inconsistent and hard to maintain, because every visual change must be repeated by hand on every single element. This textbook uses external stylesheets as the default habit starting in Section 11.6.

Linking a CSS File

To use an external stylesheet, you create a separate file with a .css extension and connect it to an HTML document using the <link> element, placed inside the head. Recall from Chapter 3 that a tidy project keeps CSS files in their own folder, often named css.

Worked Example
Linking css/main.css to index.html
  • Step 1Create a folder named css inside your project folder, next to index.html.
  • Step 2Inside that folder, create a new file named main.css. This file will hold your CSS rules.
  • Step 3In index.html, inside the head element, add: <link rel="stylesheet" href="css/main.css">
  • Step 4Save both files, then open index.html in a browser. Any rules written in main.css should now apply to the page.
  • Step 5To confirm the link is working, add an obvious test rule, such as body { background-color: yellow; }, save, and reload the page. If the background does not change, the path in href is the first thing to check.

The rel="stylesheet" attribute tells the browser what kind of linked resource this is — in this case, a stylesheet to apply to the document. The href attribute gives the path to the file, following the same relative path rules you learned in Chapter 3. A wrong path is the single most common reason CSS appears not to work at all.

Debugging Tip

If none of your CSS seems to be applying, open the browser's developer tools (Chapter 4) and check the network or console panel for a failed request to your CSS file. A 404, or a stylesheet that never appears in the page's loaded resources, almost always means the href path is incorrect or the file was saved in the wrong folder.

Sections 11.7 – 11.10
Putting It to Work: Styling, Defaults, and Reuse
Text and Boxes · Browser Defaults · Reusable Systems · Your First Stylesheet

Styling Text and Boxes at an Introductory Level

With selectors, properties, and a linked stylesheet in place, you can begin applying real styles. This section introduces a small, practical set of properties for text and simple boxes. Later chapters return to typography (Chapter 13) and the box model (Chapter 14) in much greater depth — this is only a first, gentle introduction.

PropertyPurposeExample Value
colorText colorcolor: #1a2c6b;
background-colorBackground color behind an elementbackground-color: #f0f0f8;
font-familyTypeface used for textfont-family: Georgia, serif;
font-sizeSize of textfont-size: 18px;
text-alignHorizontal alignment of text inside its elementtext-align: center;
paddingSpace inside an element, between its content and its edgepadding: 16px;
borderA line drawn around an element's edgeborder: 1px solid #c0c0cc;
h1 { color: #1a2c6b; font-family: Georgia, serif; } .card { background-color: #f0f0f8; padding: 16px; border: 1px solid #c0c0cc; }

Notice that .card in the second rule is a class selector. Any element in the HTML marked with class="card" — whether it is a div, a section, or an article — will receive that background color, padding, and border. This is the beginning of reusable styling, a theme this chapter returns to in Section 11.9.

Looking Ahead

Every element on a page is technically a box, even when no border is visible. Padding, borders, margins, width, and height all interact in a predictable system called the box model. You will study it in full in Chapter 14. For now, treat padding and border as simple tools for adding breathing room and a visible edge.

Browser Defaults

If you write a plain HTML page with no CSS at all and open it in a browser, it will not look like unformatted plain text. Headings will already be bold and noticeably larger than body text. Paragraphs will already have space between them. Lists will already show bullets or numbers. Links will already be blue and underlined. None of this happened by accident — every browser applies its own built-in stylesheet, called the user-agent stylesheet, before your own CSS is applied.

This explains something that confuses many beginners: a page with "no styles" is not actually styleless. It is styled by the browser's defaults. When you write your own CSS, you are not starting from a truly blank canvas — you are adding rules that, depending on specificity and source order (covered fully in Chapter 12), can override what the browser already decided.

Why This Matters

Different browsers do not always agree on every default value — small differences in default margin, font size, or list spacing can appear between browsers. Professional developers often account for this using reset or normalization techniques, which intentionally remove or standardize certain browser defaults before applying their own design. This textbook does not require a formal reset at the introductory level, but you should understand that the variation exists and that author styles are what bring a page's appearance under your control.

Practically, this means that whenever a page looks "almost right" but slightly different from what you expected, the browser's default styles are often the explanation — not a mistake in your own CSS. Inspecting an element with developer tools, as you learned in Chapter 4, will usually show you exactly which styles are browser defaults and which are your own.

CSS as a Reusable System

One of the most important habits to develop early is thinking of CSS as a system, not as page-specific decoration. A single external stylesheet, linked from every page in a website, can give the entire site a consistent look — consistent colors, consistent spacing, consistent typography — without repeating a single rule by hand on each page.

Classes are the main tool that makes this reuse possible. A class such as .card, .button, or .section-title can be applied to many different elements across many different pages. Change the rule once, in one file, and every element using that class updates everywhere it appears.

Connecting to the Running Project
One stylesheet, five pages
  • The projectThe Student Learning Site you have been building since Part I has several pages: Home, About, Lessons, Resources, and Contact.
  • One fileA single file, css/main.css, is linked from the head of every one of those pages.
  • Shared rulesRules for headings, navigation links, and reusable classes like .card apply identically across every page that links the file.
  • One change, five updatesIf you later decide to change your site's main color, you change it in one place in main.css, and every linked page updates automatically. This is the practical payoff of separating structure from presentation.
Looking Ahead

Chapter 18 takes reuse a step further with CSS custom properties (variables), which let an entire color and spacing system be defined once and reused throughout a stylesheet. The habits you build now — writing classes instead of repeating one-off rules — prepare you directly for that chapter.

Building a First Stylesheet

This section walks through building a small external stylesheet for a simple page, combining everything covered in this chapter: rules, selectors, properties, values, linking, and reuse through classes.

Guided Walkthrough
Styling a simple "About" page
  • Starting HTMLAssume an about.html page with a header containing an h1, a main containing a few paragraphs, and a section with class="card" highlighting one fact.
  • Link the fileAdd <link rel="stylesheet" href="css/main.css"> inside the head of about.html.
  • Style the page background and textIn main.css, write a rule for body setting a light background color, a readable font-family, and a comfortable line-height.
  • Style the headingWrite a rule for h1 setting color and font-family so the heading stands out clearly from body text.
  • Style the reusable cardWrite a rule for .card with background-color, padding, and border, so this class can be reused on any page that needs a highlighted box.
  • Test and adjustSave both files, reload the page, and check the result in the browser. Use developer tools to confirm each rule is being applied and adjust values until the page looks the way you intend.
/* css/main.css */ body { background-color: #f8f8fc; font-family: Georgia, serif; line-height: 1.6; } h1 { color: #1a2c6b; font-family: "Helvetica Neue", Arial, sans-serif; } .card { background-color: #f0f0f8; padding: 16px; border: 1px solid #c0c0cc; }

Notice that nothing about about.html needed to change visually inside the markup itself — every change happened in main.css. This is the habit you will repeat for the rest of the book: write meaningful HTML first, then control its appearance from a linked, external stylesheet.

Chapter Summary

Key Terms

CSS
Cascading Style Sheets — the language that controls the visual presentation of HTML documents, including color, typography, spacing, and layout.
cascade
The set of rules browsers use to decide which competing CSS rule applies to an element when more than one rule could match it.
stylesheet
A collection of CSS rules, whether written internally in a page or externally in a linked .css file.
CSS rule
A selector paired with a declaration block, instructing the browser which elements to style and how to style them.
selector
The part of a CSS rule that chooses which HTML elements the rule applies to.
declaration
A single property-value pair inside a declaration block, such as color: navy;.
declaration block
The portion of a CSS rule enclosed in curly braces, containing one or more declarations.
property
The name of a visual characteristic being controlled, such as color or font-size.
value
The setting assigned to a property, such as navy or 18px.
type selector
A selector that matches every element of a given HTML type, such as p or h1.
class selector
A selector, written with a leading period, that matches every element carrying a given class attribute, such as .card.
ID selector
A selector, written with a leading hash symbol, that matches the single element carrying a given unique ID, such as #site-header.
inline style
CSS written directly inside an element's style attribute, applying only to that one element.
internal stylesheet
CSS written inside a <style> element in a page's head, applying only to that one document.
external stylesheet
CSS written in a separate .css file and linked into one or more HTML documents, the standard approach for real projects.
link element
The HTML element, <link>, used with rel="stylesheet" and an href path to connect an external CSS file to a page.
user-agent stylesheet
The built-in default stylesheet every browser applies before any author-written CSS, responsible for default heading sizes, link colors, and list bullets.

Concept Check

Answer these questions before beginning the full review questions. They check basic understanding, not deep analysis.

  1. In your own words, what does CSS control that HTML does not?
  2. What are the two main parts of a CSS rule?
  3. What is the difference between a class selector and an ID selector?
  4. Name the three places CSS can be written, and state which one is recommended as a standard habit.
  5. What attribute of the <link> element tells the browser where the CSS file is located?
  6. Why does an HTML page with no author-written CSS still show visible formatting?
  7. Why is reusing a class across many elements more maintainable than repeating inline styles?

Common Misconceptions

Misconception 1
"An unstyled HTML page has no styling at all."
Every browser applies a built-in user-agent stylesheet before any author CSS is considered. Bold headings, underlined blue links, bulleted lists, and default spacing are all browser defaults, not the absence of style. Writing CSS means adding to or overriding these defaults, not starting from nothing.
Misconception 2
"Inline styles are the simplest way to style a page, so they are fine to use everywhere."
Inline styles affect only the single element they are written on and cannot be reused. A page styled mostly with inline styles becomes inconsistent and difficult to update, since every visual change must be repeated by hand on every element. External stylesheets achieve the same visual result while remaining maintainable and reusable across an entire site.
Misconception 3
"CSS class names and HTML element names work the same way in a selector."
A type selector such as p matches by HTML element type. A class selector such as .card matches by an author-assigned attribute that can be applied to any element type. The leading period is required for class selectors; leaving it off, or confusing it with an ID's leading hash symbol, is a frequent beginner error that causes a rule to silently match nothing.
Misconception 4
"If my CSS file doesn't work, the problem is probably a typo in a property name."
While typos do happen, the single most common reason linked CSS appears to do nothing at all is a broken file path in the href attribute of the <link> element, not a mistake inside the CSS file itself. Always confirm the stylesheet is actually loading, using developer tools, before assuming the rules themselves are wrong.
Misconception 5
"CSS is mostly about making things look pretty, so it doesn't need the same care as HTML."
CSS affects readability, usability, and accessibility, not just decoration. Poor color contrast, illegible font sizes, and inconsistent spacing create real barriers for real users. CSS deserves the same careful, deliberate approach you learned to bring to semantic HTML in Part II.
ActivitiesCSS Rule Practice

These activities build comfort with reading and writing the basic anatomy of a CSS rule.

  1. Label the Parts. Given the rule .button { background-color: #1a2c6b; color: white; padding: 10px; }, identify the selector, and list each property-value pair separately.
  2. Selector Matching. Given a page with one element <h2 class="title" id="main-title">, write three different selectors — a type selector, a class selector, and an ID selector — that would each match this element.
  3. Fix the Rule. The following rule is broken: p { color: navy font-size: 16px }. Identify what is missing and rewrite it correctly.
  4. Write From Scratch. Write a CSS rule that selects every element with class="alert" and sets its background color to a light red and its text color to dark red.
ActivitiesStylesheet Linking Practice

These activities connect path skills from Chapter 3 to the specific task of linking CSS.

  1. Write the Link. A project has the structure index.html at the top level and css/styles.css inside a css folder. Write the exact <link> element that belongs in the head of index.html.
  2. Find the Error. A student writes <link rel="stylesheet" href="styles.css"> but their CSS file is actually located at css/styles.css. Explain what will happen and how to fix it.
  3. Multi-Page Linking. A site has index.html, about.html, and contact.html, all at the top level, sharing one stylesheet at css/main.css. Write the <link> element each page needs, and explain why the path is the same on every page in this case.
ActivitiesCode Reading

Read each short CSS example and explain, in plain language, what it does to a page.

  1. body { background-color: #1a1a1f; color: white; }
  2. .card { border: 1px solid gray; padding: 12px; }
  3. h1, h2, h3 { font-family: Georgia, serif; }
  4. #site-footer { text-align: center; font-size: 12px; }
ActivitiesDebugging Practice

Each scenario describes CSS that is not behaving as expected. Identify the likely cause.

  1. A student links a stylesheet, but none of the rules inside it appear to apply anywhere on the page. What is the first thing to check?
  2. A rule for .highlight does not seem to apply to an element. The student checks the HTML and sees <div class="highlite">. What is wrong?
  3. A page shows only some of the rules in a stylesheet — the first few rules apply, but later rules do not. The student suspects a missing semicolon somewhere earlier in the file. Explain why a single missing semicolon could cause later rules to behave unpredictably.
  4. A student uses #card as a selector intending it to style several repeated elements, but only the first one is ever affected. What rule about ID selectors explains this?

Common Errors

ErrorTypical SymptomFix
Missing semicolonA style appears to be ignored, often along with the rule after itEnd every declaration with a semicolon, with no exceptions
Wrong href pathNone of the CSS file's rules apply anywhereRe-check the relative path from the HTML file to the CSS file
Missing leading period or hashA class or ID selector matches nothingUse .classname for classes and #idname for IDs
Misspelled class nameAn element appears unstyled even though a rule was written for itConfirm the class name matches exactly between the HTML and the CSS
Reused ID across elementsOnly one element receives the intended style, or behavior becomes inconsistentUse a class instead of an ID when styling more than one element
ReviewReview Questions

Recall and Vocabulary

  1. What does CSS stand for, and what is its general purpose?
  2. Name the two main parts of a CSS rule.
  3. What is the difference between a property and a value in a declaration?
  4. Define type selector, class selector, and ID selector.
  5. What are the three locations where CSS can be written, and which is recommended for real projects?
  6. What does the rel="stylesheet" attribute do on a <link> element?
  7. What is a user-agent stylesheet?
  8. What punctuation mark ends every CSS declaration?

Understanding and Explanation

  1. Explain, in your own words, why separating structure and presentation makes a website easier to maintain.
  2. Why are inline styles discouraged as a habit, even though they are the simplest way to apply a style to one element?
  3. Explain why an HTML page with no linked stylesheet still displays visible formatting, such as bold headings and spaced paragraphs.
  4. Explain the relationship between a class selector and the class attribute in HTML. Why must the names match exactly?
  5. Why is an ID selector generally inappropriate for styling more than one element on a page?

Application and Analysis

  1. A developer wants every paragraph on a site to use the same font, but wants only paragraphs inside a "quote" section to appear in italics with a different color. Describe what kinds of selectors would accomplish this, without writing the full CSS.
  2. A student's project folder contains index.html at the top level and a CSS file at styles/site.css. They write <link rel="stylesheet" href="site.css"> and nothing happens. Diagnose the problem and write the corrected line.
  3. Compare an internal stylesheet and an external stylesheet for a five-page website. Explain which one would require less repeated effort if the site's color scheme changed, and why.
  4. A page currently uses several inline styles to set the same background color on five different div elements. Describe how you would refactor this using a single reusable class instead.

Design and Synthesis

  1. Design a small external stylesheet, written out in full, that styles a simple page consisting of a header with an h1, a main with two paragraphs, and one section with class="note". Choose your own colors, fonts, and spacing, and explain each rule in one sentence.
  2. Write a short paragraph, suitable for a beginner who has never seen CSS, explaining the difference between HTML and CSS using an analogy of your own (not the architecture analogy used earlier in this chapter).
Chapter 11 Checklist
Use this to confirm your understanding before moving to Chapter 12
Concepts
  • I can explain what CSS does and how it differs from HTML's job.
  • I can explain why separating structure and presentation is valuable.
  • I can identify the selector, declaration block, property, and value in a CSS rule.
  • I can use type selectors, class selectors, and ID selectors at an introductory level.
  • I can explain the difference between inline, internal, and external CSS.
  • I can explain why browser default styles exist and why "no CSS" does not mean "no styling."
Applications
  • I can correctly link an external CSS file using the <link> element.
  • I can write basic rules to style text color, background color, fonts, padding, and borders.
  • I can build and link a small stylesheet from scratch and confirm it is working in the browser.
  • I can recognize a missing semicolon, a broken path, and a misspelled class name as likely causes when CSS does not apply.
Study Habits
  • I understand why I should test a linked stylesheet with an obvious change before trusting smaller, subtler ones.
  • I have a strategy for confirming whether a CSS file is actually loading, using developer tools.
  • I am beginning to think of CSS as a reusable system rather than page-specific decoration.
Preview — Chapter 12
Selectors, Properties, and the Cascade

Chapter 11 introduced CSS rules, the three places CSS can live, and a first small set of properties. Chapter 12 goes much further into how CSS chooses elements and resolves conflicts. You will learn grouping selectors, descendant selectors, pseudo-classes, inheritance, specificity, and source order — the complete set of rules that make up "the cascade" in Cascading Style Sheets. Selector conflicts are one of the most common challenges beginners face in CSS, so this next chapter moves carefully and builds confidence through tracing examples by hand before writing larger stylesheets.

MGU Library Connection
  • Web Development: HTML, CSS, and JavaScript — Appendix D: CSS Reference
  • Web Development: HTML, CSS, and JavaScript — Appendix M: Glossary
  • Companion resource: CSS Selector Chart
  • Companion resource: CSS Box Model Chart (preview — full chart accompanies Chapter 14)
  • Prerequisite chapters: Part II, HTML Structure and Meaning (Chapters 5–10)
  • Next chapter: Chapter 12, Selectors, Properties, and the Cascade