Difference between revisions of "HTML:Start"

From mi-linux
Jump to navigationJump to search
(PSPad no longer installed in MI Complex)
 
(53 intermediate revisions by 8 users not shown)
Line 1: Line 1:
=='''HTML?'''==
+
[[Main Page]] >> [[4CC002|Website fundamentals]] >> [[4CC002Workbook|Workbook]] >> [[HTML]] >> Getting Started
  
The purpose of this workbook is to introduce you to the concepts used in creating web pages.  Many tools and techniques are used in the creation of web materials, but most advanced tools and techniques are based on the same fundamental method – Hyper Text Mark-up Language (HTML for short.)  Once you know the principles of HTML, you can go on to learn more advanced web development tools, understanding how they work behind the scenes.
+
[[Category:HTML]]
 +
==First thoughts==
 +
The key to understanding HTML is in understanding that you're not creating web pages.  You are almost creating a database.
  
HTML is a formatting language (sometimes referred to as a programming language, although this is a misconception) used to create a variety of web material, and is very easy to use.
+
With HTML you initially define the content of the page, not how the page looks.  You define the paragraphs, the headings, the labels, the images, and so on - the content of the page, but you do not refer to the presentation of this content.
  
=='''HTML Editors'''==
+
Imagine it like this.  If you wanted to create a database of all the customers for an organisation, you would be interested in defining customer names, their addresses, their orders, their contact details, and so on.  Later, you decide you want to produce a nice looking customer list, with all the customer names down the left hand side in bold, their addresses as a bullet point list, the primary contact in a red box.
  
