Lab Manual No 02
Lab Manual No 02
MAD
Introduction to HTML
PART II
Dated:
Semester:
Autumn 2022
HTML <head>:-
The following tags can be added to the head section: <title>, <style>, <meta>, <link>, <script>,
<noscript>, and <base>.
Example:-
<head>
<title>HTML Basic tags</title>
_uacct = "UA-232293";
urchinTracker();
</script>
</head>
Therefore it is important to use a title that really describes the content of your site. The <title>
element should contain only the text for the title and it may not contain any other elements.
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
</head>
<body>
The content of the document......
</body>
</html>
Example:-
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
The <base> tag specifies the base URL/target for all relative URLs in a page:
<head>
<base href="http://www.w3schools.com/images/" target="_blank">
</head>
Example:-
<!DOCTYPE html>
<html>
<head>
<base href="http://www.w3schools.com/images/" target="_blank">
</head>
<body>
</body>
</html>
For example, authors can link to a document that acts as index for the current document, to an
alternate version in other language, or an alternate version designed for other media (e.g., a
printer).
A particular and very common use for the HTML link tag is to provide an external style sheets
file for the document.
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
The <style> tag is used to define style information for an HTML document.
Inside the <style> element you specify how HTML elements should render in a browser:
<head>
<style type="text/css">
body {background-
color:yellow;} p {color:blue;}
</style>
</head>
The <meta> tag provides metadata about the HTML document. Metadata will not be
displayed on the page, but will be machine parsable.
Meta elements are typically used to specify page description, keywords, author of the
document, last modified, and other metadata.
The metadata can be used by browsers (how to display content or reload page), search
engines (keywords), or other web services.
<html>
<head>
CSS was introduced together with HTML 4, to provide a better way to style HTML elements.
The preferred way to add CSS to HTML, is to put CSS syntax in separate CSS files.
Example:-
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
h1 {color:red;}
h2 {color:blue;}
p {color:green;}
</style>
</head>
<body>
</body>
</html>
Inline Styles:-
An inline style can be used if a unique style is to be applied to one single occurrence of an
element.
To use inline styles, use the style attribute in the relevant tag. The style attribute can contain any
CSS property. The example below shows how to change the text color and the left margin of a
paragraph:
<!DOCTYPE
html> <html>
<body style="background-color:yellow;">
<h2 style="background-color:red;">This is a heading</h2> <p
style="background-color:green;">This is a paragraph.</p>
</body>
</html>
The font-family, color, and font-size properties defines the font, color, and size of the text in
an element:
Example:-
<!DOCTYPE
html> <html>
<body>
<h1 style="font-family:verdana;">A heading</h1>
<p style="font-family:arial;color:red;font-size:20px;">A
paragraph.</p> </body>
</html>
Example:-
<!DOCTYPE
html> <html>
<body>
<h1 style="text-align:center;">Center-aligned
heading</h1> <p>This is a paragraph.</p>
</body>
</html>
An internal style sheet can be used if one single document has a unique style. Internal styles
are defined in the <head> section of an HTML page, by using the <style> tag, like this:
<head>
<style type="text/css">
body {background-
color:yellow;} p {color:blue;}
</style>
</head>
An external style sheet is ideal when the style is applied to many pages. With an external style
sheet, you can change the look of an entire Web site by changing one file. Each page must link to
the style sheet using the <link> tag. The <link> tag goes inside the <head> section:
<head>
<link rel="stylesheet" type="text/css"
href="mystyle.css"> </head>
In HTML 4, several tags and attributes were used to style documents. These tags are not
supported in newer versions of HTML.
Avoid using the elements: <font>, <center>, and <strike>, and the attributes: color and bgcolor.
HTML Images:-
HTML Images - The <img> Tag and the Src Attribute
The <img> tag is empty, which means that it contains attributes only, and has no closing tag.
To display an image on a page, you need to use the src attribute. Src stands for "source". The
value of the src attribute is the URL of the image you want to display.
The URL points to the location where the image is stored. An image named "boat.gif", located in
the "images" directory on "www.w3schools.com" has the
URL:http://www.w3schools.com/images/boat.gif.
The browser displays the image where the <img> tag occurs in the document. If you put
an image tag between two paragraphs, the browser shows the first paragraph, then the
image, and then the second paragraph.
The height and width attributes are used to specify the height and width of an image.
Tip: It is a good practice to specify both the height and width attributes for an image. If these
attributes are set, the space required for the image is reserved when the page is loaded. However,
without these attributes, the browser does not know the size of the image. The effect will be that
the page layout will change during loading (while the images load).
Note: If an HTML file contains ten images - eleven files are required to display the page right.
Loading images takes time, so my best advice is: Use images carefully.
Note: When a web page is loaded, it is the browser, at that moment that actually gets the image
from a web server and inserts it into the page. Therefore, make sure that the images actually stay
in the same spot in relation to the web page, otherwise your visitors will get a broken link icon.
The broken link icon is shown if the browser cannot find the image.
Example:-
<!DOCTYPE html>
<html>
<body>
<p>
An image:
<p>
</body>
</html>
Computing Fundamental Lab Instructor:-Adnan Mustafa
Session:-2K19 Computer
UNIVERSITY OF ENGINEERING AND TECHNOLOGY, TAXILA
FACULTY OF TELECOMMUNICATION AND INFORMATION ENGINEERING
COMPUTER ENGINEERING DEPARTMENT
<!DOCTYPE html>
<html>
<body>
<img src="http://www.w3schools.com/images/w3schools_green.jpg"
alt="W3Schools.com" width="104" height="142">
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<p>
</p>
<p>
</p>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<a href="default.asp">
<a href="default.asp">
</body>
</html>
HTML Tables:-
HTML Table Example:
Jill Smith 50
Eve Jackson 94
John Doe 80
Adam Johnson 67
Example:-
<!DOCTYPE html>
<html>
<body>
<p>
</p>
<h4>One column:</h4>
<table border="1">
<tr>
<td>100</td>
</tr>
</table>
<table border="1">
<tr>
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
</table>
<table border="1">
<tr>
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
<tr>
<td>400</td>
<td>500</td>
<td>600</td>
</tr>
</table>
</body>
</html>
HTML Tables:-
A table is divided into rows (with the <tr> tag), and each row is divided into data cells (with the
<td> tag). td stands for "table data," and holds the content of a data cell. A <td> tag can contain
text, links, images, lists, forms, other tables, etc.
Table Example
<table
border="1"> <tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
If you do not specify a border attribute, the table will be displayed without borders. Sometimes
this can be useful, but most of the time, we want the borders to show.
<table
border="1"> <tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>
All major browsers display the text in the <th> element as bold and centered.
<table
border="1"> <tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
Header 1 Header 2
Examples:-
<!DOCTYPE html>
<html>
<body>
<tr>
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
<tr>
<td>400</td>
<td>500</td>
<td>600</td>
</tr>
</table>
<table border="0">
<tr>
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
<tr>
<td>400</td>
<td>500</td>
<td>600</td>
</tr>
</table>
</body>
</html>
Table headers:-
How to create table headers.
<!DOCTYPE html>
<html>
<body>
<h4>Table headers:</h4>
<th>Name</th>
<th>Telephone</th>
<th>Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
<h4>Vertical headers:</h4>
<table border="1">
<tr>
<th>First Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th>Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<th>Telephone:</th>
<td>555 77 855</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<table border="1">
<caption>Monthly savings</caption>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$50</td>
</tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<tr>
<th>Name</th>
<th colspan="2">Telephone</th>
</tr>
<tr>
<td>Bill Gates</td>
<td>555 77 854</td>
<td>555 77 855</td>
</tr>
</table>
<table border="1">
<tr>
<th>First Name:</th>
<td>Bill Gates</td>
</tr>
<tr>
<th rowspan="2">Telephone:</th>
<td>555 77 854</td>
</tr>
<tr>
<td>555 77
855</td> </tr>
</table>
</body>
</html>
<!DOCTYPE html>
<html>
<body>
<table border="1">
<tr>
<td>
<p>This is a paragraph</p>
</td>
<table
border="1"> <tr>
<td>A</td>
<td>B</td>
</tr>
<tr>
<td>C</td>
<td>D</td>
</tr>
</table>
</td>
</tr>
<tr>
<ul>
<li>apples</li>
<li>bananas</li>
<li>pineapples</li>
</ul>
</td>
<td>HELLO</td>
</tr>
</table>
</body>
</html>
Cell padding:-
How to use cell padding to create more white space between the cell content and its borders.
<!DOCTYPE html>
<html>
<body>
<h4>Without cellpadding:</h4>
<table border="1">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With cellpadding:</h4>
<table border="1"
cellpadding="10">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
</body>
</html>
Cell spacing:-
How to use cell spacing to increase the distance between the cells.
<!DOCTYPE html>
<html>
<body>
<h4>Without cellspacing:</h4>
<table border="1">
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With cellspacing="0":</h4>
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
<h4>With cellspacing="10":</h4>
<tr>
<td>First</td>
<td>Row</td>
</tr>
<tr>
<td>Second</td>
<td>Row</td>
</tr>
</table>
</body>
</html>
<col> Specifies column properties for each column within a <colgroup> element