Introduction to HTML for Beginners_ , Covers HTML5, CSS3, Beginner_s Guide, 1ed
Introduction to HTML for Beginners_ , Covers HTML5, CSS3, Beginner_s Guide, 1ed
Chapter 12 : Projects
CONCLUSION
APPENDICES
TOPIC 1: INTRODUCTION
TO HTML
CHAPTER 1: WHAT IS HTML?
In the next chapter, we’ll dive deeper into HTML tags and how to
use them to create more complex web pages! HTML is a markup
language that structures the content on the web. It’s easy to learn,
and once you understand the basics, you can create simple web
pages. HTML works hand-in-hand with CSS and JavaScript to
bring web pages to life, and it’s the starting point for anyone
interested in web development.
In the next chapter, we’ll learn more about setting up the
environment!
CHAPTER 2: SETTING UP YOUR
ENVIRONMENT
Choosing a Text Editor
To start writing HTML, you need a text editor. A text
editor is a program where you can write and edit code. It’s
like a more advanced version of Notepad.
Here are some great text editors for beginners:
Why choose it? It’s free, lightweight, and has a ton of features
like syntax highlighting (which helps you see different parts of
your code in different colors), autocomplete, and extensions to
make coding easier.
Recommended for: Beginners and advanced users alike.
2. Sublime Text
Why choose it? It’s fast and simple. It also supports many
programming languages and offers features like multi-line
editing.
Recommended for: People who want something quick and
lightweight.
3. Notepad++
Why choose it? It’s a great free option for Windows users. It’s
simple and works well for HTML and other coding tasks.
Each of these editors will do the job well. For this book, we’ll
use VS Code in the examples, but you can follow along with any
text editor you like.
Setting Up Your First HTML File
Now that you have your text editor ready, it’s time to create your
first HTML file. Follow these steps:
<!DOCTYPE html>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>Welcome to my first HTML page. This is a simple
paragraph.</p>
</body>
</html>
Now that your file is saved, it’s time to view it in a web browser.
This is the fun part where you get to see your code in action!
Step 1: Open the HTML File in a Browser
To view your HTML file, follow these steps:
1. Go to the folder where you saved your index.html file.
2. Right-click on the file and select Open with.
3. Choose a web browser (Chrome, Firefox, Edge, or Safari).
The browser will open, and you’ll see the text you wrote displayed
on the screen.
Here’s what you should see:
1. HTML Tags
Tags are the building blocks of HTML. They look like this:
<p>This is a paragraph.</p>
The <p> is an opening tag.
The </p> is a closing tag.
Tags tell the browser what to do with the content between them. In
this case, the <p> tag tells the browser to treat the text inside it as
a paragraph.
2. HTML Elements
An element is the combination of the opening tag, the content, and
the closing tag:
<p>This is a paragraph.</p>
In this example:
The entire thing (<p>This is a paragraph.</p>) is an HTML
element.
It tells the browser where to go when the user clicks the link.
Attributes always come in name="value" pairs. Some common
attributes are:
href (for links).
src (for images).
alt (for image descriptions).
Now that you know about tags, elements, and attributes, let’s talk
about the structure of an HTML page. Every HTML document has a
basic structure that looks like this:
<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is the main content of the page.</p>
</body>
</html>
Let’s break it down:
1. <!DOCTYPE html>
This is called the DOCTYPE declaration. It tells the browser that the
document is written in HTML5, the most current version of HTML.
2. <html>...</html>
The entire page is wrapped inside the <html> tag. This tells the
browser that everything inside these tags is HTML.
3. <head>...</head>
The <head> section contains metadata about the webpage
(information that’s not shown directly on the page). Inside the head,
you’ll often find:
Title: The text between <title>...</title> will appear on the
browser tab. In our example, the title is "My Web Page."
4. <body>...</body>
The <body> section contains the main content of the page. This is
everything you see when you visit a website, including text, images,
and links. In our example:
<h1>Welcome to My Website</h1>: This is a heading.
<p>This is the main content of the page.</p>: This is a
paragraph.
<!DOCTYPE html>
<html>
<head>
<title>My Simple HTML Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my very first web page. I'm learning HTML!</p>
</body>
</html>
Save the file and refresh your browser to see the new paragraph!
In this chapter, you learned about the basic building blocks of HTML:
tags, elements, and attributes. We also walked through the structure
of an HTML document, with the <html>, <head>, and <body> tags.
Finally, you created a simple HTML page and experimented with
adding and changing content.
In the next chapter, we’ll explore more HTML tags that allow you to
create lists, and build links. You’re already on your way to becoming
an HTML pro!
TOPIC 2: CORE
HTML ELEMENTS
CHAPTER 4 – WORKING WITH
TEXT
Example:
<h1>This is an H1 Heading</h1>
<h2>This is an H2 Heading</h2>
<h3>This is an H3 Heading</h3>
<h4>This is an H4 Heading</h4>
<h5>This is an H5 Heading</h5>
<h6>This is an H6 Heading</h6>
Output:
The <h1> heading will appear the largest, while the <h6>
will be the smallest.
Use <h1> for main titles and <h2> to <h6> for subheadings
or less important titles.
Tip:
Always use headings in order. For example, don't skip from <h1>
directly to <h4>. This helps with the structure of your webpage and
improves SEO (search engine optimization).
Paragraphs (<p>)
The <p> tag is used to create paragraphs. This is where most of the
text content of your webpage goes.
Example:
<p>This is a paragraph. It’s useful for writing blocks of text.
</p>
<p>Here’s another paragraph with more information.</p>
Output:
Each paragraph will appear on its own line with some space
between them.
Tip:
Paragraphs are great for writing long sections of content. Make
sure to break up your text into small, readable chunks to improve
readability.
1. Bold (<b>)
The <b> tag makes the text bold, which is useful for emphasizing
important words.
<p>This is a <b>bold</b> word.</p>
2. Italics (<i>)
The <i> tag makes the text italic, which is often used for emphasis
or quotes.
<p>This is an <i>italic</i> word.</p>
3. Underline (<u>)
The <u> tag adds an underline to the text.
<p>This is an <u>underlined</u> word.</p>
Example:
<p>This is <b>bold</b>, <i>italic</i>, and <u>underlined</u>
text.</p>
Output:
Bold text stands out.
Italic text is slanted.
Underlined text has a line underneath it.
Output:
Item one
Item two
Item three
Tip:
Use ordered lists when the order of items matters (like
steps in a process).
Use unordered lists when the order doesn’t matter (like a
list of ingredients).
Example:
<a href="https://www.example.com">Visit Example
Website</a>
Explanation:
The <a> tag creates the link.
href="https://www.example.com" tells the browser where
to take the user when they click the link.
"Visit Example Website" is the clickable text that will
appear on the page.
Output:
Clicking on "Visit Example Website" will take the user to
https://www.example.com.
Step 1: Open your text editor and write the following code:
<!DOCTYPE html>
<html>
<head>
<title>Working with Text</title>
</head>
<body>
<h1>Welcome to My Webpage</h1>
Example:
<img src="image.jpg" alt="A beautiful view of nature">
Explanation:
<img> is the tag for inserting images.
The src attribute stands for source and tells the browser
where to find the image file.
The alt attribute provides alternative text in case the
image fails to load, or for accessibility reasons (like screen
readers for visually impaired users).
1. src (Source)
This attribute is required and provides the location of the image
file. It can be a link to an image on your computer or an image
from the web.
<img src="path/to/image.jpg" alt="Description of the image">
Tip:
Always use alt text for accessibility and try to maintain image
proportions by adjusting width or height alone.
Just like images, you can embed videos and audio into your HTML
pages.
The <video> tag allows you to play videos on your webpage. You
can control features like play, pause, and volume. It can contain
multiple sources for different video formats.
Example:
<video width="400" controls>
<source src="video.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
Explanation:
controls: Adds playback controls (play, pause, volume).
<source>: The actual video file (multiple formats can be
provided for better compatibility).
The <audio> tag works similarly to the <video> tag, allowing you
to play audio files.
Example:
<audio controls>
<source src="audio.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
Explanation:
controls: Adds play and pause buttons for the audio file.
<source>: Points to the location of the audio file.
In the next chapter, we’ll dive into CSS, the styling language that
will help make your webpage visually appealing!
CHAPTER 6: STRUCTURING
CONTENT
Inserting Images with the <img> Tag
Adding images to your webpage is one of the easiest ways to make
it more engaging. To insert an image, we use the <img> tag in
HTML. Unlike some tags, the <img> tag is self-closing, meaning it
doesn’t need an opening and closing tag pair.
1. <div> (Division)
The <div> tag is a block-level container, which means it takes up
the full width available, stacking elements one on top of the other.
Example:
<div>
<h2>Section Title</h2>
<p>This is a paragraph inside a div container.</p>
</div>
2. <span>
The <span> tag is an inline-level container, meaning it only takes
up as much width as necessary. It’s used to style or manipulate a
small part of text within a larger block.
Example:
<p>This is a <span style="color: blue;">blue</span> word.</p>
In this example, only the word "blue" is styled, without affecting
the rest of the sentence.
1. <header>
The <header> element is used to define the header section of a
page or section. It usually contains the logo, navigation, or
introductory information.
<header>
<h1>Welcome to My Website</h1>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
</ul>
</nav>
</header>
2. <footer>
The <footer> element is used to define the footer section of a page,
typically containing copyright information or links to privacy
policies.
<footer>
<p>© 2024 My Website. All rights reserved.</p>
</footer>
3. <main>
The <main> element represents the main content of the webpage.
There should only be one <main> section on a page, as it is meant
to highlight the primary content.
<main>
<h2>Main Content Title</h2>
<p>This is where the primary content of the page goes.</p>
</main>
4. <section>
The <section> element groups related content into sections. It’s
useful for dividing a page into different parts.
<section>
<h2>Services</h2>
<p>We offer web design and development services.</p>
</section>
5. <article>
The <article> element is used for self-contained content like blog
posts, news articles, or forums.
<article>
<h3>Blog Post Title</h3>
<p>This is an individual blog post.</p>
</article>
Why Semantic HTML Matters (Accessibility and SEO)
<div>Content Title</div>
<div>Some more content</div>
Semantic HTML:
<header>Content Title</header>
<main>Some more content</main>
<!DOCTYPE html>
<html>
<head>
<title>Structured Web Page</title>
</head>
<body>
<header>
<h1>Welcome to My Blog</h1>
</header>
<main>
<section>
<h2>Latest Articles</h2>
<article>
<h3>How to Learn HTML</h3>
<p>This article will teach you how to create webpages
with HTML.</p>
</article>
</section>
</main>
<footer>
<p>© 2024 My Blog. All rights reserved.</p>
</footer>
</body>
</html>
Output:
A page with a header, a section containing an article, and a
footer at the bottom.
In the next chapter, we’ll dive into CSS, the styling language that
will help make your webpage visually appealing!
CHAPTER 7: CREATING TABLES
Example:
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
<tr>
<td>Jane</td>
<td>Smith</td>
</tr>
</table>
Explanation:
The first row (<tr>) contains header cells (<th>), which
create headings for the columns.
The next two rows contain data cells (<td>), which hold
the actual data.
Output:
Explanation:
border="1" adds a border around each cell.
cellpadding="10" adds space inside each cell.
cellspacing="0" removes the space between cells.
Output:
Each cell now has borders and padding to make the table more
readable.
Using Tables for Organizing Data
Tables are best used for organizing data, such as product listings,
schedules, or any kind of structured information.
Output:
Forms are essential for collecting data from users, such as login
credentials, search queries, or survey responses. HTML forms
consist of input elements like text fields, checkboxes, and buttons,
all enclosed within a <form> tag.
Example:
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br><br>
<button type="submit">Submit</button>
</form>
Explanation:
<label>: Provides a label for the input field.
<input>: Defines different types of inputs like text, email,
or password.
<button>: Creates a clickable button to submit the form.
Output:
A simple form with fields for name and email, and a submit
button.
<label for="password">Password:</label>
<input type="password" id="password" name="password">
<br><br>
<label>Gender:</label>
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female">
Female<br><br>
<button type="submit">Submit</button>
</form>
Form Attributes: action, method
When you submit a form, the data needs to be sent somewhere.
That’s where the action and method attributes come in.
1. action
The action attribute defines where the form data should be sent
(the URL or server-side script).
<form action="/submit-form">
...
</form>
2. method
The method attribute specifies how to send the data. It can be
either GET (data is sent in the URL) or POST (data is sent in the
request body).
GET: Used when you’re retrieving data.
POST: Used when you’re sending sensitive or large
amounts of data.
Example:
<form>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br>
<br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"
minlength="6" required><br><br>
<button type="submit">Submit</button>
</form>
Explanation:
required: Makes the field mandatory.
minlength="6": Ensures the password is at least 6
characters long.
Output:
If the user tries to submit the form without entering valid data (like
a properly formatted email), the browser will show a message
prompting them to fix it.
<!DOCTYPE html>
<html>
<head>
<title>Registration Form</title>
</head>
<body>
<h2>Sign Up</h2>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password"
minlength="6" required><br><br>
<label>Gender:</label>
<input type="radio" name="gender" value="male"> Male
<input type="radio" name="gender" value="female">
Female<br><br>
<button type="submit">Submit</button>
</form>
TOPIC 3: BASIC
CSS
CHAPTER 9: WHAT IS CSS?
Brief Overview of CSS and Its Role
CSS stands for Cascading Style Sheets. It is a language used to
describe the look and formatting of an HTML document. While
HTML is responsible for the structure of a webpage (what’s on the
page), CSS is responsible for how that page looks (how the content
is presented).
Think of HTML as the building blocks of a house, while CSS is the
paint, decor, and furnishings that make the house beautiful.
Example in HTML:
<!DOCTYPE html>
<html>
<head>
<style>
p{
color: blue;
font-size: 16px;
}
</style>
</head>
<body>
<p>This is a paragraph styled with CSS.</p>
</body>
</html>
In this example, all paragraphs will be blue and have a font size of
16px.
CHAPTER 10: ADDING BASIC
STYLES
There are three main ways to add CSS to your HTML: inline
styles, internal CSS, and external stylesheets. Each method has
its own use cases.
Example:
<p style="color: green; font-size: 20px;">This is a green
paragraph.</p>
In this case, the style only applies to this one paragraph, making it
green and 20px in size.
Explanation:
The style attribute is used inside the <p> tag.
CSS properties like color and font-size are defined directly
inside the tag.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
color: red;
}
p{
font-family: Arial, sans-serif;
line-height: 1.5;
}
</style>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph with internal CSS.</p>
</body>
</html>
Explanation:
The <style> tag is placed inside the <head> of the
document.
The CSS inside the <style> tag applies to all matching
elements in the HTML. Here, all <h1> tags will be red, and
all <p> tags will use the Arial font with a line height of 1.5.
External Stylesheets: Linking CSS Files to HTML with
<link>
External CSS is the best practice for larger websites. It allows you
to keep your CSS in a separate file and link it to your HTML
document using the <link> tag. This keeps your HTML clean and
makes it easy to update styles across multiple pages.
Example:
1. Create an external CSS file (styles.css):
h1 {
color: blue;
}
p{
font-size: 18px;
color: darkgray;
}
html
Copy code
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>
<h1>This is a Heading</h1>
<p>This paragraph is styled with external CSS.</p>
</body>
</html>
Explanation:
The <link> tag is used to link an external CSS file
(styles.css) to the HTML document.
The href attribute contains the path to the CSS file.
All styles in the external CSS file will be applied to this
HTML page. For instance, the heading (<h1>) will be blue,
and the paragraph (<p>) will be dark gray.
There are three main ways to add CSS to your HTML: inline
styles, internal CSS, and external stylesheets. Each method has
its own use cases.
Example:
p{
font-size: 18px;
color: #333333;
font-family: Arial, sans-serif;
}
font-size: 18px; makes the text size 18 pixels.
color: #333333; changes the text color to dark gray using a
hexadecimal code.
font-family: Arial, sans-serif; sets the font to Arial, with
sans-serif as a fallback.
HTML Example:
<!DOCTYPE html>
<html>
<head>
<style>
p{
font-size: 18px;
color: #333333;
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<p>This paragraph has customized text style.</p>
</body>
</html>
Setting Background Colors
CSS also allows you to set background colors for any element on
your webpage using the background-color property.
Example:
body {
background-color: lightblue;
}
p{
background-color: yellow;
}
background-color: lightblue; sets the entire page’s
background to light blue.
background-color: yellow; gives the paragraph a yellow
background.
HTML Example:
<!DOCTYPE html>
<html>
<head>
<style>
body {
background-color: lightblue;
}
p{
background-color: yellow;
}
</style>
</head>
<body>
<p>This paragraph has a yellow background.</p>
</body>
</html>
CSS Example:
File.css
a{
color: blue;
text-decoration: none;
}
a:hover {
color: red;
text-decoration: underline;
}
a styles all links with a blue color and no underline by
default.
a:hover changes the link to red and adds an underline
when the user hovers over it.
HTML Example:
File1.html
<!DOCTYPE html>
<html>
<head>
<style>
a{
color: blue;
text-decoration: none;
}
a:hover {
color: red;
text-decoration: underline;
}
</style>
</head>
<body>
<a href="https://www.example.com">This is a link with hover
effects.</a>
</body>
</html>
TOPIC 4: PUTTING IT ALL
TOGETHER
CHAPTER 12 : PROJECTS
Before writing any code, it’s important to plan your web page. Ask
yourself the following questions:
What is the purpose of your webpage? – Is it a personal
blog, a simple landing page, or an informational page?
What content will be on the page? – This might include
headings, paragraphs, images, links, etc.
How will the content be structured? – Make a rough
sketch or outline of how you want your web page to look.
Identify key sections like the header, main content area,
and footer.
Once you’ve planned your content, start creating the structure of your
webpage using HTML. Begin by setting up a basic HTML document
with tags like:
<header>: This could contain a heading and a navigation
bar.
<main>: This is where your main content (paragraphs,
images, links) will go.
<footer>: You can add a simple footer with copyright
information or contact details.
Focus on:
Properly organizing your content inside sections and
containers using tags
like <div>, <section>, and <article>.
Use headings (<h1>, <h2>) for titles and subheadings, and
paragraphs (<p>) for content.
Adding Simple Styling with CSS
After structuring your webpage with HTML, use CSS to make it look
visually appealing. Apply simple styles like:
Text formatting: Change the font size, color, and style to
make the text easier to read.
Background colors: Set background colors for different
sections to make them stand out.
Spacing: Use padding and margins to ensure elements
aren’t too close to each other.
Keep it simple:
Use internal CSS or an external stylesheet.
Focus on creating a clean and readable design, with enough
spacing and visual contrast between different sections of
the page.
PROJECT 2 – YOUR FIRST
PORTFOLIO WEBSITE
Structuring the Portfolio Page with HTML
For links:
Create buttons or clickable images that take users to your
projects.
Make sure the links open in new tabs so users don’t leave
your portfolio.
Basic CSS Styling: Making It Look Presentable
Once you’ve added the content, use CSS to make your portfolio look
professional and well-designed. Focus on:
Typography: Choose fonts that are easy to read and match
your style. Use different font sizes for headings and body
text.
Colors: Select a color scheme that complements your
content. Use background colors and text colors that
contrast well.
Spacing and Layout: Make sure there’s enough spacing
between different sections and elements. Use margins and
padding to avoid a cluttered look.
Both of these projects are opportunities for you to experiment and get
creative. You don’t need to aim for perfection right away; instead,
focus on learning and gradually improving. Start with basic designs,
and as you grow more comfortable, try experimenting with more
advanced features and styles.
TOPIC 5: CONCLUSION
CONCLUSION
Recap of Key Concepts
Throughout this book, you’ve learned the fundamental building blocks
of web development through HTML and CSS. Here's a quick recap of
the key concepts covered:
HTML Basics: You explored the role of HTML in
structuring a webpage, learned about common tags,
elements, and attributes, and practiced creating well-
structured web documents.
CSS Basics: We introduced you to CSS and its role in
styling webpages. You learned how to apply inline,
internal, and external styles to HTML, and how to use
selectors, properties, and values.
Project Work: You built simple projects like a basic
webpage and your own portfolio website, which helped you
apply both HTML and CSS to real-world scenarios.