Guidelines for building your own website

Today we are going to set up a multi-page website using HTML and CSS. The website will have a navigation menu for switching between the different pages. Here is an example website to refer to:

Click here to open the example website

Use the example website as a guideline for laying out your website but do not copy it directly – instead build your own website about whatever topic you have picked to make a website about. You can use Trinket or Notepad or another text/code editor to write the code for your website.

Website file structure

You will see that the example website has 3 separate pages. The file names of these pages are index.html, about.html and contact.html. There is a stylesheet, style.css and an image folder containing all the images that appear on the pages. There is also a special icon image file, faveicon16.png, that is used as an icon for the website.

We will introduce some new HTML tags called semantic tags. In the past div tags were used to apply styling to different areas of the document but HTML5 introduced some new semantic tags that give the document structure more meaning. The semantic tags you will see in this example are:

  • <header> – this is used for the header of a web page or can be used for the header of a section within the web page
  • <nav> – this is used for marking up a navigation menu
  • <main> – this is used to mark up the main part of the web page
  • <footer> – this is used to mark up the web page footer or footer of a section within the web page

Web page layout

The example website uses a typical basic page layout:

You can use a similar layout for your website or you can adapt it to suit the needs of your website.

index.html – the website start page (home page)

Inside the <head>, you should have at least a <title> tag with the title of your website and a link tag that specifies the stylesheet document. In this example we also have a <link> tag that defines a website icon (you can see the website icon on the tab in the browser).

<!DOCTYPE html>
   <title>Sample HTML5 Layout</title>
   <link href="style.css" rel="stylesheet" />
   <link rel="icon" type="image/png" href="favicon16.png" sizes="16x16"> 

Inside the <body> tag we will use a <header> tag for the website header which in this case, contains the website logo and navigation menu. The navigation menu is contained inside <nav> tags and also uses an unordered list with each list item containing links to the pages of the website. Note that we have added a class called “current” to one of the links in the menu so that we can attach a special style to the menu item that is currently open.

      <div class="contents">
         <img id="logo" src="images/logo.png" width="200" height="200" alt="CoderDojo" title="CoderDojo">
               <li><a href="index.html" class="current">Home</a></li>
               <li><a href="about.html">About Us</a></li>
               <li><a href="contact.html">Contact Us</a></li>

Next we have a <main> tag that is used to contain the main content of the page. Note the src (source) attribute for the img (image) tags starts with “images/…” – this is because our images are in a folder called ‘images’. Also note the target="_blank" attributes in the links that go to external websites – this causes those links to open up in new tabs.

      <div class="contents">
         <img src="images/coderdojo-home.png" alt="CoderDojo - The global network of code clubs for kids">
         <h1>Welcome to CoderDojo Nelson</h1>
         <p><a href="" target="_blank">CoderDojo</a> is a worldwide network of independent, volunteer led programming clubs for young people. 
         CoderDojo Nelson meets at NMIT, Nelson on Wednesday evenings from 6:30 to 8pm. CoderDojo Nelson is also affiliated with <a href="" target="_blank">Code Club Aotearoa</a>.</p>
         <p><img class="aligncenter" src="images/photo1.jpg" alt="CoderDojo" width="640" height="480"></a></p>
         <h2>Some of the Technologies &amp; Learning Resources we use</h2>
         <a href="" target="_blank"><img src="images/code-logo.png" alt="" width="200" height="100"></a> 
         <a href="" target="_blank"><img src="images/Scratch_Logo.png" alt="Scratch" width="200" height="100"></a> 
         <a href=""><img src="images/google-cs-first.png" alt="Google CS First" width="200" height="100"></a> 
         <a href="" target="_blank"><img src="images/logo_codecademp.png" alt="Codecademy" width="200" height="100"></a> 
         <a href="" target="_blank"><img src="images/raspberry-logo.png" alt="Raspberry Pi" width="200" height="100"></a> 
         <a href="" target="_blank"><img src="images/logo-arduino.png" alt="Arduino" width="200" height="100"></a> 
         <a href="" target="_blank"><img src="images/Khan_Academy_logo.png" alt="Khan Aacademy" width="200" height="100"></a>


Finally we have a <footer> tag that is used to contain the website footer – just some copyright information in this example. Notice the code &copy; inside the footer. This is called a HTML entity and is a special code used to generate special characters, in this case a copyright symbol – ©. Some other examples of HTML entities are:

  • &amp; – ampersand (&)
  • &lt; – less than (<)
  • &trade; – trademark (™)
  • &frac14; – 1 quarter fraction (¼)

      Copyright &copy; 2017. All rights reserved.

style.css – Our website stylesheet

Now let’s review the CSS for this example website.

It is good practice to start our stylesheet with some comments:

   Example basic website for CoderDojo
   By Aidan Curran, CoderDojo Nelson

The main font we are using is applied to the body tag. We add some styling such as a background colour to our website header:

body {
   margin: 0;
   font-family: Arial, Helvetica, sans-serif;
header {
   padding: 10px;
   background-color: #7C10C2;
   border-bottom: 10px solid #FCA500;

Now we add styling for the navigation menu. Since the menu links are contained in an unordered list we have to make the list display in-line (instead of each item on a new line). We add some text colour, background colour and padding to make the menu links look like buttons. We use the .current class selector to make the current page item a different background colour and use the :hover selector to give the buttons a different colour when you hover over them with the mouse cursor.

nav {
   text-align: center;
nav ul li {
   display: inline; /* this puts the list items side by side instead of each on a new line */
   padding-left: 5px;
   padding-right: 5px;
   font-weight: bold;
nav ul li a {
   color: white;
   text-decoration: none; /* this removes the underline that usually appears under linked text */
   padding: 5px 20px;
nav ul li a.current { /* .current is a class selector that selects the a tags in the navigation menu with class="current" */
   background-color: #3FB842;
nav ul li a:hover { /* The :hover selector is used to select elements when you mouse over them */
   background-color: #0092D4;

Add some white space at the bottom of the page:

main {
   padding-bottom: 50px;

We are using a div tag with the class “contents” to control the width of the content. Setting the margin to auto on the right and left sides cause the div element to be centred.

div.contents {
   width: 80%;
   max-width: 1200px;
   margin: 0 auto;

This will prevent large images from extending outside the boundary of the page contents:

img {
   max-width: 100%;

Add some colour and spacing to our headings:

h1 {
   color: #7D10C2;
   margin-top: 40px;
h2 {
   color: #0092D4;

Some styling for our hr tags – horizontal rule (horizontal divider lines):

hr {
   border-bottom: 1px solid #0091D5; 
   margin: 50px 0;
   height: 0;
   color: transparent;

A few style rules for the website footer:

footer {
   border-top: 1px solid #FCA500;

Adding other pages to our website

You can copy the index.html file to use as a starting point to make your other pages. Just change the contents of the page and move the class=”current” to the menu link that matches the page.

Upload the website files to your hosting space

Once you have the website ready, upload the files to the hosting space that you set up last week. To do this, log in to your hosting control panel and go to the file manager.