Video by Dr. Chuck on CSS Basics Part 1: A beginner-friendly video explaining the fundamentals of CSS.
Video by Dr. Chuck on CSS Basics Part 2: A continuation of the CSS basics, covering more advanced topics.
Inline CSS (avoid except for dynamic styles):
<p style="color: blue; font-size: 16px;">Text</p>
Internal CSS:
<head>
<style>
p {
color: blue;
font-size: 16px;
}
</style>
</head>
External CSS (best practice):
<head>
<link rel="stylesheet" href="css/style.css">
</head>
/* style.css */
p {
color: blue;
font-size: 16px;
}
Try the following (admittedly badly designed) page with and without CSS: CSS Zen Garden
Without CSS, the content is still accessible, but the visual presentation is poor.
Maybe important for visual impairments?

selector {
property: value;
}
For all selectors, CSS rules apply
The property is what you want to change
Think of it as a paintbrush for HTML elements
Element Selector:
p {
color: black;
}
h1 {
font-size: 32px;
}
Class Selector:
.highlight {
background-color: yellow;
}
.btn {
padding: 10px 20px;
border-radius: 5px;
}
<p class="highlight">Highlighted text</p>
<button class="btn">Click Me</button>
ID Selector:
#header {
background-color: navy;
}
#main-content {
padding: 20px;
}
<div id="header">Header Content</div>
<div id="main-content">Main Content</div>
Universal Selector:
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
Multiple sources of styles: browser defaults, user styles, author styles
Specificity hierarchy: inline > ID > class > element
Concept: The more specific the selector, the higher its priority
Concept: Later rules override earlier ones if they have the same specificity
<div>: Block-level container for grouping elements<span>: Inline container for grouping text or elements<div class="container">
<h1>Title</h1>
<p>This is a <span class="highlight">highlighted</span> word.</p>
</div>
spand and div are often used together with CSS to style specific parts of a webpage.
Concept: span and div have no inherent visual effect; they are designed to be styled with CSS.
Concept: this is so because other older elements had specific meanings and visual effects (like <b>, <i>, <u>, etc.)
# means ID selector. Find element with that ID.
. means class selector. Find all elements with that class.
No prefix means element selector. Find all elements of that type.
Explanation of CSS Specificity: A video explaining how CSS specificity works.
Example of specificity:
/* Element selector */
p {
color: black; /* specificity: 1 */
}
/* Class selector */
.highlight {
color: blue; /* specificity: 10 */
}
/* ID selector */
#main {
color: red; /* specificity: 100 */
}
red, blue, green, etc.#RRGGBB or #RGBrgb(255, 0, 0)rgba(255, 0, 0, 0.5) (with alpha for transparency)hsl(0, 100%, 50%)hsla(0, 100%, 50%, 0.5) (with alpha for transparency)/* Named color */
color: red;
/* Hexadecimal */
color: #FF0000;
/* RGB */
color: rgb(255, 0, 0);
/* RGBA */
color: rgba(255, 0, 0, 0.5);
/* HSL */
color: hsl(0, 100%, 50%);
/* HSLA */
color: hsla(0, 100%, 50%, 0.5);
font-family: Specifies the font type.font-size: Specifies the size of the font.font-weight: Specifies the weight (boldness) of the font.font-style: Specifies the style (normal, italic, oblique) of the font./* Font family */
font-family: Arial, Helvetica, sans-serif;
font-family: 'Times New Roman', serif;
font-family: 'Courier New', monospace;
/* Font size */
font-size: 16px;
font-size: 1.2em; /* relative to parent */
font-size: 1.2rem; /* relative to root */
/* Font weight */
font-weight: normal;
font-weight: bold;
font-weight: 700;
/* Font style */
font-style: italic;
font-style: oblique;
/* Shorthand */
font: italic bold 16px/1.5 Arial, sans-serif;
body {
font-family: 'Roboto', sans-serif;
}
/* Link states */
a:link { color: blue; }
a:visited { color: purple; }
a:hover { color: red; }
a:active { color: orange; }
<nav> tag is to define a section of navigation links in an HTML document.nav a {
text-decoration: none;
padding: 10px 15px;
color: white;
background-color: #333;
}
nav a:hover {
background-color: #555;
}
Descendant Selector (space):
/* All p elements inside div */
div p {
color: blue;
}
Child Selector (>):
/* Only direct children */
div > p {
font-weight: bold;
}
Adjacent Sibling (+):
/* p immediately after h2 */
h2 + p {
margin-top: 0;
}
General Sibling (~):
/* All p elements after h2 */
h2 ~ p {
color: gray;
}
/* Has attribute */
input[required] {
border: 2px solid red;
}
/* Exact value */
input[type="email"] {
background-color: lightyellow;
}
/* Contains value */
a[href*="example"] {
color: green;
}
/* Starts with */
a[href^="https"] {
padding-left: 20px;
}
/* Ends with */
a[href$=".pdf"] {
color: red;
}
/* Link states */
a:link { color: blue; }
a:visited { color: purple; }
a:hover { color: red; }
a:active { color: orange; }
/* Form states */
input:focus {
outline: 2px solid blue;
}
input:disabled {
background-color: #eee;
}
input:checked + label {
font-weight: bold;
}
/* Structural */
li:first-child {
font-weight: bold;
}
li:last-child {
border-bottom: none;
}
li:nth-child(odd) {
background-color: #f0f0f0;
}
li:nth-child(3n) {
color: red;
}
p:not(.special) {
color: gray;
}
/* First line/letter */
p::first-line {
font-weight: bold;
}
p::first-letter {
font-size: 2em;
float: left;
}
/* Before/After */
.quote::before {
content: """;
font-size: 2em;
}
.quote::after {
content: """;
font-size: 2em;
}
/* Selection */
::selection {
background-color: yellow;
color: black;
}
Color Values:
/* Named colors */
color: red;
/* Hexadecimal */
color: #FF0000;
color: #F00; /* shorthand */
/* RGB */
color: rgb(255, 0, 0);
/* RGBA (with transparency) */
color: rgba(255, 0, 0, 0.5);
/* HSL */
color: hsl(0, 100%, 50%);
/* HSLA */
color: hsla(0, 100%, 50%, 0.5);
Background Properties:
.element {
background-color: #f0f0f0;
background-image: url('bg.jpg');
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
background-attachment: fixed;
/* Shorthand */
background: #f0f0f0 url('bg.jpg') no-repeat center/cover;
}
/* Multiple backgrounds */
.hero {
background:
url('overlay.png'),
url('photo.jpg');
background-size: cover, cover;
}
/* Gradients */
.gradient {
background: linear-gradient(to right, red, blue);
background: linear-gradient(45deg, red, yellow, blue);
background: radial-gradient(circle, red, blue);
}
Font Properties:
.text {
/* Font family */
font-family: Arial, Helvetica, sans-serif;
font-family: 'Times New Roman', serif;
font-family: 'Courier New', monospace;
/* Font size */
font-size: 16px;
font-size: 1.2em; /* relative to parent */
font-size: 1.2rem; /* relative to root */
/* Font weight */
font-weight: normal;
font-weight: bold;
font-weight: 700;
/* Font style */
font-style: italic;
font-style: oblique;
/* Shorthand */
font: italic bold 16px/1.5 Arial, sans-serif;
}
Text Properties:
.paragraph {
/* Alignment */
text-align: left;
text-align: center;
text-align: right;
text-align: justify;
/* Decoration */
text-decoration: underline;
text-decoration: line-through;
text-decoration: none;
/* Transform */
text-transform: uppercase;
text-transform: lowercase;
text-transform: capitalize;
/* Spacing */
letter-spacing: 2px;
word-spacing: 5px;
line-height: 1.6;
/* Indent */
text-indent: 50px;
/* Shadow */
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
Web Fonts:
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
body {
font-family: 'Roboto', sans-serif;
}
Absolute Units:
/* Pixels (most common) */
font-size: 16px;
/* Points (print) */
font-size: 12pt;
/* Inches, cm, mm (rarely used) */
width: 2in;
Relative Units:
/* em - relative to parent font-size */
font-size: 1.5em; /* 1.5 times parent */
/* rem - relative to root (html) font-size */
font-size: 1.5rem;
/* Percentage */
width: 50%;
font-size: 120%;
/* Viewport units */
width: 50vw; /* 50% of viewport width */
height: 100vh; /* 100% of viewport height */
font-size: 5vmin; /* 5% of smaller dimension */
Every element is a rectangular box with:
.box {
/* Content area */
width: 300px;
height: 200px;
/* Padding (inside) */
padding: 20px;
padding: 10px 20px; /* vertical horizontal */
padding: 10px 20px 30px 40px; /* top right bottom left */
/* Border */
border: 2px solid black;
border-width: 2px;
border-style: solid;
border-color: black;
border-radius: 10px;
/* Margin (outside) */
margin: 20px;
margin: 10px auto; /* center horizontally */
/* Box-sizing */
box-sizing: border-box; /* includes padding and border in width */
}
Content-box (default):
.box {
width: 300px;
padding: 20px;
border: 5px solid black;
/* Actual width = 300 + 40 + 10 = 350px */
}
Border-box (recommended):
* {
box-sizing: border-box;
}
.box {
width: 300px;
padding: 20px;
border: 5px solid black;
/* Actual width = 300px (includes padding and border) */
}
/* Block elements (full width) */
div {
display: block;
}
/* Inline elements (only content width) */
span {
display: inline;
}
/* Inline-block (inline but can have width/height) */
.button {
display: inline-block;
width: 200px;
padding: 10px;
}
/* Hide element */
.hidden {
display: none;
}
/* Flex and Grid (next week) */
.container {
display: flex;
display: grid;
}
/* Hide but keep space */
.invisible {
visibility: hidden;
}
/* Hide completely */
.gone {
display: none;
}
/* Transparent */
.see-through {
opacity: 0.5;
}
Static (default):
.element {
position: static; /* Normal flow */
}
Relative:
.element {
position: relative;
top: 20px; /* Move down from normal position */
left: 10px; /* Move right from normal position */
}
Absolute:
.parent {
position: relative;
}
.child {
position: absolute;
top: 0;
right: 0; /* Position relative to parent */
}
Fixed:
.navbar {
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 1000; /* Stack order */
}
Sticky:
.sidebar {
position: sticky;
top: 20px; /* Sticks when scrolling */
}
.layer1 {
position: relative;
z-index: 1;
}
.layer2 {
position: relative;
z-index: 2; /* Appears on top */
}
.modal {
position: fixed;
z-index: 9999; /* Very top */
}
.sidebar {
float: left;
width: 30%;
}
.main {
float: right;
width: 68%;
}
.clearfix::after {
content: "";
display: table;
clear: both;
}
🛠️ Teaching Tools & Platforms
Live coding in VS Code + Live Server (set up and demo CSS changes in real time).
Online editors like CodePen/JSFiddle for student experimentation.
Weekly small projects (e.g., style a resume, build a responsive navbar).
By the end of the activity, students will:
You will create and publish a single-page website on
github.io, styled using CSS. Choose a theme:
- XKCD-style comic page
- Star Wars opening crawl
- Retro terminal / hacker page
- Your own fun theme
Your page must be online by the end of the session.
Create a GitHub account (if needed).
Create a new repository called:
username.github.io
Add two files:
index.htmlstyle.cssEnable GitHub Pages → Settings → Pages → Deploy from main branch
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Fun Webpage</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>Welcome to My Page</h1>
<p>A long time ago, in a browser far, far away…</p>
</header>
<main>
<section>
<h2>About</h2>
<p>This page is styled entirely with CSS.</p>
</section>
</main>
</body>
</html>
Students must:
body {
background: black;
color: yellow;
font-family: 'Arial', sans-serif;
overflow: hidden;
}
main {
width: 60%;
margin: auto;
font-size: 1.5em;
text-align: justify;
animation: crawl 20s linear infinite;
}
@keyframes crawl {
from { transform: translateY(100%); }
to { transform: translateY(-200%); }
}
body {
font-family: "Comic Sans MS", cursive;
background: white;
color: black;
}
h1 {
border-bottom: 2px solid black;
}
section {
max-width: 600px;
margin: auto;
}
Vote for:
🏆 Small prizes or bragging rights recommended.
Create a themed website hosted on GitHub Pages that uses CSS to express a narrative or aesthetic.
You may work individually or in pairs.
Your site must include:
header, main, footer or similar)section, nav, article)At least:
Use of:
One of:
username.github.io| Criterion | Marks |
|---|---|
| CSS correctness & clarity | 30 |
| Visual creativity & theme | 25 |
| HTML structure | 20 |
| GitHub Pages deployment | 15 |
| Code readability | 10 |
| Total | 100 |