Contents  >

Colours and Web Design

IBAT Next Course

Learning Goals

At the end of this Tutorial you will be able to:

You can view a finished version of this project by clicking the image below.

GitHub image

Contents

About colours in web design

The colour name system

The RGB colour system

The hex code colour system

Your two work files: base-7.html and base-7.css

Adding text and background colours to the four <div> boxes

Identifying colours with web browser DevTools

Updating the <head> of your web page

Validating your stylesheet

Uploading your two files to GitHub

Further resources

About colours in web design

Colours provide web pages with interest and personality. One way to add colour to a web page is to include images.

You can see from the examples below how the same image but with different dominant colours affects the impact of a web page.

Colours and Web Design

Many research studies have shown that colour choice in design influences user psychology and behaviour. For example:

At the end of this Tutorial is a list of resources you may find helpful when choosing website colours.

Colours: three CSS properties

This Tutorial will focus on adding colours to a web page by setting values for the following three CSS properties. Note the US-style spelling in each case.


   color: /* Insert colour value here */;
   background-color: /* Insert colour value here */;
   border-color: /* Insert colour value here */;

In the example below, you can see the text elements <h2> and <p> both have a color of dark blue. They are positioned in a <div> with a class name of "container-box" that has a background-color of light pink.

Colours and Web Design

  .container-box { background-color: #fef1ef }
  .container-box h2, 
  .container-box p { color: #1e266d }

And here are some examples of the border-color property in use along with text color and background-color properties.

Colours and Web Design

In web design, there are three common systems for setting colours:

The next three sections of this Tutorial will explain each colour system in detail.

The colour name system

Simply typing a colour name – such ‘red’ or ‘blue’ (without quotes) – in a CSS rule is a common starting point when designing a new web page.


  h1 { color: red }

Many colour names are both easy-to-remember and self-explanatory. For example, ‘yellow’, ‘purple’ and so on. Other colour names are less obvious, such as ‘hotpink’, ‘mediumvioletred’ and ‘lavenderblush’.

Colour names are not case-sensitive. For example, these three versions of the same colour name are all valid.


  h3 { color: DarkOrchid }
  h3 { color: darkorchid }
  h3 { color: DARKORCHID }

You can see a full list of colour names on this W3 Schools web page.

However, the final version of a web page will typically use either RGB values or hex codes rather colour names for the following two reasons:

Note that, in CSS, the colour name of grey can be written in either US spelling (gray) or UK spelling (grey). Either will work correctly.

The RGB colour system

The RGB system is based on the following idea:

Any colour can be created by combining different intensities of the three primary colours: red, green and blue.

Here are a few points about the Red-Green-Blue colour system:

The following examples of CSS rules show the RGB system used to create the three colours of blue, a light brown and magenta.


  h1 { color: rgb(0,0,255) /* blue */}
  h2 { color: rgb(255,248,220) /* light brown */ }
  h3 { color: rgb(255,0,255) /* magenta */  }

The hex code colour system

This is the colour system most widely used in web design. As with the RGB system, the displayed colour is created by combining different intensities of red, green and blue. But the hex (short for hexadecimal) code system is different in four ways:

Here are the three colours of blue, light brown and magenta written as hex codes in CSS rules.


  h1 { color: #0000FF /* blue */ }
  h2 { color: #FFF5DC /* light brown */ }
  h3 { color: #FF00FF /* magenta */ }

Like colour names, hex codes are not case-sensitive. For example, both #0000ff and #0000FF are valid and display the colour blue.

Understanding the hex code system

A hex colour code may look like a random jumble of numbers and letters. Given that this system is so widely-used in web design, however, it is worth taking a few moments to understand how this colour system works.

Here are the main points to note:

So, in the hex colour code system:

Three-digit, short-hand hex codes

Not every hex colour code needs to be written as a string of six digits. You write some hex colours in three-digit shorthand.

Consider the example of the colour white. In CSS, you can write this in two ways:

#FFFFFF

-or-

#FFF

The general rule is as follows:

If any of the three pairs in a six-digit hex code is a duplicate, you need only write that hex digit once.

You can see some more examples of three-digit hex codes below.

Colours and Web Design

For every colour above, three pairs of duplicate hex digits (such as 00, 33 or FF) are shortened into one digit.

Your two work files: base-7.html and base-7.css

In this Tutorial you will work with these two files:

First, let’s edit the HTML file from your previous Tutorial:

  1. In your text editor, open the file named base-6.html.
  2. In the <head> of the base-6.html file, change the title as follows:  
    
    <title>Responsive web page with colour text boxes</title>
    
  3. Also in the <head>, change the description as follows:  
    
    <meta name="description" content="A sample responsive web page with examples of text in colour boxes.">
    
  4. Also in <head>, change the stylesheet link as follows:  
    	
      <link rel="stylesheet" href="base-7.css">
    
  5. Use the File | Save As command to save your HTML file with the following new name:   base-7.html
  6. Switch to the base-6.css file, and use the File | Save As command to save the file with this new name:   base-7.css

You are now ready to work with your new web page (base-7.html) and stylesheet (base-7.css).

Adding text and background colours to the four <div> boxes

In the base-7.html web page are four text boxes created by <div> tags as shown below. And for each <div> are three related styles in the base-7.css file.

Tutorial RWD: Media Queries

Let᾿s add some CSS colour rules for the first of the four <div> elements.

  1. In your text editor, switch to the base-7.css stylesheet file.
  2. To the .important-note-1 selector, add the following two new style rules:
    
     .important-note-1 {
        ...
        border-color: #1FA441;
        background-color: #E4F5E8;
      }
    
  3. To the .important-note-1 h3 and .important-note-1 p selectors, add these new style rules:
    
     .important-note-1 h3 {
        ...
        color: #1FA441;
      }
    
     .important-note-1 p {
        ...
        color: #000;
      }
    
  4. Save the CSS file, and view your base-7.html web page in your web browser. You should see that the first of the four text boxes has been updated with your new colour style rules. Tutorial RWD: Media Queries

Now, let’s move one to the second of the four text boxes.

  1. To the .important-note-2 selector, add the following two new style rules:
    
     .important-note-2 {
        ...
        border-top-color: #044E6C;
        border-bottom-color: #044E6C;
      }
    
  2. To the .important-note-2 h3 and .important-note-2 p selectors, add these new style rules:
    
     .important-note-2 h3 {
        ...
        color: #044E6C;
      }
    
     .important-note-2 p {
        ...
        color: #044E6C;
      }
    
  3. Save the CSS file, and view your base-7.html web page in your web browser. The second of the four text boxes should now look as shown below. Tutorial RWD: Media Queries

Next, let’s add some colours to the third text box.

  1. To the .important-note-3 selector, add the following two new style rules:
    
     .important-note-3 {
        ...
        border-left-color: #E66465;
        background-color: #FFE7E8;
      }
    
    You need not make any changes to the sub-heading and paragraph text for the third text box.
  2. Save the CSS file, and view your base-7.html web page in your web browser. Text box number three should now look similar to that below. Tutorial RWD: Media Queries

Lastly, let’s update the colours of the fourth text box.

  1. To the .important-note-4 selector, add the following two new style rules:
    
     .important-note-4 {
        ...
        border-color: #2c4763;
        background-color: #1f364d;
      }
    
  2. To the .important-note-4 h3 and .important-note-4 p selectors, add these new style rules:
    
     .important-note-4 h3 {
        ...
        color: #9cb3c9;
      }
    
     .important-note-4 p {
        ...
        color: #fff;
      }
    
  3. Save the CSS file, and view your base-7.html web page in your web browser. The fourth text boxes should now look as shown below. Tutorial RWD: Media Queries

Identifying colours with web browser DevTools

You can use the DevTools feature of web browsers to identify the colour of text and backgrounds on a web page. For example, use your web browser to visit the following website:

https://www.citizensinformation.ie

To use the DevTools of the Google Chrome browser:

  1. Press F12 to display the Chrome DevTools window.   You may find it easier to use this option with the DevTools area positioned (docked) at the bottom of the web browser window. Tutorial RWD: Media Queries
  2. Click the Select arrow at the top-left of the Chrome DevTools window. Tutorial RWD: Media Queries
  3. Click on the header of the web page with the blue background. Chrome DevTools surrounds the header with a colour border. Tutorial RWD: Media Queries In the Chrome DevTools window, you can see the Elements panel at the left and the Styles sub-panel at the right. Tutorial RWD: Media Queries In the Styles sub-panel, you can see the text and background colour values of the selected web page element.

To use the DevTools of the Mozilla Firefox browser:

  1. From the Tools menu, choose the Web Developer command and then Inspector.   You may find it easier to use this option with the DevTools area positioned (docked) at the bottom of the web browser window. Tutorial RWD: Media Queries
  2. Click the Inspect arrow at the top-left of the Firefox DevTools window. Tutorial RWD: Media Queries
  3. Click on the header of the web page with the blue background. Firefox DevTools surrounds the header with a blue, dashed-line border. Tutorial RWD: Media Queries In the centre panel of the Firefox DevTools window, you can see the text and background colour values of the selected web page element. Tutorial RWD: Media Queries

In both Chrome and Firefox DevTools windows, you can edit the CSS colour or other values of any selected web page element.

Here are a few resources to learn more about DevTools:

Updating the <head> of your web page

Before you validate your web page and upload it to GitHub, ensure the following details are correct within the <head> of your base-7.html file.

GitHub image

Validating your web page

To check the HTML in your web page is correct or valid, use the official W3C Markup Validation Service as follows.

  1. Go to this web page: https://validator.w3.org.
  2. Click the Validate by Direct Input tab. Colours and Web Design
  3. Select your entire HTML file (both <head> and <body>), and copy-and-paste it into the box named Enter the Markup to validate. Colours and Web Design
  4. Click the Check button.
  5. If you see any errors, return to your base-7.html file in your text editor, fix the errors, save the file, and copy-and-paste 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.

Validating your stylesheet

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. Colours and Web Design
  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 base-7.css file in your text editor, fix the errors, save the file, and copy the entire file again. Tutorial RWD: Media Queries
  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.

Uploading your two files to GitHub

After validating your web page and stylesheet, you are now ready to upload them to your account on GitHub.

  1. Sign in to your account at GitHub.com. At the left of the screen, you can see a list of your repositories. Colours and Web Design
  2. On your GitHub home page, click the name of the repository that holds your web pages. Its name will look as follows, where username is your chosen username on GitHub.   username.github.io   Colours and Web Design
  3. On the next screen displayed, near the centre of the screen, click the Upload button. Colours and Web Design
  4. Select or drag-and-drop the two files base-7.html and base-7.css to upload them to your GitHub account. Colours and Web Design
  5. After uploading your files, scroll down to the bottom of the screen, enter a short message in the Commit changes box and click the Commit changes button.

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/base-7.html

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

Further resources

Colour psychology 101: How colour affects perception of your website
By Safa Khudeira at the Intechnic Blog

How to use the psychology of colour to increase website conversions
By Neil Patel at the Neil Patel Blog

Understanding colour psychology for impactful web design
By Jerry Cao at DesignModo

The psychology of colour in web design
By Jenni McKinnon at the Envato Blog

A quick guide to website photography
By Eric Karkovack at the Speckyboy



Return to Contents.