In order to create a HTML file, all that you need is the simplest software tool available to any computer user – a text editorAny text editor can be used, but for the purpose of this course, I will use the NOTEPAD text editor available on any version of Microsoft Windows.
+
What you should hopefully realise is that with computers involved, there is no need to create the customer list again in a prettier format.  You only need to provide instructions on how the information should look when it's printedThat's the relationship between HTML and CSS. HTML is the database-side of things, defining the information you want to presentCSS are the instructions that control how to present the information you have defined.
WHY? Notepad is the standard text editor distributed with any version of Microsoft WindowsIt is installed by default with any Windows installation, and is very easy to use.
 
  
====UPDATED FOR VERSION 2.0====
+
Now, here's the tricky bit.
It has now been decided that [http://www.pspad.com PSPad] (freely available [http://www.pspad.com www.pspad.com]) is the preferred text editor for the module.  It must be stressed that [http://www.pspad.com PSPad] is still just a text editor (with more useful functions) and for the purpose of this workbook, Notepad is still a perfectly adequate substitute.  No aspects of this workbook require you to use any features not available in Notepad. You can install a cutdown version of PSPad in your My Documents directory to use on university computers by following instructions here -> [[PSPad - download and install instructions]]
 
  
=='''Saving Your Work'''==
+
As web users, when we look at a page, we don't separate the content from the presentation in our minds.  We see the whole thing together.  When we write HTML and CSS, we tend to dip in and out of each language, not see them in isolation.  For example, for the first few exercises, I'll be discussing layouts, content and presentation interchangeably, because that's what you're most likely to be familiar with.
  
In order to create web pages using this workbook, you will need somewhere to store them.  The best place to store them is in "My Documents" – if you wish to work on your website from any university computer, "My Documents" will be available.  If you wish to transport your work home, I would recommend the purchase of a small USB data storage device (AKA a USB Pen/Key Drive), so that you can transport your work with you, and amend it whatever computer you are using.
+
OK - let's get started.
  
=='''Your First Webpage'''==
+
== The Tools ==
  
Follow the steps shown below to create your first page.
+
In order to learn HTML and CSS from scratch, the best possible tools to use are the simple text editors
Start PSPad – in the new file dialog box, choose "HTML document" and click OK.  If you are not shown the dialog, go to the "File" menu, and click "New File…"
 
 
Make sure that the content of the new file is exactly as shown at the top of the next page.  PSPad may fill in some of this for you, but you’ll need to fill in what it does not.
 
  
<nowiki>
+
* Notepad / [http://www.pspad.com/ PSPad] / [http://notepad-plus.sourceforge.net/uk/site.htm Notepad++] on Windows OS's
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+
* [G/K/X (depending on your Graphical Environment)]Edit, Kate, Mousepad, Leafpad, Nano, Vim or similar on Linux.
  
 +
If you are using this wiki for a module that Alix Bergeret leads, you '''WILL NOT BE PERMITTED''' to develop your HTML/CSS in anything other than a simple text editor. The use of tools such as Dreamweaver, Frontpage, Expression, NVU, BLUFISH, and similar are strictly forbidden. There is a very good reason for this. Most IDEs such as the list above complete code for you - that's their primary purpose, to reduce development time by completing parts of the development for you. When you're an experienced developer, this is great, and saves time and effort. When you're a novice, this is very bad, as you don't learn the aspects that the IDE does for you, so your knowledge has big gaps.
 +
 +
==Exercise 1 - The first experiment==
 +
 +
Let's take a look at a typical webpage - <b>YOU DON'T HAVE TO CREATE THIS YET, JUST UNDERSTAND WHAT YOU'RE READING</b> - you'll have the chance to start building in chapter 3:
 +
 +
<nowiki><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 
  <HTML>
 
  <HTML>
 
   <HEAD>
 
   <HEAD>
       <TITLE>
+
       <TITLE>My first HTML document</TITLE>
        My first HTML document
 
      </TITLE>
 
 
   </HEAD>
 
   </HEAD>
 
   <BODY>
 
   <BODY>
       <P>
+
       <P>Hello world!</P>
        Hello World!
 
      </P>
 
 
   </BODY>
 
   </BODY>
 
  </HTML></nowiki>
 
  </HTML></nowiki>
  
 +
==Exercise 1 - Breakdown==
 +
===Line 1 - <nowiki><!DOCTYPE...</nowiki>===
 +
Probably the most important line in this example is the one that starts <nowiki><!DOCTYPE...</nowiki>
 +
 +
When this page is downloaded into a browser or any other client application, this line tells the application what language the document is written in and also what DTD to use to decode and display the contents.
  
Click on Save (in the File Menu) and save the file somewhere in the "My Documents" folder, with a meaningful name, such as first.htm
+
====What is a DTD?====
Open up the "My Documents" folder on your desktop, and double-click the first.htm file to open in.
+
A DTD is a Document Type Definition - it contains all the rules and valid uses of each element within your HTML.
Congratulations, you’ve just created and viewed your first web page.
 
  
=='''Your First Webpage – Debrief'''==
+
===Line 2 - <nowiki><HTML></nowiki>===
 +
Following the DTD, every HTML page begins with <nowiki><HTML></nowiki>.  This is called the 'HTML element start tag'.  Put simply, this defines the beginning of the web page.  It states that everything following this tag, until it's end-tag (<nowiki></HTML></nowiki>) is the webpage.
  
Let’s examine the contents of the first.htm file to understand what the commands mean.
+
=== Line 3 - <nowiki>&lt;HEAD&gt;</nowiki> ===
  
<nowiki><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"></nowiki>
+
The <nowiki>&lt;HEAD&gt;</nowiki> start-tag defines the heading section of the web page. The heading section IS NOT SHOWN ON THE PAGE. This is tricky to come to terms with at first. The heading of a web page in HTML is not the top of the visible screen, the way the heading of a document normally would be. The heading of a web page is a place to typically change settings affecting the way the web page is displayed. This is the place where scripting languages like JavaScript would exist in a web page, as users would not want to see the JavaScript code, they would only want to see the output of what JavaScript can accomplish. The thing to remember, is that content in this section is not shown on a web page (sort of!)
  
At the start of every HTML file you must include this statement.  Automated testing tools used to verify web pages use this line to understand what version of HTML the document is written in.  This must be exact – no missing spaces or symbols.  Although the contents of the blue box above are shown on two lines due to the width of this page, the contents can be on one line – a space should be typed between the …//EN" and "http: parts of the statement.
+
===Line 4 - <nowiki><TITLE>...</nowiki>===
 +
The <nowiki><TITLE></nowiki> of a web page is not shown in the pageThe title is shown in the address bar at the top of the browser window.  It is the name that is used when book-marking a page, in the history, on the start/task bar if you have one on your computer.  It is not shown anywhere in the body of the web page.
  
<nowiki><HTML></nowiki>
+
===Line 5 - <nowiki></HEAD></nowiki>===
 +
<nowiki></HEAD></nowiki> defines the end of the HEAD section of a web page.  The thing to notice is the '''/''' symbol before the word HEAD.  Every / symbol followed by an element name is the end of that instance of that element.
  
This statement identifies the start of the Hypertext Mark-up Language section of the document.
+
===Line 6 - <nowiki><BODY></nowiki>===
 +
<nowiki><BODY></nowiki> defines the beginning of the main visible part of the webpage.  Everything that follows (with some minor exceptions) from this point until the end of the body section (<nowiki></BODY></nowiki>) is designed to be visible content of the webpage, like menus, and colour, and images, and so on.
  
  <nowiki><HEAD></nowiki>
+
===Line 7 - <nowiki><P>...</nowiki>===
 +
This is the only visible element of the web page.  The <nowiki><P></nowiki> defines the beginning of an instance of a ''paragraph'' element.  The text that follows (Hello World!) is the content of that paragraph.  The <nowiki></P></nowiki> defines the end of the paragraph (note the '''/''').  Pay careful attention to the fact that we have not defined a font, or a size, or a colour, or any other visible attributes of the paragraph.  We have merely defined the fact that we want a paragraph, and we have defined it's content.
  
HTML documents are broadly split into two sections – the header section and the main body.  The header section contains commands that are not visible in the main content of the web page, but control other aspects, such as some aspects of the appearance of the web page.  A HTML document must contain both a header and a main body section.
+
===Line 8 - <nowiki></BODY></nowiki>===
Note: notice how the <HEAD> line is indented from the line before.  Indenting is a useful programming standard used to better format the content of HTML, make the code easier to read, and to quickly find sections when errors need to be corrected.  You should adopt this convention of indenting in your coding – if you are following this workbook as part of a course, you will no doubt be assessed on the quality of your code at some point.
+
<nowiki></BODY></nowiki> defines the end of the main visible body of the webpage.
  
      <nowiki><TITLE>My first HTML document</TITLE></nowiki>
+
===Line 9 - <nowiki></HTML></nowiki>===
 +
<nowiki></HTML></nowiki> defines the end of the webpage.
  
This line controls the title of the documentThe title is presented both in the Title Bar of the browser (Internet Explorer, etc.) window and also in the Taskbar at the bottom of the Windows XP screenIt is useful to give documents meaningful titles so that they are easily identified when the desktop has lots of open windows.
+
==Thinking in boxes==
Note: notice how the <TITLE> line is indented with the <BODY> section
+
If you look again at the structure of this webpage, you'll realise that we define a series of elements that exist inside other elementsThis "element within element" concept is called "nesting."  In order to write correct HTML, that will work as we expect it to, it is critical that we get the nesting aspect of the page rightThe best way to describe this is to think about a series of boxes within boxes.
  
  <nowiki></HEAD></nowiki>
+
[[Image:HTMLBoxes2.png]]
  
This line identifies that we have completed the header section of our document.
+
Box number 1 is our paragraph - we put a label on it (P) and inside we put some text (Hello World!) then we close the box.
  
<nowiki><BODY><P>Hello World!</P></BODY></nowiki>
+
Box number 2 is our body part of our webpage - we put a label on it (BODY) in it we put all the items we want to be visible on our web page, in the right order (in this case just the (P) box)
  
This line identifies that we are beginning the main body of the document, followed by the content of the page, followed by the end of the main body of the web page.
+
Box number 3 is our title - we put a label on it (TITLE) and put the title of the page (My First HTML Document) inside the box.
  
<nowiki></HTML></nowiki>
+
Box number 4 is our heading section - we put a label on it (HEAD) and put all the non-visible items we want into it in the right order (in this case, just the (TITLE))
  
This line identifies the end of the HTML document.
+
Box number 5 is our web page as a whole - we put a label on it (HTML) and also stamp it with the language it was written in (DOCTYPE...)
  
 +
Boxes within boxes...
  
==Ready for the next part?==
+
=Ready to Move on?=
 +
When you're absolutely confident you understand this section of the wiki, you can carry on to section [[HTML:Basics]] - do not continue to [[HTML:Basics]] if you are unsure about any of this content - you should seek assistance from your tutor if anything is unclear.
  
When you fully understand everything on this page, try moving on to [[02 - The Basics of HTML 4.01 ]]
+
=Related Pages=
 +
<categorytree mode=pages>HTML</categorytree>

Latest revision as of 15:00, 12 July 2011

Main Page >> Website fundamentals >> Workbook >> HTML >> Getting Started

First thoughts

The key to understanding HTML is in understanding that you're not creating web pages. You are almost creating a database.

With HTML you initially define the content of the page, not how the page looks. You define the paragraphs, the headings, the labels, the images, and so on - the content of the page, but you do not refer to the presentation of this content.

Imagine it like this. If you wanted to create a database of all the customers for an organisation, you would be interested in defining customer names, their addresses, their orders, their contact details, and so on. Later, you decide you want to produce a nice looking customer list, with all the customer names down the left hand side in bold, their addresses as a bullet point list, the primary contact in a red box.

What you should hopefully realise is that with computers involved, there is no need to create the customer list again in a prettier format. You only need to provide instructions on how the information should look when it's printed. That's the relationship between HTML and CSS. HTML is the database-side of things, defining the information you want to present. CSS are the instructions that control how to present the information you have defined.

Now, here's the tricky bit.

As web users, when we look at a page, we don't separate the content from the presentation in our minds. We see the whole thing together. When we write HTML and CSS, we tend to dip in and out of each language, not see them in isolation. For example, for the first few exercises, I'll be discussing layouts, content and presentation interchangeably, because that's what you're most likely to be familiar with.

OK - let's get started.

The Tools

In order to learn HTML and CSS from scratch, the best possible tools to use are the simple text editors

  • Notepad / PSPad / Notepad++ on Windows OS's
  • [G/K/X (depending on your Graphical Environment)]Edit, Kate, Mousepad, Leafpad, Nano, Vim or similar on Linux.

If you are using this wiki for a module that Alix Bergeret leads, you WILL NOT BE PERMITTED to develop your HTML/CSS in anything other than a simple text editor. The use of tools such as Dreamweaver, Frontpage, Expression, NVU, BLUFISH, and similar are strictly forbidden. There is a very good reason for this. Most IDEs such as the list above complete code for you - that's their primary purpose, to reduce development time by completing parts of the development for you. When you're an experienced developer, this is great, and saves time and effort. When you're a novice, this is very bad, as you don't learn the aspects that the IDE does for you, so your knowledge has big gaps.

Exercise 1 - The first experiment

Let's take a look at a typical webpage - YOU DON'T HAVE TO CREATE THIS YET, JUST UNDERSTAND WHAT YOU'RE READING - you'll have the chance to start building in chapter 3:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
 <HTML>
   <HEAD>
      <TITLE>My first HTML document</TITLE>
   </HEAD>
   <BODY>
      <P>Hello world!</P>
   </BODY>
 </HTML>

Exercise 1 - Breakdown

Line 1 - <!DOCTYPE...

Probably the most important line in this example is the one that starts <!DOCTYPE...

When this page is downloaded into a browser or any other client application, this line tells the application what language the document is written in and also what DTD to use to decode and display the contents.

What is a DTD?

A DTD is a Document Type Definition - it contains all the rules and valid uses of each element within your HTML.

Line 2 - <HTML>

Following the DTD, every HTML page begins with <HTML>. This is called the 'HTML element start tag'. Put simply, this defines the beginning of the web page. It states that everything following this tag, until it's end-tag (</HTML>) is the webpage.

Line 3 - <HEAD>

The <HEAD> start-tag defines the heading section of the web page. The heading section IS NOT SHOWN ON THE PAGE. This is tricky to come to terms with at first. The heading of a web page in HTML is not the top of the visible screen, the way the heading of a document normally would be. The heading of a web page is a place to typically change settings affecting the way the web page is displayed. This is the place where scripting languages like JavaScript would exist in a web page, as users would not want to see the JavaScript code, they would only want to see the output of what JavaScript can accomplish. The thing to remember, is that content in this section is not shown on a web page (sort of!)

Line 4 - <TITLE>...

The <TITLE> of a web page is not shown in the page. The title is shown in the address bar at the top of the browser window. It is the name that is used when book-marking a page, in the history, on the start/task bar if you have one on your computer. It is not shown anywhere in the body of the web page.

Line 5 - </HEAD>

</HEAD> defines the end of the HEAD section of a web page. The thing to notice is the / symbol before the word HEAD. Every / symbol followed by an element name is the end of that instance of that element.

Line 6 - <BODY>

<BODY> defines the beginning of the main visible part of the webpage. Everything that follows (with some minor exceptions) from this point until the end of the body section (</BODY>) is designed to be visible content of the webpage, like menus, and colour, and images, and so on.

Line 7 - <P>...

This is the only visible element of the web page. The <P> defines the beginning of an instance of a paragraph element. The text that follows (Hello World!) is the content of that paragraph. The </P> defines the end of the paragraph (note the /). Pay careful attention to the fact that we have not defined a font, or a size, or a colour, or any other visible attributes of the paragraph. We have merely defined the fact that we want a paragraph, and we have defined it's content.

Line 8 - </BODY>

</BODY> defines the end of the main visible body of the webpage.

Line 9 - </HTML>

</HTML> defines the end of the webpage.

Thinking in boxes

If you look again at the structure of this webpage, you'll realise that we define a series of elements that exist inside other elements. This "element within element" concept is called "nesting." In order to write correct HTML, that will work as we expect it to, it is critical that we get the nesting aspect of the page right. The best way to describe this is to think about a series of boxes within boxes.

HTMLBoxes2.png

Box number 1 is our paragraph - we put a label on it (P) and inside we put some text (Hello World!) then we close the box.

Box number 2 is our body part of our webpage - we put a label on it (BODY) in it we put all the items we want to be visible on our web page, in the right order (in this case just the (P) box)

Box number 3 is our title - we put a label on it (TITLE) and put the title of the page (My First HTML Document) inside the box.

Box number 4 is our heading section - we put a label on it (HEAD) and put all the non-visible items we want into it in the right order (in this case, just the (TITLE))

Box number 5 is our web page as a whole - we put a label on it (HTML) and also stamp it with the language it was written in (DOCTYPE...)

Boxes within boxes...

Ready to Move on?

When you're absolutely confident you understand this section of the wiki, you can carry on to section HTML:Basics - do not continue to HTML:Basics if you are unsure about any of this content - you should seek assistance from your tutor if anything is unclear.

Related Pages

<categorytree mode=pages>HTML</categorytree>