Aral Code

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;"
Example Your first styles
<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

PropertyWhat it changesExample value
colorText colornavy, #0f5c4d
background-colorBackground colorlightyellow
font-sizeText size18px, 1.5em
font-familyThe fontArial, sans-serif
text-alignAlignmentleft, center, right

Background color

Example 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.

Example font-family
<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

Example text-align
<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.

Example A styled announcement box
<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>:

Example CSS rules in 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

  1. Inline — the style attribute on one element. Quick, but hard to maintain.
  2. Internal — a <style> element in the head. Good for a single page.
  3. External — a separate .css file 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. 🙂

1. Which property changes the color of text?
2. Which style is written correctly?
3. Where should the <style> element go?
4. Why end a font-family list with sans-serif or serif?

By Sir Reyel · Last updated 2026-12-04