The external path is resolved relative to the HTML document unless a base URL changes that behavior.
Check the actual filename and folder when the file does not load.
A link points to a file; it does not create that file for you.
Do not memorize “external beats internal” or the reverse.
Rules in linked sheets and style elements participate in the cascade.
For comparable normal author declarations, a style attribute has precedence over stylesheet declarations; importance and other cascade stages still matter.
05
🎯Basic Selectors — Match the Right Elements
A type selector matches an element type: p matches paragraphs.
A class selector begins with a dot: .notice matches an element whose class list contains notice.
An ID selector begins with a hash: #registration matches the element with that ID.
A selector list uses commas to apply a rule to several matching groups.
The universal selector* matches elements broadly.
Broad rules can be useful for a common foundation, but keep component rules focused so they do not change unrelated parts of a page.
Predict the matches: a paragraph with class notice can match both p and .notice.
Their declarations can combine when they affect different properties.
A competing declaration for the same property must be resolved by the cascade.
06
🏷️Classes and IDs — Reuse Versus Identity
An element can have several classes separated by spaces.
Each class can describe a reusable role, such as notice, warning or compact.
An ID identifies one element in the document and should be unique.
Prefer reusable classes for ordinary component styling; reserve IDs for genuine document identity and related uses.
In HTML you write class="notice featured".
In CSS you write .notice or .featured, without adding the dot to the HTML class value.
Do not use class=".notice" and expect .notice to match it as the class notice.
<p id="workshop-note" class="notice featured">Bring your HTML notes.</p>
.notice { padding: 1rem; }
.featured { font-weight: 700; }
The paragraph receives both reusable styles.
The id can also be a fragment-link destination.
An ID selector has higher specificity than a class selector, but adding IDs everywhere to win conflicts makes future changes harder.
07
🌳Relationships and Attribute Selectors
A space in a selector expresses a descendant relationship. .card p can match paragraphs anywhere inside .card.
A greater-than sign expresses an immediate child: .card > p excludes paragraphs nested inside another child element.
An attribute selector can match an attribute’s presence or value.
For example, input[type="email"] matches email inputs.
The attribute selector is useful when that attribute is a meaningful part of the component’s behavior.
.card p { color: #254864; }
.card > p { margin-top: 0; }
input[type="email"] { border-color: #126d96; }
A comma is not a descendant relationship: .card, p selects cards and paragraphs separately.
A missing space can change meaning too: .card.featured requires the same element to have both classes, whereas .card .featured requires a featured descendant of a card.
08
🖱️States — hover and focus-visible
A pseudo-class can match an element in a particular state. :hover commonly matches a pointer hovering over an element. :focus-visible matches when the browser considers a visible focus indicator appropriate, including ordinary keyboard use.
Provide a clear keyboard focus style as well as pointer feedback.
A touch device may not have a persistent hover interaction.
Do not place essential instructions behind hover alone or remove focus outlines without supplying a visible alternative.
Expected result under the stated assumptions: the later .note rule supplies purple text because both selectors have equal specificity and both declarations are normal author declarations in the same layer.
14
🔢Specificity and !important — Different Decisions
Compare specificity as components, not a single decimal score.
ID selectors form one component; class, attribute and pseudo-class selectors form another; type selectors and pseudo-elements form another.
A basic #note selector is more specific than .note, which is more specific than p.
This comparison applies after the relevant earlier cascade decisions.
An important declaration can beat a normal declaration in the same author context even when the normal selector is more specific. !important is a declaration flag, not an extra selector or a normal increase to the specificity count.
Use focused rules and inspect conflicts before reaching for !important.
Overusing it can make component changes difficult.
Inline normal styles can also be overridden by an applicable important author declaration.
Important user styles may be used to preserve user needs.
In the first pair, the matching ID rule wins over the later class rule.
In the separate second pair, the important class declaration wins over the normal ID declaration.
The lab lets you compare these cases without combining their assumptions.
15
🌳Inheritance — A Child Can Receive a Parent Value
Some properties, including color and common font properties, are inherited when the child does not have its own winning value for that property.
Many box-related properties, such as margin and border, are not inherited by default.
Inheritance is not another highly specific rule on the child.
An explicit declaration on a child can replace an inherited value even when the parent selector looks more specific.
Ask whether the child has a declaration of its own before comparing the parent’s selector as if it matched the child.
.workshop { color: #176343; }
.workshop p { margin: 0; }
/* The paragraph can inherit the workshop color. */
inherit explicitly requests the parent’s computed value for a property. initial requests the property’s initial value; it does not mean “whatever the parent used.” unset follows inheritance for inherited properties and uses the initial value for others.
Advanced reverting and layer controls can be studied after the basics.
16
🔄Premium Visualizer — CSS Rule Selection
Trace matching, cascade context, specificity, source order and the result. This is a guided explanation of the fixed examples shown here. Use the timeline or playback controls; no claim is made that the visualizer evaluates arbitrary CSS.
CSS RULE SELECTION TRACE
Step 1 of 5
🎯
STEP 01
Match rules to the element
The paragraph has id="lesson-note" and class="note", so both the ID and class rules match.
Before comparing priorities, check the selector and confirm that the stylesheet loaded. A non-matching rule cannot style this paragraph.
17
🧪Premium Interactive — CSS Conflict Lab
The preview is a separate local document with controlled rules.
Select a case, change the text size and inspect the actual rendered paragraph.
Each case explains its expected winner under the stated simple author-style assumptions.
The lesson styles outside the preview cannot overwrite its rules.
Compare source-order, ID specificity, inherited color and an important declaration.
Read the rules in the same order they are supplied to the preview.
The label reports an expected result for the known example; it is not a live browser-computed-style inspector.
Select a case and inspect its rules.
CSS supplied to the preview
18
🔎Debugging — Inspect Instead of Guessing
📂
File and path
Confirm that the linked stylesheet exists, loads successfully and has the expected content.
🎯
Matching
Check spelling, classes, IDs, combinators and the actual element structure.
⚖️
Conflict
Inspect crossed-out declarations, importance, specificity and order in browser tools.
🧱
Value and context
Check syntax, supported values, inheritance and the background or parent that affects the result.
An invalid or unsupported declaration is generally ignored rather than converted into the value you intended.
A missing colon or a malformed block can affect parsing beyond one obvious line.
Keep braces balanced and inspect the browser’s parsed rules.
If a change seems absent after deployment, first verify that the deployed file contains it.
A local edit that has not been deployed cannot change the public page.
A cached resource can also show earlier content; inspect the actual loaded resource before changing unrelated selectors.
Try a small, reversible rule in browser tools to confirm the hypothesis.
Then make the permanent change in the correct source file.
Do not keep appending broad overrides that affect the header, footer and other lessons by accident.
19
💬Interview Questions — Flip to Explain
QUESTION
Does the last CSS declaration always win?
Click or press Enter to explain
ANSWER
No. It must match, be valid and survive earlier cascade comparisons. Later order resolves an otherwise equal conflict, not every conflict.
QUESTION
Do external styles always outrank internal styles?
Click or press Enter to explain
ANSWER
No. Both can contain author rules. Their cascade context, specificity and order decide applicable conflicts.
QUESTION
What is the difference between class and ID selectors?
Click or press Enter to explain
ANSWER
Classes identify reusable groups and can be combined. An ID identifies one element and should be unique; an ID selector has a higher specificity component.
QUESTION
How does inheritance differ from matching a selector?
Click or press Enter to explain
ANSWER
Inheritance supplies certain parent values when the child has no overriding value. It does not mean the parent selector also matches the child.
QUESTION
Does !important increase selector specificity?
Click or press Enter to explain
ANSWER
No. It flags a declaration as important. Importance is considered at a different cascade stage from selector specificity.
QUESTION
Why keep a unitless line-height?
Click or press Enter to explain
ANSWER
The number acts as a multiplier with the element’s font size, which can make inherited text spacing easier to manage.
QUESTION
Can CSS make a div into a native button?
Click or press Enter to explain
ANSWER
No. Appearance does not provide the semantics and keyboard behavior of a native control.
QUESTION
Why test a background and foreground together?
Click or press Enter to explain
ANSWER
Readability depends on the actual combination, including transparency, parent backgrounds and images behind the text.
20
❓MCQ Practice — Explain the Winner
PRACTICE
1. Which declaration has the correct CSS syntax?
PRACTICE
2. Which selector matches class="notice"?
PRACTICE
3. What does .card > p match?
PRACTICE
4. Normal author .note rules in one layer have equal specificity. Which wins for the same property?
PRACTICE
5. Which is more specific in the stated simple normal author context?
PRACTICE
6. What does !important do?
PRACTICE
7. Which property is commonly inherited?
PRACTICE
8. With a root font size of 16px, what is 1.125rem?
PRACTICE
9. Which supplies a CSS comment?
PRACTICE
10. Why can opacity: .5 harm a card’s text readability?
PRACTICE
11. Which supports visible keyboard focus?
PRACTICE
12. A rule does not style the expected paragraph. What should you inspect first?
21
💻Extra Practice — Predict and Verify
🧱
Rule repair
Repair color = blue to a valid declaration. Expected: color: blue; is parsed as the requested color.
🏷️
Class matching
Use class="notice featured" with .notice and .featured rules. Expected: the same element can receive declarations from both.
🌳
Child comparison
Put one paragraph directly inside a card and another inside a nested section.
Expected: .card p matches both; .card > p matches only the direct child.
📄
Equal-rule order
Write two .note color rules, then reverse their order.
Expected: the later rule wins in the stated equal normal author context.
🔢
ID comparison
Put the class rule after a matching ID rule. Expected: the normal ID declaration still wins in the same context.
🌿
Inheritance boundary
Give a parent a color and border.
Expected: the paragraph can inherit the color, while the border does not automatically become the paragraph’s border.
📏
Unit calculation
Assume a 20px parent and set the child font-size to 1.25em. Expected requested font size: 25px under that assumption.
⌨️
Focus and text growth
Keep a visible focus style and increase preview text size.
Expected: the active control stays identifiable and text is not clipped.
22
📌Quick Revision
🧱Syntax: selector { property: value; }
📂Files: A linked stylesheet must exist and load at the given path.
🏷️Selectors: Use classes for reuse and IDs for unique identity.
🌳Relationships: A space means descendant; > means immediate child.
⌨️States: Keep keyboard focus visible as well as hover feedback.
🎨Readability: Check the actual foreground and background together.
📏Units: Relative values have a stated, property-specific basis.
⚖️Cascade: Consider context and importance before specificity and ties.
🔢Order: Later order decides an otherwise equal conflict.
🌿Inheritance: Some parent values pass to children; many box properties do not.
23
📖Glossary — Flip to Learn
TERM
Stylesheet
Click to see meaning
DEFINITION
Stylesheet
A collection of CSS rules defining presentation.
TERM
Selector
Click to see meaning
DEFINITION
Selector
A pattern used to match elements for a rule.
TERM
Declaration
Click to see meaning
DEFINITION
Declaration
A property/value pair with an optional importance flag.
TERM
Property
Click to see meaning
DEFINITION
Property
The aspect of presentation being specified, such as color.
TERM
Cascade
Click to see meaning
DEFINITION
Cascade
The process that resolves competing applicable declarations.
TERM
Specificity
Click to see meaning
DEFINITION
Specificity
Selector components used in the cascade after relevant earlier decisions.
TERM
Source order
Click to see meaning
DEFINITION
Source order
The order used to resolve a remaining equal-priority conflict.
TERM
Inheritance
Click to see meaning
DEFINITION
Inheritance
The transfer of certain parent values when a child lacks an overriding value.
TERM
Pseudo-class
Click to see meaning
DEFINITION
Pseudo-class
A selector feature describing a state or other condition.
TERM
Computed value
Click to see meaning
DEFINITION
Computed value
A property value after the relevant computation stage, before some later layout-dependent resolution.
24
🏆Final Challenge — Style the Semantic Workshop
Take the standalone workshop page from Level 10 and create workshop.css next to it.
Link the stylesheet in the head.
Use classes for the hero, notice and practice panels; style the headings, body text and native disclosure while keeping all existing semantic tags and keyboard controls.
Use a readable font stack, a flexible text size and a unitless line-height.
Choose contrasting text and background colors.
Provide a clear focus-visible style and avoid a fixed panel height that clips enlarged text.
Keep decorative backgrounds separate from essential content.
Add two deliberately competing normal class color rules to a practice notice and predict their winner.
Then compare a matching ID rule in a separate example.
Record the assumptions that make your predictions valid and inspect the winning declaration in browser tools.
Success criterion: the external file loads, the selectors match only the intended content, the page remains operable by keyboard, and you can explain the conflicting color result.
Level 12 will build on this foundation with the box model and layout.
25
✅Level 11 Complete?
Before marking complete, write and link a valid stylesheet, demonstrate class matching, explain an equal-rule conflict and an inherited value, and preserve a visible keyboard focus indicator. Completion is a local study milestone, not a score or design certification.