CSS gives styles to HTML elements through rules. A rule has a selector and a pair of braces; each declaration inside contains a property and a value. The browser combines the HTML structure with matching CSS rules.
Read a rule first
A CSS declaration uses property: value;. The semicolon ends one declaration, and braces group declarations for the same selector. The browser reads rules from top to bottom. When several rules match one element, the cascade considers their source, selector specificity, and order.
<h1>My first styled page</h1>
<p>CSS changes how this content looks.</p>h1 {
color: #0f766e;
}
p {
font-size: 18px;
}Change one value at a time and watch the text, color, size, or position. This connects each declaration to a visible result. Browser developer tools show the result of the same matching process.
A useful checking order
- Confirm that the selector matches the intended HTML element.
- Check the property name, colon, value, and semicolon.
- Test narrow space, longer text, and keyboard use.
Live style lab: CSS basics
Switch between the examples, then edit either HTML or CSS. The right side is a real browser rendering.
Connect the HTML structure with each matching CSS declaration.
Example buttons replace both editors; Reset lab restores the first example. Your CSS runs only inside the isolated preview and cannot change the course page.
A common source of confusion
CSS changes presentation and layout; it does not change the meaning of the HTML. Keep meaningful HTML elements and style them, rather than choosing the wrong element only for its default appearance. Readability comes before decoration.
KNOWLEDGE QUIZ
Practice: build a css basics example
Write a small CSS rule set for the supplied HTML and verify each result in a browser preview.
- Keep the HTML content and semantic structure.
- Use selectors related to this lesson and write at least three declarations.
- Check text contrast and make sure no content is covered or clipped.
HTML structure
<h1>My first styled page</h1>
<p>CSS changes how this content looks.</p>