unit-i HTML
unit-i HTML
HTML stands for Hypertext Markup Language, and it is the most widely used language to write Web
Pages. As its name suggests, HTML is a markup language.
Hypertext refers to the way in which Web pages (HTML documents) are linked together. When you click a
link in a Web page, you are using hypertext.
Markup Language describes how HTML works. With a markup language, you simply "mark up" a text
document with tags that tell a Web browser how to structure it to display.
Follow the 4 steps below to create your first web page with Notepad.
To start Notepad
When you save an HTML file, you can use either the .htm or the .html file extension. Save the file in a
folder that is easy to remember.
Start your web browser (e.g. Microsoft Internet Explorer) and open your html file from the File, Open
menu, or just browse the folder and double-click your HTML file.
An HTML document
starts and ends with <html> and </html> tags. These tags tell the browser that the entire document is
composed in HTML. Inside these two tags, the document is split into two sections:
The <head>...</head> elements, which contain information about the document such as title of the
document, author of the document etc. Information inside this tag does not display outside.
The <body>...</body> elements, which contain the real content of the document that you see on your
screen.
A good way to learn HTML is to look at how other people have coded their html pages.
Department of Computer Engineering Page 2
Subject Name: Static Webpage Design Unit No: I Subject Code: 4311603
To find out, simply click on the View option in your browsers toolbar and select Source or Page Source.
This will open a window that shows you the actual HTML of the page. Go ahead and view the source html
for this page.
HTML Versions
Since the early days of the web, there have been many versions of HTML:
Version Year
HTML 1991
HTML+ 1993
HTML5 2012
XHTML5 2013
HTML Tags
Logical tags are designed to describe (to the browser) the enclosed text's meaning.
An example of a logical tag is the <strong> </strong> tag. By default all browsers make the text appear bold
when in between the <strong> and </strong> tags.
Physical tags on the other hand provide specific instructions on how to display the text they enclose.
Examples of physical tags include:
<b>: Makes the text bold.
<big>: Makes the text usually one size bigger than what's around it.
<i>: Makes text italic.
HTML Elements
<html>
<head>
<title>My First Webpage</title>
</head>
<body>
This is my first homepage.
<b>This text is bold</b>
</body>
</html>
<body>
This is my first homepage. <b>This text is bold</b>
</body>
This HTML element starts with the start tag <body>, and ends with the end tag </body>. The purpose of the
<body> tag is to define the HTML element that contains the body of the HTML document.
Nested Tags
You may have noticed in the example above, the <body> tag also contains other tags, like the <b> tab.
When you enclose an element in with multiple tags, the last tag opened should be the first tag closed.
Example:
<p>
Tag Attributes
Tags can have attributes. Attributes can provide additional information about the HTML elements on your
page.
The <tag> tells the browser to do something, while the attribute tells the browser how to do it.
For instance, if we add the bgcolor attribute, we can tell the browser that the background color of your page
should be blue, like this: <body bgcolor="blue">.
This tag defines an HTML table: <table>. With an added border attribute, you can tell the browser that the
table should have no borders: <table border="0">.
Attributes are always added to the start tag of an HTML element and the value is surrounded by quotes.
Headings are defined with the <h1> to <h6> tags. <h1> defines the largest heading while <h6> defines the
smallest.
<h1>This is a heading 1</h1>
<h2>This is a heading 2</h2>
<h3>This is a heading 3</h3>
<h4>This is a heading 4</h4>
Paragraphs
Paragraphs are defined with the <p> tag. Think of a paragraph as a block of text. You can use the align
attribute with a paragraph tag as well.
<p align="left">This is a paragraph</p>
<p align="center">this is another paragraph</p>
Line Breaks
The <br> is used to break the lines.
Horizontal Rule
The <hr> element is used for horizontal rules that act as dividers between sections, like this:
The horizontal rule does not have a closing tag. It takes attributes such as align and width.
Comments in HTML
The comment tag is used to insert a comment in the HTML source code. A comment can be placed
anywhere in the document and the browser will ignore everything inside the brackets. You can use
comments to write notes to yourself, or write a helpful message to someone looking at your source code.
Example:
HTML Fonts
The <font> tag in HTML is deprecated. The World Wide Web Consortium (W3C) has removed the <font>
tag from its recommendations. In future versions of HTML, style sheets (CSS) will be used to define the
layout and display properties of HTML elements.
HTML Backgrounds
Backgrounds
The <body> tag has two attributes where you can specify backgrounds. The background can be a color or an
image.
Bgcolor
The bgcolor attribute specifies a background-color for an HTML page. The value of this attribute can be a
hexadecimal number, an RGB value, or a color name:
<body bgcolor="#000000"> OR
<body bgcolor="rgb(0,0,0)"> OR
<body bgcolor="black">
The lines above all set the background-color to black.
Background
The background attribute can also specify a background-image for an HTML page.
The value of this attribute is the URL of the image you want to use.
<body background="clouds.gif">
<body background="http://myfolder/clouds.gif">
The URL can be relative (as in the first line above) or absolute (as in the second line above).
<html>
<head>
<title>My First Webpage</title>
</head>
<body background="http://myfolder/clouds.gif" bgcolor="#EDDD9E">
<h1 align="center">My First Webpage</h1>
<p>Welcome to my <strong>first</strong> webpage. I am writing this page using a text editor
and plain old html.</p>
<p>By learning html, I'll be able to create webpages like a <del>beginner</del>
programmer....<br> </p>
</body>
</html>
HTML Links
HTML uses the <a> anchor tag to create a link to another document or web page.
An anchor can point to any resource on the Web: an HTML page, an image, a sound file, a movie, etc. The
syntax of creating an anchor:
The <a> tag is used to create an anchor to link from, the href attribute is used to tell the address of the
document or page we are linking to, and the words between the open and close of the anchor tag will be
displayed as a hyperlink.
With the target attribute, you can define where the linked document will be opened. By default, the link will
open in the current window. The code below will open the document in a new browser window:
Email Links
To create an email link, you will use mailto: plus your email address. Here is a link to ACC's Help Desk:
To add a subject for the email message, you would add ?subject= after the email address. For example:
Department of Computer Engineering Page 8
Subject Name: Static Webpage Design Unit No: I Subject Code: 4311603
To link directly to the top section, add a # sign and the name of the anchor to the end of a URL, like this:
HTML Images
The <img> tag is empty, which means that it contains attributes only and it 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 on your page. The syntax of
defining an image:
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).
The letters td stands for table data, which is the content of a data cell.
A data cell can contain text, images, lists, paragraphs, forms, horizontal rules, tables, etc
<table>
<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>
Department of Computer Engineering Page 9
Subject Name: Static Webpage Design Unit No: I Subject Code: 4311603
</tr>
</table>
To display a table with borders, you will use the border attribute.
<table border="1">
Headings in a Table
<table border="1">
<tr>
<th>Heading</th>
<th>Another Heading</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>
The <table> tag has two attributes known as cellspacing and cellpadding.
Here is a table example without these properties.
These properties may be used separately or together.
Cellspacing is the pixel width between the individual data cells in the table (The thickness of the
lines making the table grid).
The default is zero.
If the border is set at 0, the cellspacing lines will be invisible.
<tr>
<td>some text</td>
<td>some text</td>
</tr>
</table>
Table Tags
Tag Description
<table> Defines a table
<th> Defines a table header
<tr> Defines a table row
<td> Defines a table cell
<caption> Defines a table caption
<colgroup> Defines groups of table columns
<col> Defines the attribute values for one or more columns in a table
Marquee
</marquee>
width: how wide the marquee is. This will have a value like 10 or 20%etc.
height: how tall the marquee is. This will have a value like 10 or 20% etc.
direction: which direction the marquee should scroll. This will have value either up, down, left or right.
behavior: what type of scrolling. This will have value scroll, slid and alternate.
loop: how many times to loop. The default value is INFINITE, which means that the marquee loops
endlessly.
bgcolor: background color. This will have any color name or color hex value.
hspace: horizontal space around the marquee. This will have a value like 10 or 20%etc.
vspace: vertical space around the marquee. This will have a value like 10 or 20%etc.
Examples:
Adding Audio:
HTML5 provides a quick and easy way to add audio and video files to be played on a website. Using the
audio element an audio clip can be added to a page. Just as with the img element, an audio element also
needs a source URL specified via the src attribute.
<audio src="images-audio-video/jazz.ogg"></audio>
Adding Video:
Adding in HTML videos is very similar to that of adding in audio. In this case however, we use the video
element in place of the audio element.