25-503p-14-Flores-John Paul-Ths-343pm
25-503p-14-Flores-John Paul-Ths-343pm
25-503p-14-Flores-John Paul-Ths-343pm
Task # 005
Topic # VI HTML
Sub-Topics:
A. About HTML
Like the frame of a house might be composed of individual pieces of wood, an HTML document is composed
of individual HTML elements. Here is an example of a simple HTML element:
<p>This is an element</p>
Each HTML element is made up of tags, which for this element are the <p> and </p> symbols you see on
either side. You can think of them as a container, where the <p> tag marks the beginning of an element,
the </p> tag marks the end, and the content is the text in between.
The tags in the image below specify that the text inside is
a paragraph, which lets your browser know how to display
it. If you were to load that <p> element in a webpage, for
example, you would not see the <p> and </p> tags on
the screen. Your browser would just read those tags
as instructions to take the text in between and show it on
the screen, and to give that text a little space above and
below, and to let it take up a whole line on its own, just like
a paragraph printed in a book.
ELECT3 - Web Design Page | 1
In other words, HTML elements provide the structure of your page, just like the frame provides the
structure of a house. HTML elements generally look very plain on their own—we'll get to that later,
when CSS provides the presentation of your page—but they are the skeleton under all of the webpages you
visit.
Try this!
<p>This is a paragraph</p>
<p>Then one more paragraph</p>
<p>It's just a bunch of paragraphs</p>
Try adding all of that HTML to the input below, then press the View HTML button. Make sure to type in the
tags exactly, but feel free to change the text inside.
View HTML
Add our CSS
You should see the HTML you entered appear as three lines of text with a bit of space between each one.
Notice that the <p> and </p> tags you entered don't actually appear; they're there behind the scenes
telling your browser what to display.
Nested elements
If you think of an HTML element as a container, it's important to note that text is not the only thing that can
go inside of it. Sometimes you will want to put one HTML element inside of another, which is referred to
as nesting the element.
For example, if you wanted to make one of the words in a paragraph italic, the HTML element <i> can do
that, but to pick out just one word in your paragraph, you would need to put it inside the paragraph
element. It might look like this, for example:
Try adding that HTML to the input below, then press the View HTML button. Make sure to type in the tags
exactly, but feel free to change the text inside.
View HTML
Add our CSS
You should see a line of text where only the word "one" is italicized. Try wrapping the <i> and </i> tags
around a different word, too, or around more than one word. Whatever you put inside those tags should be
displayed in italics.
A webpage is a collection of HTML elements in an HTML document. The HTML for a very simple webpage
might look something like this:
Most of the webpages you regularly visit are going to have more
elements than this, and there are some that your browser will
require by default. Don't worry about that for now, though. The
important thing to keep in mind is that an HTML document is a file, just
like any other file you might find on your computer. For example, you
could save the code above to your hard drive and call it website.html:
Then you could double-click it to open it with a web browser, just the
way one might open a Word Document in Microsoft Word. When your browser opens the file, it uses the
HTML you've written as instructions to determine what it should show on the screen.
The webpages you visit every day on the Internet are no different. When you enter a web address into your
search bar or click on a link, you're sending a request to a computer somewhere else, and that computer
sends you a response in the form of an HTML document. In turn, your browser reads that HTML document,
just like it would if you double-clicked an HTML file on your hard drive.
Look familiar?
Most of the webpages you visit certainly look more complicated than what you see here, but the underlying
frame is still the same. No matter how elaborate they may be, the core is still HTML.
B. Create A Webpage
Once you have a basic grasp on what HTML actually is, you need to be able to see it work. A great way to do
that is to write and run your own HTML on your computer. This lesson assumes that you've set up your
workspace and are comfortable with the general skills that all of these tutorials require, so be sure to read
lessons if not.
Keep in mind that the HTML document you'll be creating in this lesson will only be available on your
computer; it will not be accessible by anybody else online. However, you will still be able to load it in your
browser just like the webpages you regularly visit.
Now that you have your empty index.html file open in your text editor, you can write your first HTML. Type
or copy the following into your empty index.html file:
<html>
<body>
<p>Hello, world!</p>
</body>
</html>
➢ <html>: The html element is the base container for everything else on your webpage. Every other
element you add will go inside of this one.
➢ <body>: The body element is where you will put all of the actual content of your website. If you
were to leave it blank, you could still load the page, but you'd see nothing but a white screen. To
start, all we'll put inside is a paragraph element, which you saw in the last lesson.
➢ <p>: The paragraph element is just like the paragraph elements you've seen before. This one is just
nested inside other elements.
Only the <p> element will actually show up as something you can see on the page. The others are what is
often referred to as boilerplate code, meaning that they appear unchanged in just about every HTML
document because your browser requires them.
There are other pieces of boilerplate code that your browser requires before it will consider this a valid
webpage, but we'll get to those later.
Nesting
You might have noticed a few things about how that code
was formatted, too. For example, some of the elements are inside
other elements. This is another example of the concept of nested
elements that we covered before.
Indentations
There are also indentations before some of the tags. They're there to make the code more readable to the
programmer working on it. Some people prefer to use the tab key to make these indentations, while others
prefer a few presses of the space bar, but in either case, the goal is to have an increasing amount of space
for each layer of nested elements, which makes it clearer which elements are inside of which.
As far as your browser goes, the amount you indent each element makes no difference. Your browser could
read that code formatted this way just as easily:
<html><body><p>Hello, world!</p></body></html>
That kind of formatting would make things much more difficult for you, though, and would make it much
easier to make a mistake if you wanted to change something.
Once you've filled in your HTML file and saved it, you can view it as a webpage in your browser. Just follow
these steps:
The file should open in your default web browser. You should
see something like this:
Try this!
If you want to keep playing with these basic pieces, you can.
1. Go back to your text editor and change the text inside the paragraph element in index.html to say
whatever you want.
2. Save the file and refresh the page in your browser.
3. You should see your new text on the page.
By default, every browser puts a bit of space above and below paragraph elements when they display them,
which keeps each paragraph independent from the ones around it, just like the paragraphs you'd see
printed in a book or magazine.
Like the paragraph element, heading elements are also used to display text on the screen. They're generally
used to create section headings.
For example, you might use a heading element to display the title of
an essay you're writing, or the name of a chapter in a book. The
actual text of the essay or chapter, on the other hand, would use
paragraph elements.
They also come with some default browser styling, which reinforces that order of importance:
the <h1> element is the biggest, the <h2> is smaller, and on like that.
Text formatting elements are used to change the way text looks in certain predefined ways. For instance,
here are a few common text formatting elements:
These elements are usually found nested inside of other text elements, such as the paragraph or heading
elements, because they are usually only meant to apply to part of the text. For example:
<p>These words aren't bold, but <b>these two</b> are.</p>
Try experimenting with each of the elements covered in this lesson in the input below. You can enter
whatever you want, but if you need some ideas on what to enter, try using the elements below as an
example.
View HTML
Add our CSS
Do it yourself!
Open the index.html file of your GCF Programming Tutorials project in your text editor, and let's add
some text elements. For the best understanding, be sure to actually type this code in, rather than copying
and pasting it.
1. When you first created this file, you already had one element of actual content on the page. First,
find that element:
<p>Hello, world!</p>
3. Instead, let's start making something that's more like a real webpage that you might actually see in
regular life: a movie review webpage. Start with a heading, and make sure to put it inside
the <body> element, where your <p>element was before:
<h1>Cinema Classics Movie Reviews</h1>
4. Just below that, let's add a sub-heading. While the first heading was the main heading of your whole
webpage, this one will just be the title for your review of a made-up blockbuster hit:
<h2>Review: Basketball Dog (2018)</h2>
5. Now let's add some text. This is the real meat of your review, so there are a lot more words, but
notice that they're still just wrapped in simple <p> tags, one for each separate paragraph. Add this
just below the <h1> element you just added:
<p>4 out of 5 stars</p>
6. Given that she's the director of the movie, it seems like "Vicki Fleming" might be the most important
name in those paragraphs, so let's make it bold to attract more attention to it. Wrap just that name
with <b> and </b> tags, like so:
<b>Vicki Fleming</b>
7. It also might be a good idea to set the star rating apart from the rest of the text, too.
Let's italicize that to separate it. Wrap just those words with <i> and </i> tags, like so:
<p><i>4 out of 5 stars</i></p>
Once you've done all of this, your complete code should look like this:
<html>
<body>
<h1>Cinema Classics Movie Reviews</h1>
<h2>Review: Basketball Dog (2018)</h2>
<p><i>4 out of 5 stars</i></p>
<p>From director <b>Vicki Fleming</b> comes the heartwarming tale of a boy named Pete (Trent
Dugson) and his dog Rover (voiced by Brinson Lumblebrunt). You may think a boy and his dog learning the
true value of friendship sounds familiar, but a big twist sets this flick apart: Rover plays basketball, and he's
doggone good at it.</p>
<p>While it may not have been necessary to include all 150 minutes of Rover's championship game in real
time, Basketball Dog will keep your interest for the entirety of its 4-hour runtime, and the end will have any
dog lover in tears. If you love basketball or sports pets, this is the movie for you.</p>
<p>Find the full cast listing at the Basketball Dog website.</p>
</body>
</html>
Double-click your index.html file to load it in the browser, and you should see this. Your webpage is starting
to look a little more like an actual webpage!
The HTML we've been working with so far works, but it's
technically missing some pieces that every browser expects it to
include: the DOCTYPE declaration and the head element. Unlike
most of the elements you've worked with so far, though, these
ones are not focused on creating the structure of what you see
on the page. Instead, they're focused on establishing
the metadata of your webpage.
Metadata is often described as "data about data." In other words, if the HTML of your webpage is data,
metadata is additional information used to explain various things about that HTML. For example, one might
use it to establish:
In turn, anything that reads your webpage—a browser, or a social media platform like Facebook or Twitter
where it might be shared, or a search engine like Google that might automatically collect information about
all sorts of webpages—can use that metadata to tell people useful information about your webpage.
One of the most essential pieces of metadata that is required on every webpage is the DOCTYPE
declaration. It should be the first thing you see in an HTML document (we'll be adding it to yours shortly)
and looks like this:
<!DOCTYPE html>
This particular DOCTYPE declaration states both that an HTML document contains HTML, and that the
version of that HTML is HTML5. It's important because there are still plenty of webpages on the Internet
written in older versions of HTML. For example, some webpages might have a DOCTYPE declaration that
looks more like this:
That declaration specifies an earlier version of HTML (4.1), which has some differences from HTML5. When
you load a webpage that doesn't have a DOCTYPE declaration, your browser goes into a special mode
called quirks mode. That basically just means that the browser is guessing what kind of HTML a webpage is
using, and when the browser starts guessing, it sometimes gets things wrong.
The rest of the metadata one might provide for a webpage goes inside of a special HTML element
called the <head> element. It looks like this:
<head></head>
Like many of the other HTML elements you've used, you can think of it as a container meant to hold all the
various types of metadata you might want to include. However, it's not part of the structure of your
The simplest version of a head element contains just one thing: the <title> element. The <title> element, as
the name suggests, should contain the title of your webpage. It's the only thing your browser requires the
head element to contain:
The <title> element lets anything that reads your HTML document know what to call it. For example, most
browsers use the <title> element to determine what to show in the tab for that webpage. If you were to
load a webpage with the above title element in your browser, you'd see this in your browser tab:
Real-world metadata
It may feel at first like metadata is unimportant—you can't see it doing anything on your webpage, after
all—but you're actually seeing metadata in use all the time in day-to-day life. For example, let's consider
this site. If you were to search for GCFLearnFree on Google, this would be your top result:
<meta name="description" content="GCFGLobal - The freedom to learn what you want, when you want,
absolutely free! Check out our Everyday Life, Basic Math, and Computer Training today!">
Just like before, the images and text you see there don't appear on
the homepage. Instead, they also come from a handful of slightly
different meta tags in the head element, these particular ones required by Facebook:
In other words, metadata doesn't necessarily tell you or show you much when you're just looking at your
own webpage, but it does a lot to help your browser make sense of your HTML, and it can provide tools for
things like social media platforms and search engines to understand and explain what your webpage is all
about.
Do it yourself!
Open the index.html file of your GCF Programming Tutorials project in your text editor, and let's add some
metadata.
1. First, go to the very top of your file and add this before anything else:
<!DOCTYPE html>
2. Next, find your opening <html> tag. All of your structural HTML elements go inside of
the <html> element, and the rest of your metadata does too.
3. Add your <head> element there, after the opening <html> tag and before the opening <body> tag.
Be sure to indent it to the same level as the <body> element for readability:
<head>
</head>
4. We left an empty line between the <head> and </head> tags because we're going to add the title
tag there. This is the title of the webpage, and we're making a movie review site, so let's give it a
name that reflects an interest in respectable films like Basketball Dog:
Open the File Explorer or Finder and navigate to your GCF Programming Tutorials project, then double-click
your index.html file. Your webpage should open in your default browser. Keep in mind that the <!DOCTYPE
html> addition is metadata just for your browser—you won't see it on the page—but now that you have it,
your browser will consider this to be valid HTML.
As for the <title> element you added, check the browser tab and you should see the title of your website
now. It should look like this.
1. https://edu.gcfglobal.org/en/basic-html/about-html/1/
2. https://edu.gcfglobal.org/en/basic-html/create-a-webpage/1/
3. https://edu.gcfglobal.org/en/basic-html/metadata-and-the-head-element/1/
4. https://edu.gcfglobal.org/en/basic-html/text-elements-in-html/1/