How to set up a website

Contents  >

HTML Project: 1

Introduction

This is a responsive web page that features three levels of heading, images, background colours and highlighted <div> elements.

You can display a finished version of this project on GitHub by clicking the image below.

Project Setup

Contents

Project folder and files

Start your text editor

Start your web browser

Wrap the page in a <div>

Change the background colour of the page

Style the main heading

Style the sub-headings

Style the paragraph text

Style the bullet text

Add ‘alt’ text descriptions for images

Add the external hyperlinks

Style the introduction paragraph

Style the ‘What you will learn’ and ‘Note’ boxes

Update the meta tags

Update the Google Analytics ID

Update the privacy pop-up code and message

Validating your HTML file

Validating your CSS file

Uploading your project to GitHub

Project folders and files

Your first step is to download the files you need for this project.

  1. Download the following compressed file to your computer:  how-to-set-up-a-website.zip
  2. If a sub-folder named portfolio does not already exist inside your websites folder, create it now. file-explorer-portfolio-folder
  3. Uncompress the ZIP file into your websites/portfolio sub-folder as shown below. file-explorer-unzip-files

This will create a sub-folder named how-to-setup-a-website inside your portfolio folder.

file-explorer-portfolio-project-folder

The folders, sub-folders and files for this 'How to set up a website' project will be as shown below.

file-explorer-full

Start your text editor

Now you can begin to work with the files you have downloaded.

  1. In Visual Studio Code or other text editor, open the following two downloaded files. The first is the web page; the second, the stylesheet:
    • index.html: You will find this in the main folder of your how-to-setup-a-website folder.
    • how-to-setup-a-website.css: You will find this in the assets/css/ sub-folder of the how-to-setup-a-website folder.
vs-two-files

You can close any other files you may have open in your text editor.

Start your web browser

As you work with the HTML and CSS files, you will want to be able to display in your web browser the results of the changes you will be making.

  1. In File/Windows Explorer, go to your C:\\websites\portfolio\how-to-setup-a-website sub-folder. There you can see the index.html web page for this project.
  2. If your default web browser is Firefox Developer Edition or Google Chrome, double-click the index.html file to open it. file-explorer-double-click If not, right-click the index.html file and, from the pop-up menu displayed, choose Open with and then select either Firefox Developer Edition or Google Chrome to open the file. file-explorer-right-click

Wrap the page in a <div>

The first task is to create a <div> style that will ‘wrap’ the entire page. The CSS style rules of this <div> will add some white space around the page contents so that they do ‘bleed’ not against the edges of the web browser window.

  1. Display the stylesheet file how-to-set-up-a-website.css in your text editor.
  2. At the top of the file, you can see the following standard lines that are typically included in a CSS file.  
    
    /* ==== BROWSER RESETS  ==== */
    * { padding: 0; margin: 0; border: 0; box-sizing: border-box; font-weight: normal; font-size: 16px }
    body, html { height: 100% } 
    body { max-width: 1600px; margin: 0 auto }
    img { display: block; width: 100%; height: auto }
    
  3. Click with the mouse under these standard lines, press the Enter key a few times to add some blank lines to the CSS file. Then, paste in following into your CSS file.
    
    /* ==== PAGE WRAPPER  ==== */
    .page-wrapper { 
       margin-left: auto;
       margin-right: auto;
    }
    
    /* Mobiles */
    @media all and (max-width:767px) {
       .page-wrapper { width: 80%; margin-bottom: 10% }
    }
    
    /* Desktop */
    @media all and (min-width:768px) {
       .page-wrapper { width: 60%; margin-bottom: 5% }
    }
    
    When finished, save your CSS file
  4. Switch to your HTML file. Add the opening <div> with the class name page-wrapper just after the opening <body> tag. And add the closing </div> just before the Cookie Consnet JavaScript Code.
    
    <body>
    
    <div class="page-wrapper">
    
    
    
    </div>
    <!-- JavaScript for Cookie Consent Popup Message -->
    
    Save the index.html file in your web browser. It should look as shown below. How to set up a website

Change the background colour of the page

