The theoretical rules and structure of HTML5 and CSS3
Grade XI • Computer Science ⏱️ ~25 minBrief Intro — Web Language Core
Every web page you have ever visited is built on HTML — the language that gives a page its structure — and shaped by CSS — the language that gives it style. Together they answer two simple questions: what should the page contain, and how should it look?
This activity covers the rules that make HTML and CSS work together: how tags and attributes are written, how a full HTML5 document is structured, and how CSS decides which style wins when rules conflict. By the end you will be able to read and write clean, valid web pages with confidence.
Prerequisites
By the end of this activity, you will be able to:
Every HTML element is a tag that may carry attributes to configure it — try editing the simulator below, then read the anatomy to see exactly where each part lives.
Type HTML code in the textarea and see it rendered instantly below.
In HTML, we use tags to create elements. Elements can have attributes that provide additional information.
src and width (Always specified in the start tag).<br> and <hr> that have no content or end tag.HTML provides various tags for text formatting:
| Tag | Purpose | Example |
|---|---|---|
<b>, <strong> | Bold text | Bold text |
<i>, <em> | Italic text | Italic text |
<mark> | Highlighted text | Highlighted |
<small> | Smaller text | Small text |
<del> | Deleted text | |
<ins> | Inserted text | Inserted |
<sub> | Subscript | H2O |
<sup> | Superscript | X2 |
Comments are used to add notes in your code that are not displayed in the browser:
| Attribute | Purpose | Example |
|---|---|---|
align | Horizontal alignment (deprecated) | <p align="center"> |
title | Tooltip text | <abbr title="HyperText Markup Language">HTML</abbr> |
style | Inline CSS | <p style="color: red;"> |
id | Unique identifier — may be used on only one element per page | <p id="main-text"> |
class | Reusable identifier — the same value can be used on many elements | <p class="note"> |
Every HTML5 document follows the same skeleton: a <head> that holds settings for the browser and a visible <body> that holds the page you see.
A standard HTML5 document is strictly organized into metadata and visible content.
<title> tag defines the text shown on the browser tab, not the page content.
<h1> for the main heading on the actual page content.Every HTML5 document follows the same skeleton: the <!DOCTYPE html> declaration, an <html> tag with a lang attribute, a <head> section first, then a <body> section.
lang="en" — declares the page language on the <html> tag.Tables, lists, forms, and container tags are the building blocks you will reach for in almost every real web page.
Tables are used to display data in rows and columns:
<table> - Container for the table<tr> - Table row<th> - Table header cell (bold, centered)<td> - Table data cellcolspan - Spans multiple columnsrowspan - Spans multiple rowsHTML provides three types of lists:
| List Type | Tags | Example |
|---|---|---|
| Unordered List | <ul>, <li> | • Item 1 • Item 2 |
| Ordered List | <ol>, <li> | 1. Item 1 2. Item 2 |
| Definition List | <dl>, <dt>, <dd> | Term - Definition |
Forms collect user input:
<form> - Form container<input> - Input field (types: text, password, email, number, radio, checkbox, submit, reset, button)<label> - Label for form element<select> - Dropdown list<textarea> - Multi-line text inputname - Attribute to identify form dataplaceholder - Grey hint text shown inside an input until the user typesHTML provides container elements for grouping and styling:
<div> - Block-level container (creates line breaks before and after)<span> - Inline container (no line breaks, used within text)So far, you've built page structure with pure HTML — tags that give content meaning and organization. Now we shift gears to bring those same elements to life with CSS, which layers on visual styling. Notice that the style attribute you saw in the Common Attributes table is, in fact, inline CSS in action.
When several CSS rules touch the same element, the browser does not guess — it follows a strict cascading order and specificity rules.
CSS stands for **Cascading** Style Sheets because rules "cascade" down with a specific priority order.
<h1 style="color: blue"> (Highest Priority)<style> block in the head.<link rel="stylesheet" href="style.css"> tag placed in the <head> links to a separate .css file.green in an external file, but red in an internal block, and blue inline, what color will the user see?
A CSS rule has a selector (which elements to style) and a declaration block (the properties to apply):
h1 — the selector (every <h1> element).color: navy; and font-size: 2rem; — property-value pairs inside the braces, separated by semicolons.When two rules target the same element, the browser follows specificity — not just the cascade order above:
#main) has higher specificity than a class selector (.box).<div id="main" class="box"> above renders blue.id vs class distinction matters.The style attribute allows inline CSS styling:
| Property | Description | Example |
|---|---|---|
font-family | Text font | font-family: Arial, sans-serif; |
font-size | Text size | font-size: 16px; |
text-align | Text alignment | text-align: center; |
background-color | Background color | background-color: var(--card-bg); |
color | Text color | color: var(--text-color); |
border | Element border | border: 1px solid black; |
Color Formats:
rgb(255, 0, 0) - Red#ff0000 - Redhsl(0, 100%, 50%) - RedThe CSS properties you just mastered in Part 4 — color, font-size, background-color — set the look of your content. But to control layout and spacing, you need to understand the box model: every element is a rectangular box with layers of content, padding, border, and margin.
Every HTML element is considered a rectangular box. Understanding the layers is key to layout design.