,
FUNDAMENTALS OF HTML (2)-4227
FUNDAMENTALS OF HTML (2)-4227
Comments in HTML
You can write a comment by placing the comment text between <! > tags.
For example:
TAGS
Tags are used to represent HTML elements. These can be seen as
keywords that define how a web browser will format and display
the website content.
● Tags define all document elements, i.e. they give meaning to the plain
HTML text.
● Two characters < and > surround HTML tags (They are called angle
brackets).
● The element contents are displayed between the start and end tags
● Tags that have an opening and closing can have any number of tags
within them.
● The <H1> and <h1> tags in HTML have the same meaning, i.e. tags
are not case-sensitive.
Eg: <html> and </html> is a tag that comes in pairs and <hr> does not have
a closing tag.
Tag Description
2 <html> </html> Root container for all other HTML elements of the
web page
(including the head tag)
3 <head> </head> The <head> element is a container for metadata
(data about data) Metadata typically defines the
document title,
character set, styles, scripts, and other meta
information.
4 <title> </title> Provides the title of the document and is displayed
in the tab in the browser
NOTE: There are also "self-closing" tags, whereby a br tag, for eg., will look like
"<br/>" instead of simply "<br>
EXTRA:
HTML ELEMENTS
Elements are the things that make up the web page. Tags define
the beginning and end of HTML elements. A web page can be seen
as a collection of HTML elements.
The basic elements used till now have been briefly described below
Paragraphs
Paragraphs are blocks of text separated from each other by some space.
They are defined using the <p> and </p> tags. When the p element ends, the
next element appears in the next line.
<!DOCTYPE html>
<html>
<head>
<title>p tag</title>
</head>
<body>
<p>This is line 1.</p>
<p>This is line 2.</p>
<!-- trying to format the text wiathout using p-tag -->
This is line 1. This is line 2. This is line 3.
</body>
</html>
It appears on a web browser like this:
NOTE: When formatting without a p-tag, new lines are appended on the
current line. This happens because the spacing of text doesn’t matter
to the browser.
Headings
These are HTML tags that are used to indicate that some content should be
treated as headings. The headings are divided into six levels: h1, h2, h3, h4,
h5, and h6. Among them, h1 is the highest-level heading and h6 is the
lowest-level heading.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Heading Levels</title>
</head>
<body>
<h1>Heading level 1 </h1>
<h2>Heading level 2 </h2>
<h3>Heading level 3 </h3>
<h4>Heading level 4 </h4>
<h5>Heading level 5 </h5>
<h6>Heading level 6 </h5>
</body>
</html>
Output:
BR Tag
<br> tag can be used to make a single line split between the contents of the
tab. This means that when this tag is used between a single line, the
contents after this tag will pass to the next line. Do not use it to allow
space between a block of elements ( eg., paragraph and heading).
E.g.
HR Tag
The <hr> tag in HTML, short for "horizontal rule," is a simple and effective
element used to create a horizontal line or divider on a web page. This tag is
self-closing, meaning it doesn't require a corresponding closing tag.
Historically, the <hr> tag was employed to indicate a thematic break or a
visual division between different sections of a document.
The basic syntax of the <hr> tag is uncomplicated: <hr>. When used in HTML,
it produces a horizontal line that spans the width of its containing element.
While it has attributes like align, width, and color, these are often considered
deprecated in HTML5, and styling is usually accomplished through CSS for
better control over appearance.
<!DOCTYPE html>
<html>
<head>
<title>Hello, World !< /title>
</head>
<body>
<p>This is some content above</p>
<hr>
<p>This is some content below</p>
</body>
</html>
Output: -
LISTS
Lists are used to group different pieces of information so that they are easily
linked and easy to read.
There are three types of lists to pick from: ordered, unordered, and description lists.
Unordered Lists
It's used to group a group of similar objects that aren't arranged in any
specific order. Where the counting of objects isn't necessary,
unordered lists are used.
Bullets are used by default to separate the items. They are defined
using the <ul> tag.
Example:
<!DOCTYPE html>
<html>
<head>
<title>Unordered Lists</title>
</head>
<body>
<h1>Lists</h1>
<ul>
<li>first item</li>
<li>second item</li>
<li>third item</li>
</ul>
</body>
</html>
Output: -
NOTE: The above styles can be produced by using the 'type' attribute.
Ordered Lists
<html>
<head>
<title>Ordered Lists</title>
</head>
<body>
<h1>Lists</h1>
<ol>
<li>first item</li>
<li>second item</li>
<li>third item</li>
</ol>
</body>
</html>
Similarly, like the unordered lists, there are also different types of
Now, what if you want to change the starting numbering of the lists?
HTML has got the solution for it: the 'start' attribute. So, if we change <ol> to
Description Lists
A list of definitions is not the same as a list of items. This is a collection of items
with an explanation.
Tag Description
<!DOCTYPE html>
<html>
<head>
<title>Description Lists</title>
</head>
<body>
<h2>Description List</h2>
<dl>
<dt>Coffee</dt>
<dd>- black hot drink</dd>
<dt>Milk</dt>
<dd>- white cold drink</dd>
</dl>
</body>
</html>
HTML elements can be nested i.e. elements can contain elements. All HTML
documents consist of nested HTML elements
E.g.:
<!DOCTYPE html>
<html>
<head>
<title>Hello, World !< /title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<ul>
<li>first item</li>
<li>second item
<ul type="circle">
<li>second item first subitem</li>
<li>second item second subitem
<ul type="square">
<li>second item second subitem first sub-subitem</li>
<li>second item second subitem second sub-subitem</li>
<li>second item second subitem third sub-subitem</li>
</ul>
</li>
<li>second item third subitem</li>|
</ul>
</li>
<li>third item</li>
</ul>
</body>
</html>
This will give the output as
NOTE: There is no limitation to the depth of nested lists. Although it is true for all
paired/container tags, we should be careful in nesting elements inside each other
and should only do something meaningful.
CONCLUSION:
The exploration of HTML elements delves into commonly used tags such as <p>,
<h1>, <br>, and <hr>. These tags play key roles in defining paragraphs,
headings, line breaks, and horizontal rules, respectively. The practical
examples enhance the understanding of how these elements are employed
in real-world scenarios.
REFERENCES:
a. https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/HTML_
text_fundamentals
b. https://developer.mozilla.org/en-US/docs/Web/HTML/Element