Introduction To HTML
Introduction To HTML
HTML is the skeleton of all web pages. It’s often the first language learned by developers, marketers, and
designers and is core to front-end development work.
❖ A markup language is a computer language that defines the structure and presentation of raw text.
❖ In HTML, the computer can interpret raw text that is wrapped in HTML elements.
❖ HyperText is text displayed on a computer or device that provides access to other text through links, also
known as hyperlinks.
Introduction to HTML
Elements and Structure > Introduction to HTML
<!DOCTYPE html>
<html>
<head>
<title>Online Training on Web Development: Build a Responsive Website With HTML, CSS and Bootstrap</title>
</head>
<body>
</body>
</html>
Introduction to HTML
Elements and Structure > Introduction to HTML
Example Explained
The <!DOCTYPE html> declaration defines that this document is an HTML5 document
The <html> element is the root element of an HTML page
The <head> element contains meta information about the HTML page
The <title> element specifies a title for the HTML page (which is shown in the browser's title bar or in the page's tab)
The <body> element defines the document's body, and is a container for all the visible contents, such as headings, paragraphs,
images, hyperlinks, tables, lists, etc.
The <h1> element defines a large heading
The <p> element defines a paragraph
HTML Anatomy
Elements and Structure > Introduction to HTML > HTML
Anatomy
Since there can be multiple levels of nesting, this analogy can be extended to
grandchildren, great-grandchildren, and beyond. The relationship between elements
and their ancestor and descendent elements is known as hierarchy.
HTML Structure
Elements and Structure > Introduction to HTML > HTML
Structure <body>
<div>
<h1>Sibling to p, but also grandchild of body</h1>
Let’s consider a more complicated example <p>Sibling to h1, but also grandchild of body</p>
that uses some new tags: </div>
</body>
In this example, the <body> element is the parent of the <div> element. Both the
<h1> and <p> elements are children of the <div> element. Because the <h1> and
<p> elements are at the same level, they are considered siblings and are both
grandchildren of the <body> element.
Exercise:
<body>
1. Now that you know how to structure
<h1>The Brown Bear</h1>
HTML elements, we’ll spend the rest
<h2>About Brown Bears</h2>
of the lesson building an informational <h3>Species</h3>
website using some of the most <h3>Features</h3>
common HTML elements. We’ve put <h2>Habitat</h2>
some elements in to get you started, <h3>Countries with Large Brown Bear Populations</h3>
but you’ll write the rest of the page on <h3>Countries with Small Brown Bear Populations</h3>
your own. <h2>Media</h2>
</body>
2. Below the <h3> heading that says
Features, add an <h2> heading that
says Habitat
<div>s don’t inherently have a visual representation, but they are very useful
when we want to apply custom styles to our HTML elements. <div>s allow us to
group HTML elements to apply the same styles for all HTML elements inside. We
can also style the <div> element as a whole. You can see how this can be done in
the Learn CSS course.
<div>s can contain any text or other HTML elements, such as links, images, or
videos. Remember to always add two spaces of indentation when you nest
elements inside of <div>s for better readability.
Divs
Elements and Structure > Introduction to HTML > Divs
Exercise:
1. Below the <h1> heading that says The
<body>
Brown Bear, add an opening <div> tag.
<h1>The Brown Bear</h1>
<div>
Place the closing </div> tag after the <h3> <h2>About Brown Bears</h2>
element that says Features. <h3>Species</h3>
<h3>Features</h3>
Remember to use your space bar to add two </div>
<div>
spaces of indentation when you nest
<h2>Habitat</h2>
elements. <h3>Countries with Large Brown Bear Populations</h3>
<h3>Countries with Small Brown Bear Populations</h3>
2. Above the <h2> element that says Habitat, </div>
add an opening <div> tag. <div>
Close the </div> tag after the <h3> element <h2>Media</h2>
that says Countries with Small Brown Bear </div>
</body>
Populations.
3. Above the <h2> element that says Media,
add an opening <div> tag.
HTML attributes provide additional When we add an id to a <div>, we place it in the opening tag:
information about HTML elements.
Exercise:
1. Add an id attribute with the value <body>
"introduction" to the <div> tag <h1>The Brown Bear</h1>
that’s below the The Brown Bear <div id="introduction">
<h2>About Brown Bears</h2>
<h1> heading.
<h3>Species</h3>
<h3>Features</h3>
2. Add an id attribute with the value </div>
"habitat" to the opening <div> tag <div id="habitat">
that has the Habitat <h2> heading <h2>Habitat</h2>
as a child. <h3>Countries with Large Brown Bear Populations</h3>
<h3>Countries with Small Brown Bear Populations</h3>
</div>
3. Add an id attribute with the value
<div id="media">
"media" to the opening <div> tag <h2>Media</h2>
that has the Media <h2> heading as </div>
a child. </body>
Displaying Text <div>
Elements and Structure > Introduction to HTML >
Displaying Text
<h1>Technology</h1>
</div>
<div>
<p>
Displaying Text
<span>Self-driving cars</span> are anticipated to replace up to 2 million jobs
If you want to display text in HTML, you
over the next two decades.
can use a paragraph or span:
</p>
</div>
Paragraphs (<p>) contain a block of plain
text.
<span> contains short pieces of text or
other HTML. They are used to separate
small pieces of content that are on the same In the example above, there are two different <div>. The second <div> contains
line as other content. a <p> with <span>Self-driving cars</span>. This <span> element separates
Take a look at each of these elements in “Self-driving cars” from the rest of the text in the paragraph.
action below:
It’s best to use a <span> element when you want to target a specific piece of
content that is inline, or on the same line as other text. If you want to divide
your content into blocks, it’s better to use a <div>.
Displaying Text
Elements and Structure > Introduction to HTML > <body>
Displaying Text <h1>The Brown Bear</h1>
<div id="introduction">
<h2>About Brown Bears</h2>
Exercise:
1. Below the <h2> element that says About <p>“The brown bear (Ursus arctos) is native to parts of northern Eurasia and North
Brown Bears, add <p> opening and America. Its conservation status is currently Least Concern. There are many subspecies
closing tags, and inside of the tags put within the brown bear species, including the Atlas bear and the Himalayan brown bear.”</p>
the following text:
<h3>Species</h3>
“The brown bear (Ursus arctos) is native <h3>Features</h3>
to parts of northern Eurasia and North </div>
<div id="habitat">
America. Its conservation status is
<h2>Habitat</h2>
currently Least Concern. There are
<h3>Countries with Large Brown Bear Populations</h3>
many subspecies within the brown bear
<h3>Countries with Small Brown Bear Populations</h3>
species, including the Atlas bear and the
</div>
Himalayan brown bear.” <div id= "media">
<h2>Media</h2>
</div>
Continue... </body>
Displaying Text <body>
Elements and Structure > Introduction to HTML > <h1>The Brown Bear</h1>
Displaying Text <div id="introduction">
<h2>About Brown Bears</h2>
<p>“The brown bear (Ursus arctos) is native to parts of northern Eurasia and North
Exercise: America. Its conservation status is currently Least Concern. There are many subspecies
within the brown bear species, including the Atlas bear and the Himalayan brown bear.”</p>
2. Below the <h3> element that says <h3>Species</h3>
<p>“Brown bears are not always completely brown. Some can be reddish or yellowish.
Features, add a paragraph with the following
They have very large, curved claws and huge paws. Male brown bears are often 30% larger
text: than female brown bears. They can range from 5 feet to 9 feet from head to toe.”</p>
<h3>Features</h3>
“Brown bears are not always completely </div>
brown. Some can be reddish or yellowish. <div id="habitat">
They have very large, curved claws and huge <h2>Habitat</h2>
paws. Male brown bears are often 30% <h3>Countries with Large Brown Bear Populations</h3>
<h3>Countries with Small Brown Bear Populations</h3>
larger than female brown bears. They can
</div>
range from 5 feet to 9 feet from head to toe.” <div id= "media">
<h2>Media</h2>
</div>
Continue... </body>
<body>
Displaying Text <h1>The Brown Bear</h1>
Elements and Structure > Introduction to HTML > <div id="introduction">
Displaying Text <h2>About Brown Bears</h2>
<p>“The brown bear (Ursus arctos) is native to parts of northern Eurasia and North
America. Its conservation status is currently Least Concern. There are many subspecies
Exercise: within the brown bear species, including the Atlas bear and the Himalayan brown bear.”</p>
<h3>Species</h3>
3.Under the <h3> element that says: <p>“Brown bears are not always completely brown. Some can be reddish or yellowish.
They have very large, curved claws and huge paws. Male brown bears are often 30% larger
than female brown bears. They can range from 5 feet to 9 feet from head to toe.”</p>
Countries with Small Brown Bear
<h3>Features</h3>
Populations </div>
<div id="habitat">
Add a paragraph with the following text: <h2>Habitat</h2>
<h3>Countries with Large Brown Bear Populations</h3>
“Some countries with smaller brown bear <p>“Some countries with smaller brown bear populations include Armenia, Belarus,
Bulgaria, China, Finland, France, Greece, India, Japan, Nepal, Poland, Romania, Slovenia,
populations include Armenia, Belarus,
Turkmenistan, and Uzbekistan.”</p>
Bulgaria, China, Finland, France, Greece, <h3>Countries with Small Brown Bear Populations</h3>
India, Japan, Nepal, Poland, Romania, </div>
Slovenia, Turkmenistan, and Uzbekistan.” <div id= "media">
<h2>Media</h2>
</div>
</body>
Take a look at each style in action:
Styling Text
Elements and Structure > Introduction to HTML > Divs
<p><strong>The Nile River</strong> is the <em>longest</em> river in the
world, measuring over 6,850 kilometers long (approximately 4,260
You can also style text using HTML tags. miles).</p>
The <em> tag emphasizes text, while the
<strong> tag highlights important text.
In this example, the <strong> and <em> tags are used to emphasize the text to
Later, when you begin to style websites, produce the following:
you will decide how you want browsers to
The Nile River is the longest river in the world, measuring over 6,850 kilometers
display content within <em> and <strong> long (approximately 4,260 miles).
tags. Browsers, however, have built-in style
sheets that will generally style these tags in As we can see, “The Nile River” is bolded and “longest” is in italics.
the following ways:
The text, “Video not supported”, between the opening and closing
video tags will only be displayed if the browser is unable to load the
video.
Videos
Elements and Structure > Introduction to HTML > Videos
Exercise:
1. Under the image, create a <video> tag and add the following video url as
the source:
https://content.codecademy.com/courses/freelance-1/unit-1/lesson-2/html
css1-vid_brown-bear.mp4
2. Define the width of the video as "320" and the height as "240". Make
sure to also include the controls attribute.
3. In between the opening and closing <video> tags, add the phrase Video
not supported, which will be displayed if the browser is unable to load
your video.
HTML Semantic Semantic Elements in HTML
Elements Many web sites contain HTML code like: <div id="nav"> <div class="header"> <div
id="footer"> to indicate navigation, header, and footer.
Semantic elements = elements with a In HTML there are some semantic elements that can be used to define different parts
meaning. of a web page: