Lab2
Lab2
Lab # 02
Hyper Text Markup Language
Objective:
Theory:
What is HTML?
HTML stands for Hyper Text Markup Language. Hypertext is simply a piece of text that works as a link.
Markup Language is a way of writing layout information within documents. A markup language is a set
of markup tags. The tags describe document content
An HTML document is a plain text file that contains text and nothing else. When a browser opens an
HTML file, the browser will look for HTML codes in the text and use them to change the layout, insert
images, or create links to other pages.Since HTML documents are just text files they can be written in
even the simplest text editor.
You can write your HTML by hand with almost any available text editor, including notepad that comes as
a standard program with Windows. All you need to do is type in the code, then save the document,
making sure to put an .html extension or an .htm extension to the file.
HTML Tags:
HTML markup tags are usually called HTML tags. Basically, a computer sees an "A" as simply an "A" -
whether it is bold, italic, big or small. To tell the browser that an "A" should be bold we need to put a
markup in front of the A. Such a markup is called a Tag. All HTML tags are enclosed in < and >.
Syntax:
<tagname>content</tagname>
<html>
<head></head>
<
<body></body>
</html>
All webpages have an <html> tag at the beginning and the end, telling the browser where the
document starts and where it stops.
The head is used for text and tags that do not show directly on the page.
The body is used for text and tags that are shown directly on the page.
Head Section:
The head section of the webpage includes all the stuff that does not show directly on the resulting page.
The <title> and </title> tags encapsulate the title of your page. The title is what shows in the top of your
browser window when the page is loaded.
Another thing you will often see in the head section is Meta tags. Meta tags are used for, among other
things, to improve the rankings in search engines.
Quite often the head section contains JavaScript which is a programming language for more complex
HTML pages.
Finally, more and more pages contain codes for cascading style sheets (CSS).CSS is a rather new
technique for optimizing the layout of major websites.
Body Section:
The body of the document contains all that can be seen when the user loads the page.
In the rest of this lab you can learn in detail about all the different aspects of HTML, including:
Text
o Formatting
o Resizing
o Layout
o Listing
The <!DOCTYPE>Declaration:
The <!DOCTYPE> declaration helps the browser to display a web page correctly.
There are many different documents on the web, and a browser can only display an HTML page 100%
correctly if it knows the HTML type and version used.
Example:
<!DOCTYPE html>
<html>
<body>
</body>
</html>
The DOCTYPE declaration defines the document type
The text between <html> and </html> describes the web page
The text between <body> and </body> is the visible page content
The text between <h1> and </h1> is displayed as a heading
The text between <p> and </p> is displayed as a paragraph
Adobe Dreamweaver
Microsoft Expression Web
CoffeeCup HTML Editor
However, for learning HTML we recommend a text editor like Notepad (PC) or TextEdit (Mac). We
believe using a simple text editor is a good way to learn HTML. Follow the 4 steps below to create your
first web page with Notepad.
Start
All Programs
Accessories
Notepad
When you save an HTML file, you can use either the .htm or the .html file extension. There is no
difference, it is entirely up to you.
Start your web browser and open your html file from the File, Open menu, or just browse the folder and
double-click your HTML file.
HTML Headings
HTML headings are defined with the <h1> to <h6> tags.
Example
<!DOCTYPE html>
<html>
<body> This is heading 1
<h1>This is heading 1</h1> This is heading 2
<h2>This is heading 2</h2>
Hamdard Institute of Engineering & Technology, Hamdard University
SharaeMadinat al-Hikmah, Hakim Mohammad Said Road, Karachi - 74600, Pakistan
FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY
Hamdard Institute of Engineering & Technology
Hamdard University
<h3>This is heading 3</h3>
<h4>This is heading 4</h4> This is heading 3
<h5>This is heading 5</h5>
This is heading 4
<h6>This is heading 6</h6>
This is heading 5
</body>
</html> This is heading 6
HTML Paragraphs
HTML paragraphs are defined with the <p> tag.
Example
<!DOCTYPE html> This is a paragraph.
<html>
<body> This is a paragraph.
</body>
</html>
HTML Links
HTML links are defined with the <a> tag.
Example
<!DOCTYPE html> This is a link
<html>
<body>
<a href="http://www.hamdard.edu.pk">
This is a link</a>
</body>
</html>
HTML Images
HTML images are defined with the <img> tag.
HTML Elements
An HTML element is everything from the start tag to the end tag.
<br>
*The start tag is often called the opening tag. The end tag is often called the closing tag.
Example
<!DOCTYPE html>
<html>
<body>
<p>This is my first paragraph.</p>
</body>
</html>
The example above contains 3 HTML elements: <html> element, <body> element and <p> element.
HTML links are defined with the <a> tag. The link address is specified in the href attribute:
</body>
</html>
Below is a list of some attributes that can be used on any HTML element:
Attribute Description
HTML Lines
The <hr>tag creates a horizontal line in an HTML page. The hr element can be used to separate content:
HTML Comments
Comments can be inserted into the HTML code to make it more readable and understandable. Comments
are ignored by the browser and are not displayed. Comments are written like this:
</body>
</html>
Example
<!DOCTYPE html> This text is bold
Hamdard Institute of Engineering & Technology, Hamdard University
SharaeMadinat al-Hikmah, Hakim Mohammad Said Road, Karachi - 74600, Pakistan
FACULTY OF ENGINEERING SCIENCES AND TECHNOLOGY
Hamdard Institute of Engineering & Technology
Hamdard University
<html>
<body>
This text is strong
<p><b>This text is bold</b></p>
<p><strong>This text is strong</strong></p> This text is italic
<p><i>This text is italic</i></p>
<p><em>This text is emphasized</em></p> This text is emphasized
<p>This is<sub> subscript</sub> and
<sup>superscript</sup></p> This is subscript and superscript
</body>
</html>
A hyperlink (or link) is a word, group of words, or image that you can click on to jump to another
document.
When you move the cursor over a link in a Web page, the arrow will turn into a little hand.
The most important attribute of the <a> element is the href attribute, which indicates the link’s
destination.
Syntax
The HTML code for a link is simple. It looks like this:
Example
<a href="http://www.hamdard.edu.pk/">Visit Hamdard</a>
Tip: The "Link text" doesn't have to be text. It can be an image or any other HTML element.
The example below will open the linked document in a new browser window or a new tab:
<a href="http://www.hamdard.edu.pk"
target="_blank">Visit Hamdard!</a>
</body>
</html>
Tip: Bookmarks are not displayed in any special way. They are invisible to the reader.
Example
Create a link to the "Useful Tips Section" inside the same document:
<a href="http://www.w3schools.com/html_links.htm#tips">
Visit the Useful Tips Section</a>
HTML Tables
Tables are defined with the <table> tag.
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 border="1">
<tr>
<td>Row 1, cell 1</td>
<td>Row 1, cell 2</td>
</tr>
</table>
<col> Specifies column properties for each column within a <colgroup> element
<ul> Coffee
<li>Coffee</li> Milk
<li>Milk</li>
</ul>
<ol> 1. Coffee
<li>Coffee</li> 2. Milk
<li>Milk</li>
</ol>
<dl> Coffee
<dt>Coffee</dt> - black hot drink
<dd>- black hot drink</dd> Milk
<dt>Milk</dt> - white cold drink
<dd>- white cold drink</dd>
</dl>
When used together with CSS, the <div> element can be used to set style attributes to large blocks of
content.
Another common use of the <div> element, is for document layout. It replaces the "old way" of defining
layout using tables. Using tables is not the correct use of the <table> element. The purpose of the <table>
element is to display tabular data.
When used together with CSS, the <span> element can be used to set style attributes to parts of the text.
Tag Description
HTML Forms
HTML forms are used to pass data to a server. An HTML form can contain input elements like text fields,
checkboxes, radio-buttons, submit buttons and more. A form can also contain select lists, textarea,
fieldset, legend, and label elements.
<form>
.
input elements
.
</form>
Tasks:
Q2.Create students registration form with all concerned fields that are used by the university.
Q3. Implement the different types of lists used in html to obtain following on web browser.(hint: use all
three lists)
Learning outcomes: