We had concluded the previous section with the all pervasive tag: <HTML> </HTML>. This tag informs the reader (a browser or a word-processor, or anything that reads HTML) that the file being considered is a web page.
Let's see what step 4 has in store.
== Step 4: ==
Within <HTML> </HTML> tags, insert another tag so that your lines look like:
<HTML>
<HEAD>
</HEAD>
</HTML>
Within the head tag, we store all the information that we want the browser to read first before proceeding to read the rest of the stuff, for instance, the title of the page, information about the author, meta tags (some of the meta tags causes your page to be found when the user tries to find a page like yours, through his/her preferred search engine or directory, for instance, "Description" and "Keywords" meta tags), etc. For the time being, we'll have just the Title tag here, as right now we are in no hurry to be found by all and sundry.
Although it is not within the scope of this article to tutor you on how to be search engine friendly, it is recommended you choose the words of your title after careful scrutiny. Try to include in it the words that you think the surfer might type at the search engine prompt. The search engine guys recommend that if it is your company page, then put the name of your company there.
<HTML>
<HEAD>
<TITLE>This is my first, hand-coded HTML page</TITLE>
</HEAD>
</HTML>
If a tag is not going to contain many lines of code, we can have the opening and closing tags in the same line, for instance,
<TITLE>.....</TITLE>
instead of
<TITLE>
.....
</TITLE>
This applies to all the tags.
Clear till here? Now if you want to see how your page looks on your browser, load your browser, and in the URL window, type the complete path of your file, like
c:\newfolder\firstpage.html
and press Enter.
See nothing? Don't get alarmed, and don't think you've goofed up big somewhere. We haven't yet put anything in the code that should come up in the browser. Yes, on the browser's window title bar, you can view the text that you've put within <TITLE> </TITLE>.
From now onwards, leave your browser open, and keep pressing the Refresh or Reload button to see the changes, when you make them. Just remember to save the modified file [File -> Save: In the text editor] before refreshing.
== Step 5: ==
Now we come to the body of the page. Modify your page so that it looks like:
<HTML>
<HEAD>
<TITLE>This is my first, hand-coded HTML page</TITLE>
</HEAD>
<BODY>
</BODY>
</HTML>
<BODY> tag tells the browser that from now onwards, the actual content of the page will come into the picture.
We leave this section here because the last stage of our First Page course shouldn't have an abrupt break. In the concluding section we shall see how we can display simple text, hyperlinks and graphic files on our web page.
TEXT AND HYPERLINKS
In the preceding section, we had left the discussion at the <BODY> </BODY> tag, so let us continue from here.
For showing simple text, we use the <P> tag in such a manner:
<P>Ah! This is for the first time I'm writing my own HTML. The world is so different out here. Marvelous!</P>
You can consider <P></P> to be a paragraph.
OK, now the page should look like:
<HTML>
<HEAD>
<TITLE>This is my first, hand-coded HTML page</TITLE>
</HEAD>
<BODY>
<P>Ah! This is for the first time I'm writing my own HTML. The world is so different out here. Marvelous!</P>
</BODY>
</HTML>
Refresh the page. See something?
If you want to highlight a section, for instance, "Marvelous!", you can do it like this:
<P>Ah! This is for the first time I'm writing my own HTML. The world is so different out here. <B>Marvelous!</B></P>
Refresh the page. See something?
The use of some of the tags have been discontinued by some of the newer browsers, but we'll handle those complexities when we cover style sheets. At the moment, these should work.
The browser will show the text in the default font. If you want to use your own font, size and color, you'll have to use the font size for a particular portion of the text like this:
<P>Ah! This is for the first time <FONT SIZE="10pt" FACE="Verdana" COLOR="Red">I'm writing my own HTML</FONT>. The world is so different out here. <B>Marvelous!</B></P>
If you find it confusing, just type it as it is, save the file, and refresh the page in the browser, and you'll understand what I'm trying to say.
Notice the opening and closing tags everywhere? SIZE, FACE and COLOR are the main basic attributes of the <FONT> </FONT> tag.
== Step 6: ==
Let us now create a hyperlink and get over with the current article. A hyper link is the fancy text over which when you hover your cursor, the cursor metamorphoses into a pointing finger, indicating that you are going to be taken to some other web-destination upon clicking the left mouse button. A graphic can act as a hyper-link too, but we'll come to that later.
Suppose you want to add the following lines to the page:
<P>For more cool content, go to Bytesworth.com.</P>
So that the page looks like now:
<HTML>
<HEAD>
<TITLE>This is my first, hand-coded HTML page</TITLE>
</HEAD>
<BODY>
<P>Ah! This is for the first time <FONT SIZE="10pt" FACE="Verdana" COLOR="Red">I'm writing my own HTML</FONT>. The world is so different out here. <B>Marvelous!</B></P> <P>For more cool content, go to Bytesworth.com.</P>
</BODY>
</HTML>
Save and refresh the page. </P> also acts as a line break, so the next text appears like a new paragraph.
You want the message in such a way, that when someone clicks on Bytesworth.com, the person is taken to http://www.bytesworth.com. To accomplish this, you'll have to re-write the second paragraph like this:
<P>For more cool content, go to <A HREF="http://www.bytesworth.com"> Bytesworth.com </A>.</P>
exactly like this. Don't worry if the lines appear broken, you should write the entire thing in one line, as it is.
The latest page now is:
<HTML>
<HEAD>
<TITLE>This is my first, hand-coded HTML page</TITLE>
</HEAD>
<BODY>
<P>Ah! This is for the first time <FONT SIZE="10pt" FACE="Verdana" COLOR="Red">I'm writing my own HTML</FONT>. The world is so different out here. <B>Marvelous!</B></P> <P>For more cool content, go to <A HREF="http://www.bytesworth.com"> Bytesworth.com </A>.</P>
</BODY>
</HTML>
Save it, and refresh it. Bytesworth.com should appear as a hyperlink.
Don't get distraught by the drab look. If you follow all the articles, you'll be able to make the coolest pages possible in HTML/JavaScripts.
So this is your first, basic page. Using the given tags, you can keep adding further content according to how creative you feel. In the next article, we'll be discussing general layout, tables, and a couple of more tags.
IMAGES AS HYPERLINKS
In the preceding sections, you learnt how to come up with an elementary HTML page. You learnt the tags that are the backbone of an average HTML page, namely, <HTML> </HTML>, <HEAD> </HEAD>, <TITLE> </TITLE>, <BODY> </BODY>, <P> </P> and <A> </A>.
Assuming you could assimilate the gushing fountain of wisdom in the previous articles, we move onto the streams of more evolved tags. Let's start with graphics.
Graphics enhance the look of a page, they make it more informative [One picture is worth a thousand words, etc.], and they give your page an identity. But don't go over board - the total size of one page should not, ideally, exceed 25 KB. There are many other issues involved with web-based graphics, but at this moment, we are just covering the HTMLization of graphic files.
== Step 7: ==
To include graphics, we use the <IMG> tag in this manner:
<IMG SRC="picture.gif">
Where "picture.gif" is some graphic file that you already have in the same folder. If the graphic file is not present in the same folder as your HTML page, then you have to specify the entire path of the file being used. For example, if your HTML file is in the root directory, and "picture.gif" is in a sub-directory - graphics - of your root-directory, the syntax turns out to be:
<IMG SRC="graphics/picture.gif">
"/" (forward slash) is for servers. For your local hard-drive, you should use "\" (back slash).
SRC is an attribute of <IMG> and it stands for "source".
There are primarily two graphic file formats prevalent on the web, namely, GIF and JPG. GIF files use lesser colors, and hence are smaller in size and load quicker, and further, animated graphics can be created out of GIF files. JPG files are more refined, and we use them to display graphics that require clarity and greater pixel density, for instance, a photograph. More efficacious formats are being developed in the meantime to suit Internet compatibility.
In some tags, you don't have to use the closing tag. We don't use </IMG> with <IMG>, but with the advent of XML, closing tags are going to be compulsary.
Let us borrow the HTML code of our existing page, and in that, include the <IMG> tag too.
<HTML>
<HEAD>
<TITLE>This is my first, hand-coded HTML page</TITLE>
</HEAD>
<BODY>
<IMG SRC ="picture.gif">
<P>Ah! This is for the first time <FONT SIZE="10pt" FACE="Verdana" COLOR="Red">I'm writing my own HTML</FONT>. The world is so different out here. <B>Marvelous!</B></P> <P>For more cool content, go to <A HREF="http://www.bytesworth.com"> Bytesworth.com </A>.</P>
</BODY>
</HTML>
Save and refresh your page.
You might have observed that on many web pages, they use fancy graphics to show various links, as you can see the fancy gray buttons on this web site. We perform this by
<A HREF = "morelinks.html"><IMG SRC = "morelinks.gif"></A>
We have inserted the <IMG> tag between <A> </A>, so instead of the text link, now we have a graphic link.
Our modified HTML source page, looks like this (repetitive code has been replaced by dots):
<IMG SRC ="picture.gif">
<A HREF ="morelinks.html"><IMG SRC ="morelinks.gif"></A>
You can explore the <IMG> tag further on your own, but there is another crucial attribute of this tag that we are going to cover before moving on to the next section - the ALT attribute - alternative.
We use the ALT attribute inside <IMG> to insert text that gets displayed or sounded when the cursor is hovered over the image, or while the image is being loaded, or when the graphics display has been disabled in the browser, or when your site is being viewed on a non-graphics browser, or when visually challenged people are browsing on a voice-enabled browser.
<IMG SRC ="picture.gif" ALT ="Your Title in Text">
<A HREF ="morelinks.html"><IMG SRC ="morelinks.gif" ALT ="More Links"></A>
This sums up the <IMG> tag. It's an important tag, and hence, has taken up an entire chapter. You'll find yourself implementing it again and again, but please don't over-do it.
We move on to tables now.
HTML TABLES
Tables are used to display information in an orderly manner. Incidentally, here we are not talking furniture. A table means tabular representation of certain data on your computer screen or in printed form.
Ideally, a table consists of rows and columns. Mathematically, every table has at least one row, and at least one column.
In an empty square box, even if you don't see multiple vertical and horizontal lines, there is at least one row and at least one column.
So when we are defining a table, there are three tags that are deeply involved in the entire tabular configuration. The chief tag <TABLE> </TABLE> kindles the initiation. Then we have the child tag, namely, <TR> </TR> which brings on the row, and the last, but not the least, we have a grandchild tag here, <TD> </TD> which originates a column.
The legal sequence of these three tags goes like this:
<TABLE WIDTH="n%" BGCOLOR="some color" BORDER="n">
<TR>
<TD>
The information you want to show off about.
</TD>
</TR>
</TABLE>
Where n can be any positive number. Within every <TABLE> </TABLE>, there can be n numbers of <TR> </TR>, and within every <TR> </TR>, there can be n numbers of <TD> </TD>. Then you can have nested tables. For instance, within a single cell of nth row and mth column, you can have more tables.
Note: If the upper row has a single column, and the preceding one has multiple columns, its better to define the single-columned row in a separate table.
Let's promenade through a day-to-day example. Let us create a tiny table displaying your marks in English, Mathematics and Philosophy, in two semesters and see how it fairs on your upcoming web page. Don't get intimidated by so many tags and their attributes - once you are able to create and apprehend the architecture of one table, you'll be able to create any kind of table.
Note: Within <!-- and --> we can insert comments so that we can keep account of complex HTML coding. Literally, you insert the comments like this - Less-than sign, exclamation mark, dash dash, space, you comment, space, dash dash, greater-than sign.
The code:
<!-- The title table -->
<TABLE WIDTH="100%" BORDER="1">
<!-- The row begins here -->
<TR BGCOLOR="black">
<!-- Column -->
<TD WIDTH="100%" ALIGN="center"> <P><FONT COLOR="white"><B>My Marks</B></FONT></P> </TD>
<!-- Column ends -->
</TR>
<!-- Row ends -->
</TABLE>
<!-- The title table ends -->
<!-- The rest of the table starts here -->
<TABLE WIDTH="100%" BORDER="1">
<!-- First row -->
<TR BGCOLOR="silver">
<!-- First column -->
<TD WIDTH="25%"> </TD>
<!-- First column ends -->
<!-- Second column -->
<TD WIDTH="25%" ALIGN="center"> <FONT COLOR="black"><B>English</B></FONT> </TD>
<!-- Second column ends -->
<!-- And so on
-->
<TD WIDTH="25%" ALIGN="center"> <FONT COLOR="black"><B>Mathematics</B></FONT> </TD>
<TD WIDTH="25%" ALIGN="center"> <FONT COLOR="black"><B>Philosophy</B></FONT> </TD>
</TR>
<TR BGCOLOR="white">
<TD WIDTH="25%"> <FONT COLOR="black"><B>SEM1</B></FONT> </TD>
<TD WIDTH="25%" ALIGN="center"> <FONT COLOR="black"><B>72%</B></FONT> </TD>
<TD WIDTH="25%" ALIGN="center"> <FONT COLOR="black"><B>82%</B></FONT> </TD>
<TD WIDTH="25%" ALIGN="center"> <FONT COLOR="black"><B>60%</B></FONT> </TD>
</TR>
<TR BGCOLOR="white">
<TD WIDTH="25%"> <FONT COLOR="black"><B>SEM2</B></FONT> </TD>
<TD WIDTH="25%" ALIGN="center"> <FONT COLOR="black"><B>75%</B></FONT> </TD>
<TD WIDTH="25%" ALIGN="center"> <FONT COLOR="black"><B>78%</B></FONT> </TD>
<TD WIDTH="25%" ALIGN="center"> <FONT COLOR="black"><B>65%</B></FONT> </TD>
</TR>
</TABLE>
If you want to discern what these lines do, save, and refresh your page.
WIDTH="100%" means a particular table should cover the entire width of your computer screen, and a particular column should cover the entire width of the table containing it. <TD WIDTH="25%"> means the column is covering only 25% space of the stipulated table.
This raps up the table business. Make as many tables as you can as an exercise. The next section tells you something about the Style sheets and Server Side Includes.
CASCADING STYLE SHEETS
A few sections back, I had mentioned somewhere that some of the older HTML tags have been deprecated. This means the newer browsers refuse to recognize them. If you use these tags, the new browsers can mutilate your design in retaliation.
These tags have been deprecated to accommodate more devises that are vying to give net access to their users, for instance, WAP devices, televisions, etc.
One of the deprecated tags is, <FONT> </FONT>. We no longer use it. Another one I can remember is, <CENTER> </CENTER>. Both of them generate protests by advanced HTML editors.
So to render effects that were provided by such tags in the past, we have to use Cascading Style Sheets (CSS). A popular usage of Cascading Style Sheets is to give a consistent design look to a web site. Once you've designed certain styles, you can apply them on any part of your web site with just one tag. For example, supposing you have developed hundreds of pages using a particular CSS definition for a particular section, and all of a sudden you want to change the look of that section, you just have to redefine your CSS, and lo!, your entire web site gets upgraded.
A typical CSS definition is:
<STYLE type="text/css">
A {TEXT-DECORATION: none}
A:hover {TEXT-DECORATION: underline}
P {font: 10 pt Arial;
color: black;
line-height: 12 pt;
align: left}
</STYLE>
This definition appears in the <HEAD> </HEAD> section of the page where it is being applied.
For instance, in our First HTML page, this style would appear like this:
<HTML>
<HEAD>
<TITLE>This is my first, hand-coded HTML page</TITLE>
<STYLE type="text/css">
A {TEXT-DECORATION: none}
A:hover {TEXT-DECORATION: underline}
P {font: 10 pt Arial;
color: black;
line-height: 12 pt;
align: left}
</STYLE>
</HEAD>
<BODY>
You must be familiar with <A> </A> and <P> </P> tags. When we were investigating <A> </A>, we saw that the text that appears as a link in your browser is blue, and underlined.
But, if now we type
<P>For more cool content, go to <A HREF="http://www.bytesworth.com">Bytesworth.com</A>.</P>
The attribute A {TEXT-DECORATION: none} makes sure that you don't see that underline under "Bytesworth.com", and A:hover {TEXT-DECORATION: underline} makes the underline appear when you hover the cursor over this text.
If you want to define a paragraph-heading, do it like this:
<STYLE type="text/css">
H1 {14 pt Verdana;
color: maroon;
text-decoration: underline;
font-weight: bold}
</STYLE>
So now if you type:
<H1>Our monthly output</H1>
A CSS can be defined on the page itself, or as an external file. It is preferred that you define a Cascading Style Sheet as an external file if the definitions are lengthy and you are going to apply them on more than 10 pages so that you just have to mention the name of the CSS file in the <HEAD> </HEAD> section of every page.
To define an external CSS file, open a new file in your text editor, and type
P {
font-size : 10 pt;
font-family : Arial;
line-height : 12 pt;
}
A {
font-size : 10 pt;
font-family : Arial;
font-weight : bold;
color : Maroon;
text-decoration : none;
}
A:hover {
font-size : 10 pt;
font-family : Arial;
font-weight : bold;
color : Red;
text-decoration : underline;
}
Save the file as "mystyle.css". Remember to give a css extension.
Then within <HEAD> </HEAD> of the HTML page where you want the CSS to be applied, type this:
<LINK REL = STYLESHEET Type = "text/css" HREF = "mystyle.css">
Supply the complete path if the css file resides in some other folder. Save the HTML page and Refresh it.
This covers the basic concept behind Cascading Style Sheets.
There is a dilemma though. What if you want to have different CSS styles for the same tag for different sections? We'll ponder over it in the next section. And we'll cover some more formatting issues.
NAVIGATION BARS AND BULLETED LISTS