By the end of this lesson, you will be able to:
:information_source: HTML (HyperText Markup Language) is the special language we use to create web pages. Think of it as the building blocks for everything you see on the internet!
HTML uses special tags that tell your web browser what to display. Here's what HTML does:
:bulb: Tip You can write HTML in any text editor! Just save your file with
.html
at the end (likemypage.html
) and open it in a web browser.
When you type a website address (like www.telebort.com) into your browser, here's what happens:
Graphical illustration of how does HTML work
:memo: Note HTML is like a human body! Just as our body has a head and a body, an HTML page has a
<head>
section (for information) and a<body>
section (for content).
Analogy of HTML structure as human body
Let's see how HTML transforms into a web page:
HTML Input:
<!DOCTYPE html>
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is my first paragraph.</p>
</body>
</html>
Browser Interpretation:
The browser reads the HTML tags and understands:
- <h1> = Main heading
- <p> = Paragraph text
- <title> = Page title (shown in browser tab)
Output:
Welcome to My Website
This is my first paragraph.
:information_source: HTML Elements are the building blocks of web pages. Most elements have two parts: an opening tag and a closing tag that wrap around your content.
Elements wrap around your content like a sandwich:
<tagname>
</tagname>
Let's create a paragraph:
HTML Input:
<p>Hi! My name is Chong Wei!</p>
Output:
Hi! My name is Chong Wei!
Some elements don't need closing tags. We call these empty elements:
<br />
: Creates a line break (like pressing Enter)<img>
: Adds an image<hr>
: Draws a horizontal lineHere's how <br />
works:
HTML Input:
<p>Hi!<br /> My name is Chong Wei!</p>
Output:
Hi!
My name is Chong Wei!
:bulb: Tip HTML tags work in UPPERCASE or lowercase (
<P>
=<p>
), but always use lowercase. It's easier to read and is the standard way to write HTML!
:information_source: HTML Attributes are like special instructions that give extra information about an element. They help control how elements look and behave.
Attributes are powerful tools that:
Attributes always go in the opening tag and follow this pattern:
<tag attribute="value">...</tag> OR <tag attribute="value">
The <img>
tag uses the src
attribute to show images. Here's how:
HTML Input:
<img src="https://example.com/kitten.jpg" />
Output:
<!-- Browser renders: -->
<img src="https://example.com/kitten.jpg" />
<!-- This displays an image of a kitten on the webpage -->
You can add many attributes to one element. Just separate them with spaces!
:memo: Note The
alt
attribute is super important! It shows text when:
- The image can't load
- Someone uses a screen reader
- The internet is slow
Let's add an alt
attribute:
HTML Input:
<img src="https://example.com/kitten.jpg" alt="A cute kitten" />
Output:
<!-- Browser renders: -->
<img src="https://example.com/kitten.jpg" alt="A cute kitten" />
<!-- If image fails to load, displays: "A cute kitten" -->
Let's review what we learned:
:white_check_mark: HTML is the language for creating web pages
:white_check_mark: Elements are building blocks with opening and closing tags
:white_check_mark: Attributes add extra information to elements
:white_check_mark: Tags should be written in lowercase
:white_check_mark: Some elements like <br />
and <img>
don't need closing tags
Code with AI: Let AI help you write HTML!
Prompts:
"Generate HTML for a paragraph with the text 'Hello, world!'"
"Create HTML for an image with the source 'image.jpg' and alt text 'My Image'."
"Generate HTML for an unordered list with three items: apples, bananas, and oranges."
Try these exercises to test your new skills:
<br />
tag to split a sentence into two linessrc
and alt
attributesRemember: The best way to learn HTML is by practicing. Open a text editor and start coding!