Introduction To HTML 1
Introduction To HTML 1
Overview
HTML tags are like keywords that define how a web browser will format and
display content. With the help of tags, a web browser can distinguish between
HTML content and simple content. HTML tags contain three main parts: an
opening tag, a content, and a closing tag. But some HTML tags are unclosed tags.
There are some tags in HTML that are necessary for your HTML document
because they present important information about our webpage for the
interpretation of the browser.
Some examples of essential HTML tags include <!DOCTYPE html> tag, the
<head> tag, the<title> tag, etc. Let's explore these and understand what they are
and how to use them.
The <!DOCTYPE html> tag is the first tag of any HTML document. It's a special
tag that does not have a closing set of brackets and doesn't have any HTML content
inside it.
It is used to tell the browser that the document loaded is an HTML document.
If you put an HTML tag outside the <html> tag, it may not be considered by the
browser.
<html>
...
</html>
1
The <head> tag appears at the top of any HTML document. It displays some other
tags inside it that are used to give some additional information about the webpage.
For instance, it may have a <meta> tag to provide some meta information about the
document, as shown below.
<head>
<meta charset="UTF-8">
</head>
The <title> tag is used to give a title to the HTML document. This title also
appears on the tab of a browser where your HTML document is rendered.
<title> HTML Tags </title>
The <body> tag encloses all HTML tags that are used to create various HTML
documents and webpages of your website.
<body> …….. </body>
For instance, let's say you have a portfolio website where you want to talk about
yourself. The entire content of your portfolio website would go inside the <body>
tag as shown below:
<body>
<h1>
Hi there! This is my portfolio
</h1>
<p>I'm a <strong>web developer</strong></p>
</body>
Now that we're through with the basics, let's explore some other commonly used
HTML tags alongside their use cases and syntax.
2
Unclosed HTML Tags
Some tags in HTML do not require a closing tag. They don't allow any content
inside them.
Since these tags don't have a set of closing brackets, they're called Unclosed
HTML tags. They're also known as void elements in HTML.
For instance, the horizontal ruling tag <hr> is an unclosed HTML tag.
Sytax:
<hr>
Here's a list of some the unclosed tags or void elements defined by HTML
Standard:
<br>
<col>
<hr>
<img>
<input>
<link>
<meta>
The <p> tag stands for the paragraph tag. It is used to render a paragraph or a
group of words on the webpage.
<p>
This is a paragraph!
</p>
You can use a <p> tag whenever you need to render more than one word, a line, or
a bunch of lines that need to be styled in a similar fashion.
3
The <span> tag is used for a group of words within a paragraph that needs to be
styled differently.
Here's an example of a <span> tag that has a different font color than the rest of the
paragraph:
<h1> defines the most important heading. <h6> defines the least important heading
of a HTML tag.
<h1> This is H1 </h1>
<h2> This is H2 </h2>
<h3> This is H3 </h3>
<h4> This is H4 </h4>
<h5> This is H5 </h5>
<h6> This is H6 </h6>
Sometimes you need to lay more emphasis on some parts of your paragraph.
Browsers, by default, render anything inside a <strong> tag as bold text.
<p> Sokoto State University has <strong>faculty of ICT</strong></p>
In the above sytax the words in side <strong> Tag will displayed in bold form on a
web browser.
Just like the <strong>, the <em> tag is also used to lay emphasis on certain text
within a paragraph.
However, instead of making the text bold, browsers render content inside the <em>
tag as italics.
The most important attribute of the <a> element is the href attribute, which
indicates the link's destination.
HTML gives us the <link> tag, which can be used to include an external asset,
resource, or file in a document.
The link tag can be used to connect you external css file to your HTML document
Syntax:
<link rel=”stylesheet> type=”text/css” href=”style.css>
The <img> tag in HTML is used to output or render images on the webpage. It
specifies the source of the image using the src attribute, as shown below:
The <object> tag is used to render any external resource like an image, video, or
website inside a container in your HTML page.
You can specify the path of the resource inside the data attribute of the <object>
tag as shown:
5
<object data=”image/boy.jpg” width=”400” hight=”400”>
The above would output the same image that the <img> tag did previously.
The <object> isn't used widely on modern websites. There are other alternatives to
the <object> tag, like <img>, <video>, <audio> etc., that are used in its place.
Example:
An unordered list starts with the <ul> tag. Each list item starts with the <li> tag.
<ul>
<li>Computer Science</li>
<li>Information Technology</li>
</ul>
Ordered list starts with the <ol> tag and each list item starts with the <li> tag.
<ol>
<li>Cyber Security</li>
<li>Artificial Intelligence</li>
</ol>
HTML provides support for a description list using the <dl> tag. A description list
renders a list of terms using the <dt> tag.
6
For each term, we can use the <dd> tag to present the description of that term.
<dl>
<dt>Web Development</dt>
<dd>HTML & CSS</dd>
<dd>PHP</dd>
<dt> Content Management</dt>
<dd>Wordpress</dd>
<dd>Joomla</dd>
</dl>
We can create rows and columns to specify the structure of the table using the <tr>
tag and the <th> tag. Then, we can display content inside each cell of the table
using the <td> tag.
<table>
<tr>
<th>Programmes</th>
<th>Cars</th>
<th>Countires</th>
</tr>
<tr>
<td>Data Science</td>
<td>BMW</td>
<td>Egypt</td>
</tr>
<tr>
<td>Cyber Security</td>
<td>Ford</td>
<td>Nigeria</td>
</tr>
<tr>
<td>Information Systems</td>
<td>Honda</td>
<td>Cyprus</td>
7
</tr>
</table>
Form is a common way to take input from a user, for example create account links
on some websites take some information from a user that wants to apply for a
particular task in the organization such information most often is sent to a server
for processing.
In such scenarios, HTML provides us with the <form> tag that we can use to create
a form on the webpage. Inside the <form> tag, we can render input fields using the
<input> tag and specify their labels using the <label> tag.
The <form> element is a container for different types of input elements, such as:
text fields, checkboxes, radio buttons, submit buttons, etc.
<form>
Some elements here…..
</form>
<form>
<label for=”fname”>First Name</label>
<input type=”text” id=”fname” name=”name”>
<label for=”surname”>Surname</label>
</form>
<form>
<input type=”checkbox” id=”car” name=”car” value=”car”>
<label for=”car”>Car</label>
8
<input type=”checkbox” id=”bike” name=”bike” value=”bike”>
<label for=”bike”>Bike</label>
</form
<form>
<input type=”radio id=”book” name=”book” value=”book”>
<label for=”book”>Book</label>
<input type=”radio” id=”laptop” name=”laptop” value=”laptop”>
<label for=”laptop”>Laptop</label>
</form>
<form action=”userdata.php”>
<label for=”country”>Country name</label><br>
<input type=”text” id=”country” name=”country”
value=”country”><br>
<label> for=”state”>State Name</label>
<input type=”text” id=”state” name=”state” value=”state”
<input type=”button” value=”submit”>
</form>
<script src="index.js"></script>
Comments in HTML
Comments in programs are subtitles for developers! Comments are messages for
developers that don't have any meaning for the browser.
9
We can add a comment on an HTML page using the opening comment keyword
<!-- and the closing one --> as shown below:
Syntax
<!—some comments here-->
Attributes in HTML
Attributes are properties of HTML tags that provide some additional information
on these tags.
For instance, the src attribute on the <img> tag tells us the URL of the image the
<img> tag is supposed to render.
10