Professional Documents
Culture Documents
Unit - 2 Half HTML
Unit - 2 Half HTML
HTML
HTML stands for HyperText Markup Language. It is used to design web pages
using a markup language. HTML is a combination of Hypertext and Markup
language. Hypertext defines the link between web pages. A markup language is
used to define the text document within the tag which defines the structure of
web pages. This language is used to annotate (make notes for the computer)
text so that a machine can understand it and manipulate text accordingly. Most
markup languages (e.g. HTML) are human-readable. The language uses tags to
define what manipulation has to be done on the text.
HTML is a markup language used by the browser to manipulate text, images, and
other content, in order to display it in the required format. HTML was created by
Tim Berners-Lee in 1991. The first-ever version of HTML was HTML 1.0, but the
first standard version was HTML 2.0, published in 1995.
Elements and Tags: HTML uses predefined tags and elements which tell the
browser how to properly display the content. Remember to include closing tags.
If omitted, the browser applies the effect of the opening tag until the end of the
page.
UNIT 2 (MWA)
HTML page structure: The basic structure of an HTML page is laid out below. It
contains the essential building-block elements (i.e. doctype declaration, HTML,
head, title, and body elements) upon which all web pages are created.
<! DOCTYPE html>: This is the document type declaration (not technically a tag).
It declares a document as being an HTML document. The doctype declaration is
not case-sensitive.
<html>: This is called the HTML root element. All other elements are contained
within it.
<head>:
<body>: The body tag is used to enclose all the visible content of a webpage. In
other words, the body content is what the browser will show on the front-end.
An HTML document can be created using any text editor. Save the text file
using .html or .htm. Once saved as an HTML document, the file can be opened
as a webpage in the browser.
Example:
<! DOCTYPE html>
UNIT 2 (MWA)
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!--The above meta characteristics make a website compatible with different
devices. -->
<title>Demo Web Page</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
</body>
</html>
Output:
Features of HTML:
It is easy to learn and easy to use.
It is platform-independent.
Images, videos, and audio can be added to a web page.
Hypertext can be added to the text.
It is a markup language.
Why learn HTML?
It is a simple markup language. Its implementation is easy.
It is used to create a website.
UNIT 2 (MWA)
Helps in developing fundamentals about web programming.
Boost professional career.
Advantages:
HTML is used to build websites.
It is supported by all browsers.
It can be integrated with other languages like CSS, JavaScript, etc.
Disadvantages:
HTML can only create static web pages. For dynamic web pages, other
languages have to be used.
A large amount of code has to be written to create a simple web page.
The security feature is not good.
<body>: Next step is the most important of all the tags we have learned so
far. The body tag contains the actual body of the page which will be visible to
all the users. This opens with <body> and ends with </body>. All content
enclosed within this tag will be shown on the web page be it writings or
images or audio or videos or even links. We will see later in the section how
using various tags we may insert mentioned contents into our web pages.
HTML Headings: These tags help us to give headings to the content of a
webpage. These tags are mainly written inside the body tag. HTML provides
us with six heading tags from <h1> to <h6>. Every tag displays the heading in
a different style and font size.
Most HTML heading tag that we use:-
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Example
UNIT 2 (MWA)
<html>
<head>
<title>GeeksforGeeks</title>
</head>
<body>
<h1>Hello GeeksforGeeks</h1>
<h2>Hello GeeksforGeeks</h2>
<h3>Hello GeeksforGeeks</h3>
<h4>Hello GeeksforGeeks</h4>
<h5>Hello GeeksforGeeks</h5>
<h6>Hello GeeksforGeeks</h6>
</body>
</html>
Output:
Example:
<! DOCTYPE html>
<html>
<head>
UNIT 2 (MWA)
<title>GeeksforGeeks</title>
</head>
<body>
<h1>Hello GeeksforGeeks</h1>
</body>
</html>
Output:
HTML Horizontal Line: The <hr> tag is used to break the page into various parts,
creating horizontal margins with help of a horizontal line running from the left to
right-hand side of the page. This is also an empty tag and doesn’t take any
additional statements.
HTML Images: The image tag is used to insert an image into our web page. The
source of the image to be inserted is put inside the <img
src=”source_of_image“> tag.
Image can be inserted in the image tag in two formats: –
If the image is in the same folder, then we can just write the name of the
image and the format as the path.
If the image is in another folder, then we do need to mention the path of the
image and the image name as well as the format of the image.
UNIT 2 (MWA)
Text Formatting
HTML Formatting is a process of formatting text for better look and feel. HTML
provides us ability to format text without using CSS. There are many formatting
tags in HTML. These tags are used to make text bold, italicized, or underlined.
There are almost 14 options available that how text appears in HTML and XHTML.
o Physical tag: These tags are used to provide the visual appearance to the
text.
o Logical tag: These tags are used to add some logical or semantic value to
the text.
Here, we are going to learn 14 HTML formatting tags. Following is the list of HTML
formatting –
1) Bold Text
The HTML <b> element is a physical tag which display text in bold font, without
any logical importance. If you write anything within <b>............</b> element, is
shown in bold letters.
Output:
The HTML <strong> tag is a logical tag, which displays the content in bold font and
informs the browser about its logical importance. If you write anything between
<strong>???????. </strong>, is shown important text.
2) Italic Text
The HTML <i> element is physical element, which display the enclosed content in
italic font, without any added importance. If you write anything within
<i>............</i> element, is shown in italic letters.
Output:
The HTML <em> tag is a logical element, which will display the enclosed content
in italic font, with added semantics importance.
Output:
If you want to mark or highlight a text, you should write the content within
<mark>.........</mark>.
UNIT 2 (MWA)
See this example:
Output:
4) Underlined Text
Output:
5) Strike Text
Output:
6) Monospaced Font
UNIT 2 (MWA)
If you want that each letter has the same width then you should write the content
within <tt>.............</tt> element.
Note: We know that most of the fonts are known as variable-width fonts because
different letters have different width. (For example: 'w' is wider than 'i').
Monospaced Font provides similar space among every letter.
Output:
7) Superscript Text
Output:
8) Subscript Text
Output:
9) Deleted Text
Output:
Hello
Output:
Delete your first paragraph. Delete your first paragraph.Write another paragraph.
If you want to put your font size larger than the rest of the text then put the
content within <big>.........</big>. It increase one font size larger than the previous
one.
UNIT 2 (MWA)
See this example:
Output:
If you want to put your font size smaller than the rest of the text then put the
content within <small>.........</small>tag. It reduces one font size than the
previous one.
Output:
HTML Tables
Defining Tables in HTML: An HTML table is defined with the “table” tag. Each
table row is defined with the “tr” tag. A table header is defined with the “th”
tag. By default, table headings are bold and centered. A table data/cell is
defined with the “td” tag.
UNIT 2 (MWA)
<!DOCTYPE html>
<html>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output:
UNIT 2 (MWA)
Adding a border to an HTML Table: A border is set using the CSS border
property. If you do not specify a border for the table, it will be displayed without
borders.
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
UNIT 2 (MWA)
<td>41</td>
</tr>
</table>
</body>
</html>
Output:
Adding Collapsed Borders in an HTML Table: For borders to collapse into one
border, add the CSS border-collapse property.
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
UNIT 2 (MWA)
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
Output:
Adding Cell Padding in an HTML Table: Cell padding specifies the space between
the cell content and its borders. If we do not specify a padding, the table cells
will be displayed without padding.
<!DOCTYPE html>
<html>
<head>
<style>
table,
th,
UNIT 2 (MWA)
td {
border: 1px solid black;
border-collapse: collapse;
}
th,
td {
padding: 20px;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Priya</td>
<td>Sharma</td>
<td>24</td>
</tr>
<tr>
<td>Arun</td>
<td>Singh</td>
<td>32</td>
</tr>
<tr>
<td>Sam</td>
<td>Watson</td>
<td>41</td>
</tr>
</table>
</body>
</html>
UNIT 2 (MWA)
Output:
Adding Left Align Headings in an HTML Table: By default, the table headings are
bold and centered. To left-align the table headings, we must use the CSS text-
align property.
Adding Border Spacing in an HTML Table: Border spacing specifies the space
between the cells. To set the border-spacing for a table, we must use the CSS
border-spacing property.
<!DOCTYPE html>
<html>
<body>
<table border=5 bordercolor=black>
<tr>
<td> First Column of Outer Table </td>
<td>
<table border=5 bordercolor=grey>
<tr>
<td> First row of Inner Table </td>
</tr>
<tr>
<td> Second row of Inner Table </td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Output: