So far I've just given you some code and got you to run it, but I haven't
explained how it works.
Understanding tags
The first thing we need to understand is what tags are.
Tags are the things that are angle brackets <
and >
.
Let's look at the title tag:
<title>My First Website</title>
The first <title>
opens the tag and everything up to the closing </title>
is a child of the title tag. My First Website
is the child of the title
tag.
Most tags in HTML are opened with their name surrounded by <>
- for example <body>
-
and they are closed with a slash (/
) - for example </body>
.
<body>
means the body section starts here and </body>
means the body section ends here.
Some tags don't have closing tags but there are much less common than tags that do require closing tags.
The code
Let's go line by line over the code to understand what's going on.
<!DOCTYPE html>
is a special tag that doesn't have a closing tag,
and it tells the computer that the following code is HTML code.
<html>
says that the HTML code starts here. All you code will be a child of this tag.
<head>
is the start of the head
section, certain tags that
represent things which aren't displayed on your website must go here.
<title>My First Website</title>
tells the webpage that the title is My First Website
.
</head>
ends the head
section.
<body>
start the body
section which is where everything that is displayed on the screen goes.
<h1>Hello!</h1>
creates a large header with the message Hello!
.
h1
is short for header 1
where 1
is the largest size.
</body>
ends the body
section
</html>
says that this is the end of the HTML code.
Exercise
I mentioned that h1
means header size 1
where 1
is the largest size.
Well you can make headers smaller by increasing the number (up to a maximum of 6
).
Your task is to create a new header with a size 3
below the h1
.
The header should say I am a smaller header
.
Make sure you create both the opening and closing tag!
Tip: When you make your change you need to save the file and then refresh the page in your web-browser.
It should look like this when you've done it:
Solution
Check the solution here when you've done it.