GAME DEV 2026 · HTML & CSS FUNDAMENTALS
t1a04 — CSS by Innes
Cascading Style Sheets (CSS) control how HTML elements look. CSS is usually written in a stylesheet, but you can also add styles inside a page or directly on an HTML element.
1. CSS rule syntax
A CSS rule selects an element and sets one or more properties. Each declaration uses a property, a colon, a value, and a semicolon.
b {
color: #00ff00;
}
This rule makes text inside <b> elements green. The semicolon belongs after the value.
2. Inline styles and JavaScript
The first italic line uses the page's default styling. The second has an inline style that sets its text and background colours.
This is italic text.
This is italic text with a different colour and background colour.
document.getElementById('myB1').style.color = 'red';
document.getElementById('myB1').style.backgroundColor = 'yellow';
JavaScript can change an element's inline style while the page is running. Inline styles usually override competing declarations from a stylesheet.
3. Styling a textarea
This textarea has a background image and custom dimensions. Try typing in it or resizing it from its lower corner.
textarea {
background-image: url('image.jpg');
width: 300px;
min-height: 100px;
}
4. Images from the original assignment
These keep the original image examples. If an image file is not in the project folder, the browser will show its alternative text.
myImage01.jpg was not found in this folder.
myFih.jpg was not found in this folder.
5. CSS selectors
A selector chooses which HTML elements a rule affects.
p { color: white; } /* element selector */
.card { padding: 20px; } /* class selector */
#myB1 { background: blue; } /* ID selector */
Element selectors affect every matching element, class selectors can be reused, and an ID should identify one unique element on a page.
6. Box model
Every element can be thought of as a box containing content, padding, border, and margin.
/* Makes width calculations easier */
* { box-sizing: border-box; }
7. Try a CSS selector
This paragraph is changed by selecting its ID.