Go Back

CSS Section 1

CSS Rules

Basic structure of a CSS rule:

selector { property: value; }

Example: h1 { color: purple; } sets the color of all <h1> elements to purple.

How to Write CSS

There are three main ways to write CSS:

  1. Inline CSS – Directly inside HTML elements using the style attribute.
    Example: <h1 style="background-color: blue;">
    ⚠️ Not recommended for larger projects.
  2. Internal CSS – Using a <style> tag inside the <head> of your HTML.
    Example: <style> h1 { color: blue; } </style>
    ⚠️ Still not ideal for reusable styles.
  3. External CSS – Writing CSS in a separate file and linking it using a <link> tag in the <head>.
    Example: <link rel="stylesheet" href="styles.css">
    ✅ This is the best and most scalable method.

Commonly Used CSS Properties

Next: Section 5