Tag Archives: webpage

Using CSS to style your webpage

CSS stands for Cascading Style Sheets and is a style sheet language that is used to describe the look and style of web pages. CSS can be used to create a theme by modifying the layout, colours, and fonts.

Without any special styling or formatting, the web pages that we create don’t look very exciting. That’s where CSS comes in! We can use CSS to change the colour of text and backgrounds, use different font styles, and change the layout and overall theme of our site. This tutorial explains how to use CSS in a webpage.

There are three different ways of applying CSS:

  • Inline styling – the style attribute is applied within the HTML tag
  • Internal style sheet – style attributes are applied to selectors inside the head section of a webpage
  • External style sheets – style attributes are applied in a separate CSS file that can be used across a website

Below is an example of how to use inline styling within a HTML tag:

Inline styling
Inline styling

Below is an example of how to place the styling within the style tag inside the head section of a webpage:

Adding CSS using the style tag in the head section.
Adding CSS using the style tag in the head section.

This video tutorial will focus on using inline styling and internal style sheets. The next tutorial will explain how to use external style sheets. Watch the video below to see how to use CSS and then scroll down to see the sample code.

The sample code below shows how to use inline styling:

<!DOCTYPE html>
<html>
<head>
 <title>Adding CSS to a webpage</title>
 <meta charset="utf-8"/>
</head>

<body>
 <h1 style="color:red">This heading is red.</h1>
 <h2 style="color: #FE2EF7; border: solid 1px">This heading is pink with a border</h2>
 <p style="color:blue">This text is blue.</p>
 <p style="color:green; background-color: yellow">This text is green on a yellow background</p>
</body>

</html>

The sample code below shows how to use an internal style sheet:

<!DOCTYPE html>
<html>
<head>
 <title>Adding CSS to a webpage using internal stylesheets</title>
 <meta charset="utf-8"/>
 <style type="text/css">
 p{
 color:blue;
 }
 </style>
</head>

<body>
 <p>This is a paragraph of text. Because a style has been applied using the p selector, this paragraph will be blue.</p>
</body>

</html>

Tip:

The sample code for inline styling uses the HTML colour code #FE2EF7 for the colour pink. You can use the names of colours  for basic colours such as ‘blue’ or ‘red’ but for other specific colours you will need to use the HTML colour code (a combination of letters and numbers after a hashtag). You don’t need to remember all the colour codes but it is good to remember  #000000 for black and #FFFFFF for white. You can see all the colour codes here.

Adding video to a webpage

This video tutorial explains how to add a video to your webpage using the HTML5 video tag. With the HTML5 video tag, you can specify the height, width, source, and type of video file(s) you are working with as well as adding controls, autoplay, and loop features.

When adding videos, you will need to consider browser compatibility. The following browser accept these videos using the HTML5 video tag (this could change):

  • Internet Explorer: MP4
  • Chrome: MP4, WebM, Ogg
  • Firefox: MP4, WebM, Ogg
  • Safari: MP4
  • Opera: MP4, WebM, Ogg

The safest bet is to use MP4 but it is a good idea to provide multiple file types. Keep in mind that the autoplay feature is currently not supported in Safari or Opera browsers and does not work on mobile devices such as the iPad or iPhone (this could also change).

When you add a video to your page you can specify the width and height, if you would like to auto-play the video, loop the video and if you would like to show or hide the video player controls. The video player controls look like this in Chrome browser:

Watch the video below and then scroll down to view the sample code.

The sample code below shows how to use the video tag. You might want to remove the autoplay, loop or controls attributes as they are all enabled in the example below. You will also need to change the width and height to suit your video.

<!DOCTYPE html>
<html>
<head>
 <title>Adding video to a webpage</title>
 <meta charset="utf-8"/>
</head>

<body>
 <video width="550" height="400" controls autoplay loop>
 <source src="your_video_file.mp4" type="video/mp4"/>
 Your browser doesn't support the HTML video tag. Consider upgrading to a newer browser.
 </video>
</body>

</html>

Adding audio to a webpage

This tutorial explains how to add audio to a webpage using the HTML5 audio tag. Because this tag is new to HTML5, it may not be supported in some older browsers. It is also important to note that some audio file types may not be supported in different browsers.

At the time of writing this tutorial, the following browsers support these file types using the HTML5 audio tag:

  • Chrome: MP3, WAV, OGG
  • Internet Explorer: MP3
  • Firefox: MP3, WAV, OGG
  • Safari: MP3, WAV
  • Opera: MP3, WAV, OGG

Using MP3 files for audio would be the safest bet as it is supported by all the major browsers now. For this tutorial, I will demonstrate using the HTML5 audio tag with an MP3 file. You can get free audio files from a range of sources including the YouTube Audio Library and Freesound.

When you add audio to a page you can specify whether you want to allow the audio to automatically play, loop over, and if you also want to show or hide the audio player controls which will look like this:

audioplayer

The video below shows how you can use the HTML5 audio tag to add an audio file to a webpage. It also shows how to add controls and how to autoplay and loop audio files. Watch the video below and then scroll down to see the sample code.

The sample code below shows how to add an audio file to a webpage. All you need to do is replace the filename/filetypes with whatever you are using. You might also like to remove the autoplay, loop, or control features. Note that all three of these features are enabled in the example below.

<!DOCTYPE html>
<html>
<head>
 <title>Adding audio to a webpage</title>
 <meta charset="utf-8"/>
</head>

<body>
<audio controls autoplay loop>
 <source src="your_audio_file.mp3" type="audio/mpeg"/>
 Your browser does not support the HTML5 audio tag. Consider updating to a newer browser.
</audio>
</body>

</html>

This tutorial video includes a portion of free music from the YouTube Audio Library. Music from the audio library can be used in your videos by you as long as you do not make it available, distribute or perform the music separately from your videos into which you have incorporated the music files, and as long as the music is not used in an illegal manner or in connection with any illegal content. Always read the terms and conditions.

Adding images to a webpage

This tutorial explains how to add images to your web pages using the HTML <img> tag. You can specify a number of attributes for an image including the following:

  • src – specifies the location or path of the image
  • width – specifies the width of the image
  • height – specifies the height of the image
  • alt – specifies alternative text to be displayed in case the image cannot load.

The structure of an <img> tag may be set out like the one below:

Here are a few important things to note:

  • You should aways use alt text in case the image cannot be loaded in the user’s browser

    This is what alt text looks like when an image can’t load:
    alttextAlt text often also shows up after a few seconds when the user hovers their mouse over an image.

  • The path and filename of the image specified in the src tag in your code must be exactly the same as the actual file
  • You should specify the width and height of the image so the correct space is set aside even if the image can’t be loaded
  • You can change the width/height of an image to make it smaller. However, it is a good idea to make the image the correct size in the first place to reduce the time it takes to download the image

Watch the video below to see how to use the <img> tag in your own web page and then scroll down to see the sample code.

This sample code shows how to add an image to a webpage. Copy this code into a new HTML file. Modify the width and height of the image in the code to suit your own image file and experiment with different size images.

<!DOCTYPE html>
<html>
<head>
 <title>My webpage</title>
 <meta charset="utf-8"/>
</head>
<body>
<img src="batman.png" alt="Batman" width="400" height="400"/>

<!-- Make sure you include the full file path of an image if it is located in a different folder eg. folder2/batman.png 
-->
</body>
</html>

How to make an image a link

If you want to make an image a link so that when the user clicks on image they are taken to another page, you can just place the image tag inside the link tag (instead of text for the link). As an example, the following code would take the user to ‘other_page.html’ when they click on the image which has the file name ‘your_image.png‘:

<a href="other_page.html"><img src="your_image.png"/></a>

After watching the video, answer the following questions for discussion before the next lesson:

  1. Which unit of measurement is used to specify the width/height of an image in the code? How could the use of this unit affect the way images are displayed on screens of different sizes?
  2. Are there any other units of measurement that can be used?
  3. What could cause an image to fail to load in a user’s browser?
  4. Why is it important to use images with smaller file sizes?
  5. What issues need to be considered before including images on a web page?
  6. Evaluate the effectiveness of using images to convey large amounts of information on a web page.

Now create your own web page using several of your own images combined with text. You can use the sample code above to get started.

Once you are ready to move on, click here to find out how to add audio to your web pages.

Creating lists in HTML

There are two different types of lists we will look at in this tutorial. The first type is an unordered list (bullet list) which is used to list items in no particular order. A bullet list is a dot-point list but you can customise the style of the list to use squares or arrows instead of dots, for example. The second type of list is an ordered list (numbered list) which uses numbers to order items in a list.

An unordered list looks like this:

Ordered list
Unordered list

An ordered list looks like this:

Ordered list
Ordered list

Unordered list items go between the <ul> and </ul> tags in the body section of your webpage. Ordered list items go between the <ol> and </ol> tags on your webpage. Each list item is surrounded by the <li> and </li> tags (you can use <li> in both unordered and ordered lists). Watch the video below and then scroll down to see the code. If you’d like to find out how to style lists with CSS code, you should check out the list styling tutorial.

The sample code below shows how to create ordered lists and unordered lists:

<!DOCTYPE html>
<html>
<head>
 <title>Lists</title>
 <meta charset="utf-8"/>
</head>

<body>
 <h3>My bullet list:</h3>
 <ul>
 <li>List item 1</li>
 <li>List item 2</li>
 <li>List item 3</li>
 </ul>
 <h3>My numbered list:</h3>
 <ol>
 <li>List item 1</li>
 <li>List item 2</li>
 <li>List item 3</li>
 </ol>

</body>

</html>

HTML Formatting

You can use a range of tags in HTML to format text on your webpage. This tutorial covers the following HTML formatting tags:

      • <strong> is used for bold text
      • <b> is also used for bold text
      • <em> is used for italicised text
      • <i> is also used for italicised text
      • <u> is used for underlined text
      • <del> is used for deleted text
      • <sub> is used for subscripted text
      • <sup> is used for superscripted text
      • <mark> is used for marked/highlighted text
      • <hr/> is used for a horizontal rule (line) as seen below

The video below shows how to use these tags and also how to write comments inside your code that aren’t displayed on the webpage by the browser. Comments which are only visible in your code are written inside the <!– and –> tags.

Watch the video below and then scroll down to see the sample code and find out what each line of code does.

The code below shows how to use these different HTML formatting tags.

<!DOCTYPE html>
<html>
<head>
 <title>HTML Formatting</title>
 <meta charset="utf-8"/>
</head>

<body>
<p>This is a paragraph of plain text.</p>
<hr/>
<p>This is <strong>bold</strong> text and this is <em>italicised</em> text.</p>
<p>This is <u>underlined</u> text</p>
<p>This is <del>deleted</del> text and this is <mark>highlighted</mark> text.</p>
<p>This is <sub>subscripted</sub> text and this is <sup>superscripted</sup> text.</p>
<!-- this is a comment -->
</body>

</html>

A comment is not actually displayed in the web browser. It is hidden and only visible inside your code. You can use comments to include the author of the code and date it was created. You can also use it to make notes on code that needs to be changed or what different bits of code are used for.

The code from above would display the following content in your web browser (note that the comment is not visible):

HTML formatting
HTML formatting

The difference between the <strong> and <b> tags

The <strong> tag is a part of HTML5. The <b> tag has been around for a very long time. The <em> tag is also a HTML5 tag, whereas the <i> tag has been around for a long time. In most browsers, it will appear that <strong> and <b> both do the same thing – they make text bold. And it may also appear that <em> and <i> do the same thing – they italicise text. However, there is a difference.

The <b> tag is a style. It describes how the text it surrounds should be displayed. The <strong> tag is indication of how something should be understood. It describes the text it surrounds. (eg. this text should be stronger than the rest of the text you’ve displayed).

Paragraphs, line breaks and headings in HTML

In this tutorial we will look at some HTML tags that you can use to place text inside your webpage. All of these tags are used in the <body> section of the webpage. The following HTML tags (also known as elements) are discussed in this tutorial:

  • The <p> tag is for paragraphs
  • The <br/> tag is for line breaks
  • The <h1> to <h6> tags are used for different size headings

Watch the video below or scroll down to read the instructions on how to create paragraphs, line breaks, and headings.

The paragraph tag

The first tag we will use is the <p> tag to create a paragraph. Paragraph text goes between the <p> and </p> tags. Paragraphs are separated by a space.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Paragraph example</title>
</head>

<body>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
</body>

</html>

The HTML code above would tell you web browser to display two paragraphs like this:

Two paragraphs
Two paragraphs

The line break tag

To put text in your webpage you don’t even need to use a <p> tag. You can actually just type the text straight in. However, if you add new lines for text inside your HTML document, it won’t actually show a new line in the web browser – all your text will be on one line. If you want to create a new line, then use the line break <br/> tag. This tag will create a new line where the text will continue on.

Use the code below to see how the <br/> tag adds a new line. Two things to note: The <br/> tag is a single tag so it does not require an opening and close tag combination. The <br/> tag does not add spacing between lines like the paragraph tag does.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Line break example</title>
</head>
<body>
This is a line of text.<br/>This is another line of text.
</body>
</html>

You can see the difference between using line breaks and paragraphs below. Note that there is no spacing between the text that uses a line break, but there is space between the paragraphs.

Using line breaks
Using line breaks

The heading tags

There are a number of different tags you can use to create a heading because there are a number of different heading sizes. The largest heading size tag is <h1> and the smallest is <h6>. For example, if you want to create a large heading then you would place the text inside the <h1> and </h1> tags.

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Headings examples</title>
</head>
<body>
<h1>This is the largest heading</h1>
<h2>This is a large heading
<h3>This is a medium heading</h3>
<h4>This is a small heading</h4>
<h5>This is a smaller heading</h5>
<h6>This is the smallest heading</h6>
</body>
</html>

This is what the different size headings would look like:

Headings of different sizes
Headings of different sizes

Getting started with HTML5 and CSS3

HTML (HyperText Markup Language) is the markup language that is used to create web pages. It is written using HTML elements, also known as tags. These tags are enclosed in angle brackets. Tags often come in pairs such as <p> and </p> but this is not always the case as some tags are unpaired, for example <br/>.

Web browsers such as Google Chrome, Internet Explorer, Safari or Firefox are able to read HTML files and display them as web pages on your screen. The tags tell the web browser what to display in the browser and how to display it. HTML files end in the .html file extension and can be edited in any text editing program.

HTML is the basic building block of all web pages but most websites today don’t just use standalone HTML. Web pages can be supported by CSS (Cascading Style Sheets) which define the look and layout of text and other elements on multiple pages, and other scripts written in languages such as JavaScript which can control how a web page behaves.

This tutorial is the first in the HTML5 and CSS3 video tutorial series. These videos will show you everything you need to begin creating your own website.

To begin writing the code for your own webpages you will need to download and install a good text editor for coding. The good news is that there are plenty of free text editors that can do this well. Here is a list of good text editors you can use to write your code:

I often choose to use Sublime Text or Atom on Mac (and you’ll see this in screenshots throughout this tutorial series) but you can choose any program you like – they are all fairly similar to use.

All of the main code editors are very easy to use. Basically you open a new file, save it as a file which ends in .html and then type in your code. You can usually see all your folders and files listed in the side as well.

Here is a screenshot of the Atom code editor. showing a list of folders on the left and the code on the right. You can work on multiple files in different tabs and also see the line numbers for your code next to each line of code.

atomdemo

Once you have dowloaded your HTML text editor, install and run it. Create a new file and save it as index.html – make sure that the file type is set to HTML (HyperText Markup Language). Your homepage should always be saved as index.html – by using the name index it will be recognised as the homepage in. You can name your other pages whatever you like eg. about.html or contactus.html – but it is good practice to not use spaces in your filenames.

Watch the video below to see how to build your very first web page and then scroll down to see the code and find out what is happening on each line of code.

Take a look at the sample HTML code below and then scroll down to find out what each line of code does.

<!DOCTYPE html>
<html>
<head>
 <title>My first web page</title>
 <meta charset="utf-8"/>
</head>

<body>
<p>This is my first web page.</p>
</body>

</html>

The first line tells the browser that the file or document type is HTML. The second line is the opening <html> tag for the HTML document which is paired with the closing </html> tag on the last line. The <html> tag indicates that your HTML code begins here. All of your code goes between the <html> and </html> tags.

<head> is the first section of the HTML document which contains background information about your webpage. This includes the character set that will be used (UTF-8, which represents every character in the Unicode set) and things such as the title of the web page which is usually displayed at the top of the browser window or as a label on your browser tab.

The webpage title shown in the browser tab.
The webpage title shown in the browser tab.

Note that the <head> tag is paired with the </head> tag. Whatever goes inside the <head> section is not actually displayed on your web page. It just includes background information about your webpage.

The next tag you will see is the <body> tag. Everything between the <body> and </body> tags is content that will be shown on your webpage. This includes text, images, tables, and other content.

The first HTML element (tag) we will use in the body section is the <p> tag which will make a paragraph of text. The content of your paragraph goes between the <p> and </p> tags. Create a new file and try it out!

Copy and paste the code from above in your new file, then click on File and Save As to save your text file as a HTML file. Choose a name for your file and end it in the .html file extension. If this is going to be your homepage, then name it index.html – also, if the option is available then make sure you choose “Hypertext Markup Language (.html)” next to “Save as Type”.

Saving your webpage
Saving your webpage

Save the file and open it with your web browser (eg. Chrome). Your page should look like this:

Your first webpage
Your first webpage