Let’s change the background colour of the entire web page.

  1. Display the stylesheet file how-to-set-up-a-website.css in your text editor.
  2. After the end of the /* === BROWSER RESETS === */ section at the top of the CSS file, and add the following new rule.  
    
     /* ==== BODY ==== */
     body { background-color: #f1efe9 }
    
  3. Save the CSS file and, in your web browser, view the effect on the HTML file. You should see that the background colour of the web page has changed from white to a light brown (#f1efe9).

Note that, in the CSS file, the word 'color' is written with US-style spelling: it is background-color not background-colour.

As an exercise, try setting these other values for the background-color property in your CSS file:

In each case, paste in the colour code such as #ff0d7b, save the CSS file and view the result in your web browser. When finished, set the background-color back to light brown (#f1efe9).

Style the main heading

Typically, every web page has one and only one <h1> heading. To style this main heading, set the font-family, font-weight and text-align as below. For an added effect, reduce the main heading's inter-character spacing by one pixel with the letter-spacing property.

  1. In the CSS file, under the /* === PAGE WRAPPER === */ section you previously entered, add some blank lines and then add the following.
    
    /* ==== MAIN HEADING  ==== */
    h1 {
       width: 90%;
       font-family: serif;
       font-weight: normal;
       text-align: center;
       font-size: calc(34px + (58 - 34) * ((100vw - 320px)/(1600 - 320)));
       letter-spacing: -1px;
    }
    
    These settings will always apply to the main heading, regardless of screen width.
  2. Next, set the properties of the main heading that will be different on desktop and mobile screens.
    
    /* Mobiles */
    @media all and (max-width:767px) {
       h1 { 
          line-height: 1.1;
          margin-top: 10%;
          margin-bottom: 10%;
          margin-left: auto;
       }
    }
    
    /* Desktop */
    @media all and (min-width:768px) {
       h1 { 
          line-height: 1.2;
          margin-top: 5%;
          margin-right: auto;
          margin-bottom: 5%;
          margin-left: auto;
       }
    }
    

For both the desktop and mobile versions, you can reduce the number of CSS lines required to set the margin properties and values.


 /* Mobiles */
      ...
      margin: 10% auto;

 /* Desktop */
      ...
      margin: 5% auto;

Style the sub-headings

There are three levels of sub-headings in your HTML file: <h2>, <h3> and <h4>. Let's style these now.

  1. In your CSS file, add this code after the styles you entered for the main <h1> heading in the previous step.
    
     /* ==== SUB HEADINGS ==== */
     h2, h3, h4 { font-family: sans-serif; font-weight: bold; line-height: 1.2 }
     h2 { letter-spacing: 1px; text-transform: uppercase }
    
     h2 { 
       font-size: calc(18px + (26 - 18) * ((100vw - 320px)/(1600 - 320)));
     }
    
     h3 { 
       font-size: calc(17px + (20 - 17) * ((100vw - 320px)/(1600 - 320)));
     }
    
     h4 { 
       font-size: calc(16px + (18 - 16) * ((100vw - 320px)/(1600 - 320)));
     }
    
  2. Next, add this code for the styles that depend on screen size.
    
     /* Mobiles */
     @media all and (max-width:767px) {
         h2 { margin-top: 12% }
         h3 { margin-top: 10% }
         h4 { margin-top: 8% }
     }
    
     /* Desktop */
     @media all and (min-width:768px) {
         h2 { margin-top: 6% }
         h3 { margin-top: 4% }
         h4 { margin-top: 2% }
     }
    
  3. Save your CSS file and, in your web browser, view the effect on your HTML file.

Note that the text-transform: uppercase property-value pair will cause the <h2> sub-heading to be always displayed in CAPITAL letters – regardless of the actual letter case of the text in the HTML file.

Style the paragraph text

In this step, you will set the properties of the paragraph or 'body' text of the web page.

  1. In your CSS file, set the font-family for paragraphs to sans-serif.
    • For mobiles, set the line-height to 1.4 and the margin-bottom to 5%.
    • For desktops, set the line-height to 1.6 and the margin-bottom to 3%.

    The relevant code is shown below.
    
     /* ==== PARAGRAPH TEXT ==== */
     p { 
       font-family: sans-serif;
       font-size: calc(15px + (18 - 15) * ((100vw - 320px)/(1600 - 320)));
     }
    
     /* Mobiles */
     @media all and (max-width:767px) {
        p { line-height: 1.4; margin-bottom: 5% }
     }
    
     /* Desktop */
     @media all and (min-width:768px) {
        p { line-height: 1.6; margin-bottom: 3% }
     }
    
  2. Save your CSS file and, in your web browser, view the effect on your HTML file.

Note that the line-height (inter-line spacing) for paragraphs of text is greater than the line-height for the main heading and sub-headings.

Style the bullet text

In this step, you will set the properties the text in bullet format on the web page.

  1. In your CSS file, set the font-family for bullet text to sans-serif.
    • For mobiles, set the line-height to 1.4 for individual bullets and their margin-bottom is 3%.
    • For desktops, set the line-height to 1.6 for individual bullets and their margin-bottom is 2%.

    The relevant code is shown below.
    
    /* ==== BULLETS ==== */
    
    ul li, ol li {
        font-family: sans-serif;
        font-weight: normal;
        font-size: calc(15px + (18 - 15) * ((100vw - 320px)/(1600 - 320)));
    }
    
    /* Mobiles */
    @media all and (max-width:767px) {
        ul, ol { margin-left: 5% }
        ul li, ol li {
           line-height: 1.4;
           margin-bottom: 3%;
        }
    }
     
    /* Desktop */
    @media all and (min-width:768px) {
        ul, ol { margin-left: 2% }
        ul li, ol li {
           line-height: 1.6;
           margin-bottom: 2%;
        }
    }
    
  2. Save your CSS file and, in your web browser, view the effect on your HTML file.

Note that:

Style the images and add a new one

All the required images have already been included in your HTML file – except the last one. Let’s add that now.

  1. Near the bottom of your HTML file, just after the paragraph that follows the <h3> sub-heading of Setting up your connection details, add this image code.
    
     <img src="assets/img/filezilla-account.png">
    
  2. Next, you need to add a new class to your CSS file so that every image will have some spacing under it.
    
     /* ==== IMAGES ==== */
    
     /* Mobiles */
     @media all and (max-width:767px) {
        img { margin-bottom: 6% }
     }
    
     /* Desktop */
     @media all and (min-width:768px) {
        img { margin-bottom: 2% }
     }
    
  3. Save both your HTML and CSS files. In your web browser, view the effect on your HTML file.

Add ‘alt’ text descriptions for images

If as the result of a slow connection or other reason, an image on a web page cannot be displayed, HTML offers an attribute called alt, a short form of 'alternative.' Use this to provide a short description of the undisplayed image. Let's add alt text for each of the ten images on your web page.

  1. In your HTML file, the first image is named private-registration.png. Add the following alt text value.
    
     <img src="assets/img/private-registration.png" alt="private registration">
    
  2. Add the following alt text descriptions for the remaining images.  ssl.png
    alt="SSL security certificate"  search-box.png
    alt="Choosing a domain name"  name-variations.png
    alt="Domain name variations"  hosting-options.png
    alt="Web hosting options"  cpanel.png
    alt="Web hosting control panel"  nameserver.png
    alt="Nameserver examples"  dns-copy.png
    alt="Connecting domain with web hosting"  filezilla-download.png
    alt="FileZilla FTP client"  filezilla-account.png
    alt="FileZilla site connection details"

Style the introduction paragraph

In this section, you will style the first paragraph of the web page that is located just under the main <h1> heading.

In your CSS file, you will create a new class named .box-introduction, and:

You can see the 'before' and 'after' appearance of the introduction block below.

How to set up a website 

Here are the steps:

  1. In the index.html file, wrap the first paragraph of text with a <div> block named box-introduction.
    
     <div class="box-introduction">
         <p>Follow the steps in this short guide to discover how you can purchase a domain name and a web host. You will also learn how to link your chosen domain with the web hosting 
         computer than stores your web pages.</p>
     </div>
    
  2. Switch to the CSS file and add the following two selectorsof code. The first will style the <div> text block as a whole by giving it a width, and a solid and coloured bottom border. The second is for the paragraph text within the <div> block.
    
     /* ==== DIV - INTRODUCTION ==== */
     .box-introduction { 
        width: 90%;
        border-bottom-style: solid;
        border-bottom-color: #dcd8cf;
        border-bottom-width: 12px
     }
    
     .box-introduction p { 
        font-size: calc(20px + (30 - 20) * ((100vw - 320px)/(1600 - 320)));
        line-height: 1.4; 
        font-family: serif; 
        font-style: italic; 
        text-align: center
     }
    
  3. Next, add the styles that will apply when your web page is viewed on desktop and mobile devices.
    
     /* Mobiles */
     @media all and (max-width:767px) {
         .box-introduction { 
             margin: 2% auto 16% auto;
             padding-bottom: 10px;
        }
     }
    
     /* Desktop */
     @media all and (min-width:768px) {
        .box-introduction { 
            margin: 2% auto 6% auto;
            padding-bottom: 2%;
        }
     }
    
  4. Save your CSS file and, in your web browser, view the effect on your HTML file.

Style the ‘What you will learn’ and ‘Note’ boxes

You will now style two blocks of text, one near the top and at second at the bottom of your HTML file. In each case, you will wrap them in a <div> with a class name of box-highlight.

How to set up a website 

Here are the steps:

  1. In the index.html file, wrap each <h4> sub-heading and the text that follows it with box-highlight class.
    
     <div class="box-highlight">
         <h4>What you will learn:</h4>
         <ul>
            <li>How to set up a domain name.</li>
            <li>How to create a web hosting account.</li>
            <li>How to connect your domain name to your web host.</li>
            <li>How to transfer files between your computer and your web host.</li>
         </ul>
     </div>
    
    
     <div class="box-highlight">
         <h4>Important Note</h4>
         <p>Commercial websites are included in this document as examples only. Mention of any one provider does not imply an endorsement or recommendation for the service sit offers.</p>
         <p>As with any purchasing decision, intending consumers of domain names and web hosting services should research the market carefully and choose the services that best meet their requirements and budget.</p>
     </div>
    
  2. Switch to the CSS file, create the .box-highlight selector and add the following style rules.
    
     /* ==== DIV - HIGHLIGHTED BLOCK ==== */
     .box-highlight { 
        background-color: #d4c6e6;
        margin: 5% 0;
        padding: 14px 20px;
     }
    
    Note the following:
    • You have given the boxes a background-color to highlight them.
    • You have used the margin property to create vertical spacing before and after the highlighted blocks.
    • You have used the padding property to create spacing within all four sides of the highlighted block. As a result, the text does not 'bleed' or spread all the way to the left and right and top and bottom edges of the block.
  3. Save your CSS file and, in your web browser, view your HTML file. For both the first and second highlighted blocks, you can see two spacing issues that need to be corrected. Powerpoint Project
    • There is too much vertical spacing at the top edge of the two blocks. This is because the <h4> sub-heading style has a margin-top spacing of 2% for desktops and 6% for mobiles. When you display the web page, the web browser calculates the total top edge spacing by adding the margin-top spacing of the h4 sub-heading to the padding-top value of the highlighted box.
    • There is too much vertical spacing at the bottom edge of the two blocks. This is because the <p>, <ul> and <li> selectors all have margin-bottom values. Again, the web browser is adding these values to the padding-bottom value of the surrounding box to calculate how much space it should display at the boxes' bottom edge.
  4. To fix these vertical spacing issues, add the following to your CSS file:
    
     .box-highlight h4 { margin-top: 0 }
     .box-highlight p:last-child { margin-bottom: 0 }
     .box-highlight ul { margin-bottom: 0 }
     .box-highlight ul li:last-child { margin-bottom: 0 }
    
    Note the following:
    • The h4 sub-heading has a margin-top of 0 whenever it is inside a .box-highlight block – but nowhere else. All other h4 sub-headings are unaffected.
    • A block of bullets created with the <ul> selector has a zero bottom margin whenever it is inside a .box-highlight block. Blocks of bullets located elsewhere on the web page are unaffected.
    • The :last-child attribute of the <p> and <li> tags means that the last bullet or last text paragraph within a .box-highlight will have a margin-bottom of 0.
    As a result of your changes, the top and bottom vertical spacing of .box-highlight is now set only by the padding-top and padding-bottom values of that selector.
  5. Save your CSS file and, in your web browser, view the effect on your HTML file. The two highlighted boxes should now look as shown below. Powerpoint Project

Update the meta tags

In the <head> of your index.html web page, within the <title> and <author> meta tags, you can see the name 'Mary Smith.'

Replace this with your own name, and save the index.html file.

vscode-meta-tags

Update the Google Analytics ID

Near the top of your HTML file, just before the closing </head> tag, you can see a sample Google Analytics Tracking Code.

vscode-ga

Each Google Tracking Code has a unique ID in its first and last line. Replace the sample Google Tracking ID with your own Google Tracking ID. The instructions for viewing your website’s unique Google Tracking ID are here.

When finished, save the index.html file.

Update the privacy pop-up code and message

You need to edit the ‘pop-up‘ privacy code and message in your web page.

  1. Within the <head> at the top of your index.html file, you can see a link to the stylesheet for the privacy pop-up message. You do not need to change this. vscode-privacy-head
  2. At the bottom of your web page, just before the closing </body> tag, you can see the JavaScript code for the privacy pop-up message. vscode-privacy-body Near the end of the lines of the JavaScript code, you can see the web address of the privacy page. Change the ibat-web-dev.github.io username to your username on GitHub.   You will create the actual privacy.html web page in a later project.
  3. When finished, save your index.html file.

The Privacy Code and Message

You can find the instructions for generating the JavaScript code here.

And here is a sample template file with the privacy message and code.

The web page looks 'empty'. Right-click anywhere on the page and choose View page source (Chrome or Mozilla Firefox).

Validate your HTML file

To check your HTML is correct, use the official W3C Markup Validation Service. Follow these steps.

  1. Go to this web page: https://validator.w3.org.
  2. Click the Validate by Direct Input tab. validate-html
  3. Copy and paste your HTML file into the box named Enter the Markup to validate.
  4. Click the Check button.
  5. If you see any errors, return to your index.html file, fix the errors, save the file, and copy the entire file again.  In the HTML Validator, click the Back button of your web browser to again display the Validate by Direct Input tab. Click once in the tab and paste in your corrected HTML file. Your new, pasted-in file will replace the earlier version. Finally, click the Check button.

Validate your CSS file

To check your CSS is correct, use the official W3C CSS Validation Service. Follow these steps.

  1. Go to this web page: https://jigsaw.w3.org/css-validator.
  2. Click the By direct input tab. validate-css
  3. Copy and paste your CSS file into the box named Enter the CSS you would like validated.
  4. Click the Check button.
  5. If you see any errors (other than those related to the fluid typographic equation, as shown below), return to your how-to-set-up-a-website.css file in your text editor, fix the errors, save the file, and copy the entire file again. typo-css-errors
  6. In the CSS Validator, click the Back button of your web browser to again display the By direct input tab. Click once in the tab and paste in your corrected CSS file. Your new, pasted-in file will replace the earlier version. Finally, click the Check button.

Upload your project to GitHub

The final step is to upload your project to GitHub.

All the files for this project are in a sub-folder named how-to-set-up-a-website of your websites/portfolio folder.

So you will need to upload this how-to-set-up-a-website sub-folder, which contains both files and other sub-folders, to your account on GitHub.

  1. Open a new tab in your web browser and go to GitHub.com. If you are not already signed in to your GitHub account, sign in now. github-signin
  2. On your GitHub home page, click the name of the repository ('repo') that holds your web pages. Its name will look as follows, where username is your chosen username on GitHub.   username.github.io   github-repo
  3. The next GitHub screen displayed should look as follows. Click on the portfolio folder. github-portfolio
  4. On the next screen displayed, click the Upload files button. github-upload-portfolio
  5. In File/Windows Explorer on your computer, display your portfolio folder and then drag-and-drop the how-to-set-up-a-website folder to the GitHub tab in your web browser. github-upload-drag-drop
  6. After uploading the how-to-set-up-a-website folder, scroll down to the bottom of the GitHub screen, enter a short message in the Commit changes box, click the Commit changes button, and wait for the upload to complete. github-upload-progress
  7. The portfolio folder of your website repo on GitHub should now contain a sub-folder named how-to-set-up-a-website. Click on this folder. github-uploaded-project
  8. The how-to-set-up-a-website folder should contain both the index.html file and the assets sub-folder. github-upload-portfolio-content
  9. Click on the assets sub-folder to view its contents. You should see that it contains the two sub-folders named css and img.
    • Within the assets sub-folder, click on the css sub-folder. Check that it contains the stylesheet file.
    • Within the assets sub-folder, click on the img sub-folder. Check that it contains all the image files.

Your web page is now published on GitHub at a web address similar to the following, where username is the username you have chosen for your GitHub account:

https://username.github.io/portfolio/how-to-set-up-a-website/index.html

or, simply:

https://username.github.io/portfolio/how-to-set-up-a-website

It may take a few minutes for your uploaded files to appear on GitHub.



Return to Contents.