Chapter 2: Creating Your First Web Page
As I mentioned in Chapter 1, when someone tries to access your web site the web server will look in your *
public_html* sub-directory (folder) for a file called *
index.html*. This is known as the default home page file. On many systems the web server will also look for other files until it finds one (*
home.html* ). Check with your web server support for the name that your web server uses for the default home page. Note: The bscacad3.buffalostate.edu web server runs the UNIX operating system and so all file names are CASE SENSITIVE. I *STRONGLY* recommend that you always name files and directories (folder) using all lowercase letters and numbers with no spaces or other special characters except underscores (
_) and hyphens (
Basic HTML Tags
An HTML file is simply a text file that contains HTML tags that advise the browser how to render your web page. All HTML5 files should begin with the line:
The next line should contain an opening
HTML files have a certain "structure" to them. This structured document is divided into two parts, a HEAD (
</head> tags) and a BODY (
The last line in your HTML file should be your closing
Sample HTML file
A typical HTML file would look something like this:
The rendered web page would look like this:
</head> tags define an area of your web page used by the web browser to contain *metadata* (information about your web page).
Page Title: The
Normally the set of <title></title> tags is the first HTML in this area. The text inside the <title></title> tags is displayed by the web browser in the top bar (the blue bar in IE) and is used as the words for the users bookmark or favorite. Your <title> should be something that is related to that particular web page. For example:
<title>Jim Gerland’s Home Page</title>
Page Information: The
You can also have various <meta> tags within your <head> area that might include some keywords, the author, the character set used, or a description for your web page. These are used by search engines to index your page in their search database. For example:
External Files: The
Adding comments to your code can help you remember what your code is doing at that statement and will also help others who may need to maintain your code in the future. They are also handy for commenting out certain styles when you are developing your styles.
There are many instances where you might need to either make a comment about the code or "comment out" a section of code. The <!-- --> tag can be used for this. For example, you may want to include your name as a comment:
<!-- Author: Jim Gerland -->
Or, you may have some code, for example:
<h3>My heading level 3
That you don’t want to appear but you may want it later so you just "comment it out" like this:
<!-- h3>My heading level 3
Comments can appear in both the
Your web page can contain many more tags than the example above.
HTML tags are used to define the structure of your document. So, there are 6 heading levels tags. These tags do not need to be in any order and you do not need an
<h2> tag to have an
<h3> tag (and so forth). Though you are allowed to have more than one (1)
<h1> tag, a well-designed web page should only be one (1)
<h1> tag on each page. The web browser determines the look of each heading tag and should provide more emphasis for a lower numbered heading tag than a higher numbered heading tag. You can use CSS styles to modify the look of your heading tags.
Paragraphs and Line Breaks: The
</p>, tags define a section of your web page that appears to be a single set of words or sentences. The web browser is expected to put a blank line after each paragraph.
The break tag,
<br/>, advises the browser to end that line and start the next line without displaying a blank line.
HTML revolutionized the web with its ability to identify a word or phrase or image in such a way that it appeared on your web page as a click-able link that did something. This hyperlink could open a new page or go to a sub-section of the current page. It can even open a Word document, an Excel spreadsheet, or a PDF file. There are many other types of action for these links. You use the
<a> (anchor) tag to define your link and the href attribute to tell the web browser what you’d like to happen when someone clicks on that link. For example, if you wanted to display the words "Buffalo State College" as a link and have the UB web site open when that link is clicked then you would use this code:
Web pages can contain more than words and click-able links. If you want to include an image on your page you would use an
<img/> tag like this:
<img/> tag is "self-closing" since it places information in the document directly and does not surround (contain) any page information. The
<img/> tag has additional parts (attributes) that tell the browser where to get the image from (*
src=""*), what text to display when the user may have images turned off in their browser or the words to be read to the user if they are using a screen reader (*
You can even make an image click-able by nesting the
<img/> tag inside of an
<a> tag like this:
alt="Jim Gerland Photo" id="myPic"/> Jims web page
Ordered, Unordered, and Definition Lists: The
You can display different types of lists on your web pages using the
</dl> HTML tags.
You might use an ordered list if you have a series of steps. The web browser will automatically render an ordered list with increasing numbers. For example, a recipe:
If you wanted an unordered list, such as a shopping list, you would use something like this:
The browser will render an unordered list with bullets in front of each item in the list.
A definition list would be used if you want a glossary of terms. It might look like this:
The output would look like this:
You can even nest lists inside of lists. Remember to take care with your opening and closing list and item tags though.
There are tags (
</i>) that can be used to place emphasis (italics) on a word of phrase and tags (
</strong>) that can be used to bold a word or phrase. Later we will see how it would be better to use "CSS styles" to manipulate the look of your web pages.
Horizontal Rules: The
<hr/> tag can be used to place a line on your web page. Normally the browser will place a blank line before and after the horizontal line.
Task - Create Your First Web Page
For this task you will create a web page in your web server account called *
index.html* that will be used as the starting page for the rest of your tasks in this guide. Your web page should utilize the following HTML tags and include the following:
- Appropriate html, head, and title tags to give your page a title that contains your name.
<h1>tag that contains your name.
<img/>tag with appropriate src, alt, width, and height values that insert a graphic image on your page. It does not matter at this time what the graphic is as long as it is legal and moral.
<p>tag that encloses a brief paragraph about yourself.
<ol>tag that contains
<li>tags that list the remaining Assignments for this course (2, 3, 4, 5, 6, 7, 8, 9, and 10).
- At least one of each of these
Remember, whenever you login to your web server account you need to issue the command *cd public_html* to change to the sub-directory where you can create and maintain the files for your tasks.
You can use either the vi or Emacs editor while logged into your
bscacad3 account to maintain your files or you can edit them on your PC and use an SFTP client (FileZilla for Windows or Fetch for a Mac) to move them from your PC to your
bscacad3.buffalostate.edu account. For Windows it may be even better to use Notepad++ for your editor since it has a built-in SFTP client. For Mac the better choice is TextWrangler which also has a built-in SFTP client.