WEB UNI-2 HTML
WEB UNI-2 HTML
Hyper Text: Hypertext simply means "Text within Text." A text has
a link within it, is a hypertext. Whenever you click on a link which
brings you to a new webpage, you have clicked on a hypertext.
Hypertext is a way to link two or more web pages (HTML
documents) with each other.
<!DOCTYPE>
<html>
<head>
<title>Web page title</title>
</head>
<body>
<h1>Write Your First Heading</h1>
<p>Write Your First Paragraph.</p>
</body>
</html>
Description of HTML Example
<!DOCTYPE>: It defines the document type or it instruct the browser
about the version of HTML.
<html > :This tag informs the browser that it is an HTML document. Text
between html tag describes the web document. It is a container for all
other elements of HTML except <!DOCTYPE>
<head>: It should be the first element inside the <html> element, which
contains the metadata(information about the document). It must be
closed before the body tag opens.
<title>: As its name suggested, it is used to add title of that HTML page
which appears at the top of the browser window. It must be placed inside
the head tag and should close immediately. (Optional)
<body> : Text between body tag describes the body content of the page
that is visible to the end user. This tag contains the main content of the
HTML document.
<h1> : Text between <h1> tag describes the first level heading of the
webpage.
<p> : Text between <p> tag describes the paragraph of the webpage.
Features of HTML
o Tags: An HTML tag surrounds the content and apply meaning to it.
It is written between < and > brackets.
o Attribute: An attribute in HTML provides extra information about
the element, and it is applied within the start tag. An HTML attribute
contains two fields: name & value.
Syntax
1. <tag name attribute_name= " attr_value"> content </ tag name>
o Elements: An HTML element is an individual component of an HTML file. In an HTML
file, everything written within tags are termed as HTML elements.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>The basic building blocks of HTML</title>
5. </head>
6. <body>
7. <h2>The building blocks</h2>
8. <p>This is a paragraph tag</p>
9. <p style="color: red">The style is attribute of para
graph tag</p>
10. <span>The element contains tag, attribute a
nd content</span>
11. </body>
12. </html>
Output:
HTML Tags
HTML tags are like keywords which defines that how web browser will
format and display the content. HTML tags contain three main parts:
opening tag, content and closing tag. But some HTML tags are unclosed
tags.
When a web browser reads an HTML document, browser reads it from top
to bottom and left to right. HTML tags are used to create HTML documents
and render their properties. Each HTML tags have different properties.
You can use as many tags you want as per your code requirement.
o All HTML tags must enclosed within < > these brackets.
o Every tag in HTML perform different tasks.
o If you have used an open tag <tag>, then you must use a close tag
</tag> (except some tags)
Syntax
<tag> content </tag>
Some HTML tags are not closed, for example br and hr.
<br> Tag: br stands for break line, it breaks the line of the code.
<hr> Tag: hr stands for Horizontal Rule. This tag is used to put a line
across the webpage.
HTML Attribute
o HTML attributes are special words which provide additional
information about the elements or attributes are the
modifier of the HTML element.
o Each element or tag can have attributes, which defines
the behaviour of that element.
o Attributes should always be applied with start tag.
o The Attribute should always be applied with its name and
value pair.
o You can add multiple attributes in one HTML element, but
need to give space between two attributes.
Syntax
1. <element attribute_name="value">content</element>
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. </head>
5. <body>
6. <h1> This is Style attribute</h1>
7. <p style="height: 50px; color: blue">It will add style property in elemen
t</p>
8. <p style="color: red">It will change the color of content</p>
9. </body>
10. </html>
Output:
Explanation of above example:
1. <p style="height: 50px; color: blue">It will add style property in element
</p>
Example
With link address:
Example
1. <img src="whitepeacock.jpg" height="400" width="600">
Note: The above example also have height and width attribute, which define the height and width of image on
web page.
Output:
HTML 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.
1) Bold Text
HTML<b> and <strong> formatting elements
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.
Output:
Example
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>formatting elements</title>
5. </head>
6. <body>
7. <h1>Explanation of formatting element</h1>
8. <p><strong>This is an important content</strong>, and this is normal content</p>
9. </body>
10. </html>
2) Italic Text
HTML <i> and <em> formatting elements
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.
See this example:
Output:
The HTML <em> tag is a logical element, which will display the enclosed
content in italic font, with added semantics importance .
Output:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title>formatting elements</title>
5. </head>
6. <body>
7. <h1>Explanation of italic formatting element</h1>
8. <p><em>This is an important content</em>, which displayed in italic font.</p>
9. </body>
10. </html>
Output:
Output:
5) Strike Text
Anything written within <strike>.......................</strike> element is
displayed with strikethrough. It is a thin line which cross the statement.
Output:
6) Monospaced Font
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:
Hello Write Your First Paragraph in monospaced font.
7) Superscript Text
If you put the content within <sup>..............</sup> element, is shown in
superscript; means it is displayed half a character's height above the
other characters.
Output:
8) Subscript Text
If you put the content within <sub>..............</sub> element, is shown in
subscript ; means it is displayed half a character's height below the other
characters.
Output:
9) Deleted Text
Anything that puts within <del>..........</del> is displayed as deleted text.
Output:
Hello
10) Inserted Text
Anything that puts within <ins>..........</ins> is displayed as inserted text.
Output:
Output:
2. Output:
The href attribute is used to define the address of the file to be linked. In
other words, it points out the destination page.
Example:
1. <!DOCTYPE html>
2. <html>
3. <head>
4. <title></title>
5. </head>
6. <body>
7. <p>Click on <a href="https://www.google.com/" target="_blank"> this-link </a>to go on ho
me page of JavaTpoint.</p>
8. </body>
9. </html>
Output:
Note:
o The target attribute can only use with href attribute in anchor tag.
o If we will not use target attribute then link will open in same page.
HTML Image
HTML img tag is used to display image on the web page. HTML img tag
is an empty tag that contains attributes only, closing tags are not used in
HTML image element.
Output:
Attributes of HTML img tag
The src and alt are important attributes of HTML img tag. All attributes of HTML image tag are
given below.
1) src
It is a necessary attribute that describes the source or path of
the image. It instructs the browser where to look for the image
on the server.
2) alt
The alt attribute defines an alternate text for the image, if it
can't be displayed. The value of the alt attribute describe the
image in words. The alt attribute is considered good for SEO
prospective.
3) width
4) height
Example:
1. <img src="animal.jpg" height="180" width="300" alt="animal image">
Output:
We can use alt attribute with tag. It will display an alternative text
in case if image cannot be displayed on browser. Following is the example
for alt attribute:
Output:
How to get image from another directory/folder?
To insert an image in your web, that image must be present in your same
folder where you have put the HTML file. But if in some case image is
available in some other directory then you can access the image like this:
Note: If src URL will be incorrect or misspell then it will not display your image on web page, so try to put correct
URL.
Example:
<a href="https://www.google.com/what-is-
robotics"><img src="robot.jpg" height="100"
width="100"></a>
Output:
HTML pre tag
The HTML <pre> tag is used to specify pre formatted
texts. Texts within <pre>.......</pre> tag is displayed in
a fixed-width font. Usually it is displayed in Courier font.
It maintains both space and line break.
1. <pre>
2. This is a formatted text
3. by using the HTML pre tag. It maintains
4. both space and line break.
5. </pre>
Output:
This is a formatted text
by using the HTML pre tag. It maintains
both space and line break.
1. <pre>
2. package com.javatpoint;
3. public class FirstJava{
4. public static void main(String args[]){
5. System.out.println("hello java");
6. }
7. }
8. </pre>
Output:
package com.javatpoint;
public class FirstJava{
public static void main(String args[]){
System.out.println("hello java");
}
}
If you remove pre tag from the above example, all the text will be displayed in a single line.
You can indicate quoted text in the document using the "BLOCKQUOTE and Q
elements. BLOCKQUOTE is used for long quotations and is displayed as an
indented paragraph. If the quotations bort and does not require paragraph breaks,
the Q element works fine. When using the Q element you have to specify delimiting
quotation marks.
<HTML>
<BODY>
<P> The blockquote element is used to format the content in blocks of text <BLOCKQUOTE><FONT
color = green>
I work hard,
</FONT>
</BLOCKQUOTE>
<P>If you notice the content is rendered as a block of text.
</BODY> </HTML>
You can insert special characters into the text of the HTML document. To ensure that the
browser does not confuse them with HTML tags, you have to attach escape codes to the
special characters.
>
Example
<HTML>
</TITLE> <BODY>
A=A+1
</CODE>
</body>
</html>
<
Ex:
< HTML >
<HEAD>
<BODY>
A=A+1 </CODE>
</BODY> </HTML>
QUOTES “ “
"
<HTML>
<BODY>
</BODY> </HTML>
Space
& nbsp
<body>
</body>
Ampersand &
&
<P> Give Respect & Get Respect</P>
Lists
We can use three types of lists to represent different types of data in HTML:
1. Unordered List <ul>
2. Ordered List <ol>
3. Description List <dl>
Dot,secqur
Ex…
<ul>
<li>Apple</li>
<li>Orange</li>
<li>Mango</li>
</ul>
output
Ordered List(A,a,1,i,)
The ordered list is used to represent data in a list for which the order of
items has significance.
The <ol> tag is used to create ordered lists. Similar to unordered lists,
each item in the ordered list must be a <li> tag. For example,
Ex..
<ol>
<li>Ready</li>
<li>Set</li>
<li>Go</li>
</ol>
output
Description List
The HTML description list is used to represent data in the name-value
form. We use the <dl> tag to create a definition list and each item of the
description list has two elements:
term/title - represented by the <dt> tag
description data of the term - represented by the <dd> tag
Ex…
<dl>
<dt>HTML</dt>
<dt>CSS</dt>
<dd>Cascading StyleSheets</dd>
<dt>JS</dt>
<dd>Javascript</dd>
</dl>
Output
HTML Links
HTML links or hyperlinks connect one resource on the web to another. The resource
may be an image, a web page, a program, a video clip, an audio clip, an element
within a web page, etc, or anything that can be hosted on the internet.
We use the HTML <a> tag to create hyperlinks. The syntax for the <a> tag is
Ex..
Output
Default Link Styles
By default, browsers will style links differently depending on whether the link is
active, visited, or unvisited.
Image Links
You can insert almost any content inside a <a> tag to make it a link.
Hence, we can also use images as a link.
Ex…
<a href="https://www.programiz.com">
</a>
Output
target Attribute
By default, any link clicked will open in the same browser window.
This may lead to a bad user experience. This is where
the target attribute becomes useful
Target Description
_top Opens the link in the current tab window (topmost parent).
download Attribute
Ex..
HTML Tables
HTML tables allow web developers to arrange data into rows
and columns.
Example
Example
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
</table>
output
Company Contact Country
Alfreds Futterkiste Maria Anders Germany
Centro comercial Moctezuma Francisco Chang Mexico
Table Cells
Everything between <td> and </td> are the content of the table cell.
Example
<table>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
</table>
output
Emil Tobias Linus
Note: A table cell can contain all sorts of HTML elements: text, images,
lists, links, other tables, etc.
Table Rows
Each table row starts with a <tr> and ends with a </tr> tag.
tr stands for table row.
Example
<table>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
<tr>
<td>16</td>
<td>14</td>
<td>10</td>
</tr>
</table>
Emil Tobias Linus
16 14 10
You can have as many rows as you like in a table; just make sure that the
number of cells are the same in each row.
Table Headers
Sometimes you want your cells to be table header cells. In those cases
use the <th> tag instead of the <td> tag:
Example
<table>
<tr>
<th>Person 1</th>
<th>Person 2</th>
<th>Person 3</th>
</tr>
<tr>
<td>Emil</td>
<td>Tobias</td>
<td>Linus</td>
</tr>
<tr>
<td>16</td>
<td>14</td>
<td>10</td>
</tr>
</table>
Person 1 Person 2 Person 3
16 14 10
By default, the text in <th> elements are bold and centered, but you can
change that with CSS.
EX…
<table border="1">
<tr>
<td>column 1</td>
<td>column 2</td>
<td>column 3</td>
</tr>
</table>
output
One row, multi column:
column 1 column 2 column 3
EX..
<table border="1">
<tr>
<td>Row 1, Column 1</td>
<td>Row 1, Column 2</td>
<td>Row 1, Column 3</td>
</tr>
<tr>
<td>Row 2, Column 1</td>
<td>Row 2, Column 2</td>
<td>Row 2, Column 3</td>
</tr>
</table>
Row 1, Column 1 Row 1, Column 2 Row 1, Column 3
Row 2, Column 1 Row 2, Column 2 Row 2, Column 3
rowspan
Category Examples
<table border="1">
<tr>
<th>Category</th>
<th colspan="3">Examples</th>
</tr>
<tr>
<td>Fruits</td>
<td>Apples</td>
<td>Oranges</td>
<td>Grapes</td>
</tr>
</table>
Output
Category Examples
Fruits Apples Oranges Grapes
Colspan:
<table border="1">
<tr>
<th>Department:</th>
<td>Accounting</td>
</tr>
<tr>
<th rowspan="2">Contact Person:</th>
<td>Freya Olsen</td>
</tr>
<tr>
<td>Maita Cot</td>
</tr>
</table>
Output:
Department: Accounting
Freya Olsen
Contact Person:
Maita Cot
FORM
<form> tag
This HTML code will force your visitors to choose only one option. If you
need to allow
your visitors to choose more than one option, you just add the multiple
attribute to the
Text Area= A text area acts like a text field, only that you
have more space than just one line. It is not defined by an
<input> tag, but by a tag such as.
This will show a text box with the words "Input text here" filled in.
You can also specify
the number of rows and columns to control the size of your text box,
i.e.,<textarearows="15" cols="20">
Ex…
<textarea>
</textarea>
Grouping Form Data with <fieldset>
The <fieldset> element groups related data in a form.
The <legend> element defines a caption for the <fieldset>
element.
EX..
<form>
< fieldset>
<legend>form:</legend>
First name:<br>
<input type="text" name="firstname" value="Text"
placeholder="ENTER THE NAME"><br>
Last name:<br>
<input type="text" name="lastname" value="Text "
placeholder="ENTER THE LAST NAME"><br> <br>
<input type="submit" value="Submit">
</fieldset>
</form>
EX…..
<form>
NAME: <input type="text" name="na" placeholder="a/c
holder name"required><br>
F_NAME: <input type="text"name="fname"><br>
ADDRESS: <textarea name="add"></textarea><br>
DOB: <input type="date" name="d"><br>
Gender: <input type="radio" name="gender"
value="m">Male
<input type="radio" name="gender" value="f">Female<br>
EMAIL: <input
type="text"name="email"required><br>
CONTACT: <input type="text" pattern="[0-9]{10}"
name="cont"><br>
ACOUNT NO: <input type="text" name="acno"
required><br>
IFSC-COD: <select name="ifsc"><br>
<option>BOB34412jpr </option>
<option>UCO7676jpr</option>
<option>HDFC868jpr</option>
<option>SBI98IN</option>
<option>PNB1143</option>
<option>AU00501jpr</option>
</select><br>
BANKNAME: <select name="bank">
<option>--select--</option>
<option>BOB</option>
<option>UCO</option>
<option>HDFC</option>
<option>SBI</option>
<option>PNB</option>
<option>AU</option>
</select><br>
AC TYPE:<select name="actype">
<option>SAVING</option>
<option>CREDIT</option>
</select><br>
<input type="Submit" value="Submit" name="Submit">
</form>
IFRAME
The <iframe> tag specifies an inline frame. An inline
frame is used to embed another document within the
current HTML document.
EX….
DIVISION <div>
<div class="myDiv">
<h2>This is a heading in a div element</h2>
<p>This is some text in a div element.</p>
</div>
Thank you..!