π Introduction to HTML & CSS: Building Your First Web Page
Lesson Overview
In this lesson, you will:
- Understand the Basics of HTML & CSS
- Learn How to Structure a Web Page with HTML
- Style Your Web Page Using CSS
- Practice Semantic HTML for Better Accessibility & SEO
- Apply the CSS Box Model to Layout Your Content Properly
By the end of this lesson, you will have a fully structured and styled web page.
π Step 1: Setting Up Your Project
Before we start coding, let's set up our project.
π Project Folder Structure:
basic-webpage/
βββ index.html
βββ style.css1οΈβ£ Create a Project Folder
- Open VS Code (or any text editor).
-
Open your terminal and run:
mkdir basic-webpage cd basic-webpage -
Inside
basic-webpage, create the two necessary files:touch index.html style.css
π Step 2: Writing the HTML
HTML (HyperText Markup Language) is the structure of a webpage. Think of it like the skeleton of a body.
What is Semantic HTML?
Semantic HTML uses meaningful tags that describe their content. Examples include:
<header>for the top section of a page<main>for the primary content<section>to group related content<footer>for the bottom of a page
π Code: index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Web Page</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<!-- Header Section -->
<header>
<h1>Welcome to My Web Page</h1>
</header>
<!-- Main Content -->
<main>
<section>
<h2>About Me</h2>
<p>Hi! I'm learning HTML and CSS. This is my first webpage.</p>
</section>
<section>
<h2>My Interests</h2>
<ul>
<li>Coding</li>
<li>Music</li>
<li>Traveling</li>
</ul>
</section>
</main>
<!-- Footer -->
<footer>
<p>© 2025 My First Web Page</p>
</footer>
</body>
</html>Explanation
- The
<head>contains metadata and links to the CSS file. - The
<header>section contains the main title (<h1>). -
The
<main>includes:- "About Me" section with a paragraph.
- "My Interests" section with an unordered list (
<ul>).
- The
<footer>includes copyright information.
π Step 3: Styling with CSS
CSS (Cascading Style Sheets) is used to style the HTML structure.
CSS Box Model
Everything in CSS is a box with:
- Content (text or images)
- Padding (space inside the border)
- Border (the edge around the content)
- Margin (space outside the border)
π Code: style.css
/* Reset default styles */
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
color: #333;
}
/* Header Styling */
header {
background-color: #007bff;
color: white;
padding: 20px;
text-align: center;
}
/* Main Content */
main {
max-width: 800px;
margin: 20px auto;
padding: 20px;
background: white;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
/* Section Styling */
section {
margin-bottom: 20px;
}
/* List Styling */
ul {
list-style-type: square;
}
/* Footer Styling */
footer {
background: #007bff;
color: white;
text-align: center;
padding: 10px;
margin-top: 20px;
}Explanation
-
The
bodyhas global styles:font-family: Arial, sans-serif;β Sets a clean font.background-color: #f4f4f4;β Adds a light background.
-
The
header:background-color: #007bff;β Gives a blue background.color: white;β Makes text white.text-align: center;β Centers the text.
-
The
main:max-width: 800px; margin: auto;β Centers the content.box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);β Adds a soft shadow for depth.
-
The
footer:- Matches the header for a cohesive look.
π Step 4: Viewing Your Page
- Open your project folder.
- Open
index.htmlin your browser. - You should see a beautifully structured and styled webpage!
π Step 5: Understanding the CSS Box Model
The Box Model controls how elements behave.
Example of a Box Model Breakdown
div {
width: 300px;
padding: 10px;
border: 5px solid black;
margin: 20px;
}Explanation:
width: 300px;β Content width.padding: 10px;β Space between content & border.border: 5px solid black;β Adds a black border.margin: 20px;β Adds space outside the box.
Visual Representation
+-----------------------+ β Margin (20px)
| +-----------------+ | β Border (5px)
| | Content Area | | β Padding (10px)
| +-----------------+ |
+-----------------------+π Step 6: Next Steps
β
Created a structured HTML page
β
Styled it with CSS
β
Applied the Box Model
β
Understood semantic HTML for better accessibility
π― Next Lesson: Adding a Hamburger Menu & JavaScript for Interactivity! π
Final Notes
You now have a strong foundation in HTML & CSS! Feel free to experiment:
- Change colors & fonts
- Modify spacing & layout
- Practice adding more sections
In the next lesson, we will:
- Build a hamburger menu for navigation β
- Use JavaScript to fetch & display data from an API β
Letβs keep building! π
