Style & Color Lesson 14 of 42
HTML Styles — Changing How Things Look
Learn the style attribute and your first CSS properties — color, background-color, font-size, font-family and text-align — plus the style element in the head.
HTML decides what is on the page. To change how it looks — colors, sizes, fonts, alignment — we use CSS (Cascading Style Sheets). CSS is a whole language of its own, but you can start using it right now inside your HTML. This lesson gives you a friendly first taste.
The style attribute
Any element can have a style attribute. Inside it, you write one or more CSS declarations. Each declaration has a property and a value, joined by a colon and ending with a semicolon:
style="property: value;"
style="color: blue; font-size: 20px;"
<h1 style="color: darkgreen;">Mabuhay!</h1>
<p style="color: gray;">Welcome to our class website.</p>
<p style="font-size: 24px;">This text is bigger.</p>
Five properties to start with
| Property | What it changes | Example value |
|---|---|---|
color | Text color | navy, #0f5c4d |
background-color | Background color | lightyellow |
font-size | Text size | 18px, 1.5em |
font-family | The font | Arial, sans-serif |
text-align | Alignment | left, center, right |
Background color
<body style="background-color: #fff8e1;">
<h2 style="background-color: #0038a8; color: white;">Team Blue</h2>
<h2 style="background-color: #ce1126; color: white;">Team Red</h2>
<p style="background-color: #fcd116;">Our flag colors: blue, red and yellow.</p>
</body>
Font family
font-family picks the font. Always give a list of choices, ending with a general family like sans-serif or serif, in case the first font isn't installed on the visitor's device.
<p style="font-family: Georgia, serif;">This looks like a printed book.</p>
<p style="font-family: Arial, Helvetica, sans-serif;">This is clean and modern.</p>
<p style="font-family: 'Courier New', monospace;">This looks like a typewriter.</p>
Text alignment
<h2 style="text-align: center;">Certificate of Recognition</h2>
<p style="text-align: center;">is awarded to</p>
<h3 style="text-align: center;">JUAN DELA CRUZ</h3>
<p style="text-align: right;">— The Principal</p>
Combining several properties
Put several declarations in one style, separated by semicolons.
<p style="background-color: #e3f1ec; color: #0f5c4d; font-size: 18px; font-family: Arial, sans-serif; text-align: center; padding: 16px; border: 2px solid #0f5c4d; border-radius: 10px;">
📢 <strong>No classes tomorrow</strong> due to the typhoon signal. Stay safe!
</p>
We sneaked in three extra properties: padding (space inside the box), border, and border-radius (rounded corners). Try changing their values!
A better way: the style element
Writing style on every element gets tiring and messy. If all your paragraphs should be gray, you'd have to repeat it on every single <p>. Instead, you can write the CSS once, in a <style> element inside the <head>:
<!DOCTYPE html>
<html>
<head>
<style>
body { font-family: Arial, sans-serif; background-color: #fbfaf7; }
h1 { color: #0f5c4d; text-align: center; }
p { color: #444; font-size: 18px; }
</style>
</head>
<body>
<h1>Grade 10 – Bonifacio</h1>
<p>All paragraphs are now gray and 18px.</p>
<p>We wrote the style only once!</p>
</body>
</html>
Each rule starts with a selector (like p) that says which elements to style, followed by declarations in curly braces { }. This is real CSS, and it's the start of the next big topic after HTML.
Three ways to add CSS
- Inline — the
styleattribute on one element. Quick, but hard to maintain. - Internal — a
<style>element in the head. Good for a single page. - External — a separate
.cssfile linked with<link rel="stylesheet" href="style.css">. Best for real websites, because many pages can share one design.
Quick Quiz
Check what you learned. Walang grade ito, practice lang. 🙂
By Sir Reyel · Last updated 2026-12-04