CSS3 Syntax and Three Ways to Add CSS: Rules, Selectors, Properties, Values, Comments and Basic Selectors

HTML5 and CSS3 45 min min read Updated: Nov 17, 2026 Beginner
CSS3 Syntax and Three Ways to Add CSS: Rules, Selectors, Properties, Values, Comments and Basic Selectors
Beginner Topic 1 of 3

Anatomy of a CSS Rule

css p { color: #333; font-size: 1.125rem; }
PartExampleMeaning
SelectorpWhich elements to style
Declarationcolor: #333;One style instruction
PropertycolorWhat to change
Value#333What to change it to

A rule can have many declarations. Each ends with a semicolon. The rule is wrapped in curly braces.

Three Ways to Add CSS

WayWhereWhen to use
ExternalA .css file linked with linkBest for almost all sites. One file styles many pages
InternalA style element in the headA quick demo or single page
InlineA style="..." attributeRarely. Hard to maintain and hard to override
html <!-- External --> <link rel="stylesheet" href="css/style.css"> <!-- Internal --> <style> h1 { color: teal; } </style> <!-- Inline --> <p style="color: crimson;">Red text</p>

Comments

css /* This is a CSS comment */ body { margin: 0; } /* so is this */

Basic Selectors

css /* Element selector */ h2 { color: #0b5fff; } /* Class selector: elements with class="note" */ .note { background: #fff7d6; padding: 1rem; } /* Id selector: one element with id="hero" */ #hero { min-height: 60vh; } /* Grouping: same style for several selectors */ h1, h2, h3 { font-family: Georgia, serif; } /* Universal selector: everything */ * { box-sizing: border-box; }
html <section id="hero"> <h2>Welcome</h2> <p class="note">New here? Start with the basics.</p> </section>
Classes first Use classes for most styling. Ids must be unique and are harder to override. Name classes by purpose, like .btn or .card, not by color like .red.

Common Mistakes

  • Missing semicolon or curly brace: the next rule may stop working
  • Misspelled property names: the browser silently ignores them
  • A wrong file path in link
  • Forgetting the dot before a class name or the hash before an id

Practice

  1. Create style.css and style body, h1 and p
  2. Make a .note class and use it on two paragraphs
  3. Use DevTools to turn a declaration off and on

Conclusion

A CSS rule has a selector and declarations. Use an external stylesheet, and style with classes.

Quick Summary: Rule anatomy; three ways to add CSS; comments; basic selectors; mistakes.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators