Search the guide

2.1

Overview & Goals

trophy icon At the end of this part, you will be able to:
  • Modify, add and remove content to an HTML page.
  • Check the validity of your HTML code and fix it if needed.
  • Edit, modify and organize images to optimize them for a website.

Contents of this part

This second chapter supports you as you edit your resumé.

  • You’ll first learn about common HTML elements so you understand the function of each of these building blocks and can add, remove or change parts of your résumé.
  • Your browser’s developer tools can help you fix errors or draw inspiration from other websites.
  • We are all humans, and typos happen when writing HTML code. Learn how to recognize, find and fix them by keeping your HTML code clean and a good folder structure.
  • You then learn how to use hyperlinks to direct your visitors to other pages or sites and to show them images.
  • Your images will be hosted in your repository alongside your HTML code. The final section teaches you the best practices for resizing and delivering images.

What you need to do

This part of the guide will support you in editing all the content in your resumé and change the images. This includes:

  • Editing all text content in the page: tagline, schools, job names, etc.
  • Adding or removing sections, e.g. additional jobs, languages or hobbies
  • Adding a photo of yourself and the logos of schools and employers.

In doing so, you must follow good coding practices. This includes:

  • Checking that the structure of your HTML code is still valid after major changes.
  • Putting your images in the appropriate folders and delivering them alongside your website on GitHub.
  • Managing your images to ensure a compromise between image quality and page load speed.
  • Republishing your website and checking that it is working correctly on mobiles.

2.2

Common HTML elements

film icon Watch on Microsoft Stream
  • You don’t need to remember the whole list of HTML elements, but you need to pick the right ones when coding.
  • Some elements are essential for the structure of the code: <html> <body>, <head>, etc..
  • Elements can be generic or semantic, and they can be inline or block.
  • There are 100+ elements, not all are listed here, so check online references.

Previously in this course…

In part 1.5, you’ve already encountered quite a few elements:

  • <html>, the root element containing everything else.
  • <head>, which contains metadata about the whole document.
  • <meta> and <title> which are only found in the head.
  • <body>, for all the content within the browser frame.
  • <p>, the paragraph element.
  • <strong>, which turns its contents bold.
  • <br>, the line break tag.

You already know that some elements need an opening and a closing tag, for example a paragraph starts with <p> and ends with </p>.

Other elements are self-closing and cannot contain anything. Within the list above, only <meta> and <br> are self-closing, they do not need an end tag.

How many tags are there?

Given the complex history of the HTML standard, you won’t find a universally accepted number, but there are over 100 (yes, one hundred) elements you can use in a web page.

You never need to remember all of them by heart, but you need to be able to identify which element is the most appropriate for your needs.

Sources you can use include:

“Block” elements

This is a first list of very common HTML elements (the underlined parts explain what the tag name stands for):

  • Heading levels 1 to 6: <h1>, <h2>, <h3>, <h4>, <h5> and <h6>
  • Lists, which exist in two flavours:
    1. unordered lists, a.k.a. bullet points, with the <ul> element
    2. ordered (or numbered) ones, with <ol>
  • Within either <ul> or <ol>, each list item uses the <li> tag.
  • <hr> is an horizontal rule. It is self-closing
  • The most used HTML element on the web is <div>, which is used to create logical divisions within content. <div> is often used in combination with CSS styles (which you’ll learn about in the next part) to group elements visually. This page alone has such div elements.

All these tags, as well as <p> and <br>, have in common that opening them creates a new “block”. This means that you break the flow of the text and move to a new line. This behaviour will become clearer when you compare these with inline tags.

Code:
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<p>This is a paragraph</p>
<div>

<p>Another paragraph inside a div</p>

</div>
<hr>
<ul>

<li>Item in an unordered list</li>

</ul>
<ol>

<li>Item in an ordered list</li>

</ol>
Result:

Heading 3

Heading 4

This is a paragraph

Another paragraph inside a div


  • Item in an unordered list
  1. Item in an ordered list

“Inline” elements

Here is a second list of elements:

  • <em>, standing for emphasis and <i>, which both turn your text in italics.
  • <b>, like <strong>, makes your text bold.
  • <u> for underline.
  • <a>, meaning anchor, which is used in hyperlinks with the href (hypertext reference) attribute.
  • <img>, the image tag, which needs a src (source) attribute to link it to an image file, and an alt attribute to provide a textual alternative. <img> is self-closing.
  • <span> is also a common, generic way of identifying a span of text

The biggest difference with the first list of tags is that inline ones do not interrupt the flow of text but rather make it continue on the same line.

Code:
<p>

This paragraph contains
<strong>words in bold type</strong>,
<em>words in italics</em> and
<u>also underlined ones</u>.

</p>
<p>

This paragraph contains
<span>a span</span>,
<a href="part-1.html">a hyperlink sending you to part 1</a> and the
<img src="images/common/logo-buas.svg" alt="Our logo" width="43" height="14">
BUas logo.

</p>
Result:

This paragraph contains words in bold type, words in italics and also underlined ones.

This paragraph contains a span, a hyperlink sending you to part 1 and the Our logo BUas logo.

“Semantic” elements

With over 100 elements, you’ve already noticed that some of them are very similar and what they do. For example:

  • <b> and <strong> look the same
  • <i> and <em> also have an identical effect
  • Alongside <div>, there are several tags that can be used to create a division in the page, e.g. <header>, <main>, <article>, etc.

The difference between these similar tags is called semantics. In other words, each of these tags ascribes a meaning, or a function, to its content.

The rationale behind semantics is that the structure of your HTML page should reflect the structure of your content independently of how your page looks in the browser. This is important for:

  • Accessibility purposes: Some people rely on screen reading software to be able to access the web. This software will in turn rely on the structure of the page to identify key elements and say out loud what they are.
  • Search Engine Optimization (SEO): Every search engine ascribes a ranking to determine how relevant a page is with regards to search keywords. This ranking is partly based on whether a keyword appears in relevant parts (e.g. headings). Search engines also rely on the page structure to identify important information like business addresses and opening hours.
  • Collaboration: Well-structured code that clearly signposts what each part of the page means will be easier for other web developers to read and to work on.

Some tags are considered to be generic, which means that they have no specific structural meaning and are generally used purely for layout and styling purposes. This is the case for <div> and <span>

Example semantic elements

The meaning of semantic tags is defined in the HTML standard:

  • <header> is used for the introduction to a piece of content.
  • <nav> defines a section used for navigation purposes such as a menu or table of contents.
  • <article> is a self-contained piece of content, such as a news article, a blog post, a product entry in an online shop, etc.
  • <section> is used for an important subdivision of your document such as a chapter.
  • <footer> is used at the end of a piece of content.
  • <aside> to introduce indirectly related content.

The structure of your page could for example look like this:

<header>
<nav>
<article> <aside>
<section>
<footer>

Other elements

We’re still far from the 100+ elements we mentioned at the start. Some elements that you may use for the purpose of your assignment include:

Some of these elements are present in this page as well as in other templates for this course. Don’t hesitate to check the source code!

Miscellaneous Examples

Use <audio> to listen to HUB radio:
Use this form to send an email

2.3

Use Developer Tools

film icon Watch on Microsoft Stream
  • Your browser has Developer Tools that can help you check the structure of any page.
  • Use it to test fixes on your code or to see how other.
  • You can also use it to identify some errors.

Where to find Developer Tools?

Check the official documentation for your browser. Keyboard shortcuts vary depending on the operating system.

Browser (link leads you to developer docs) Keyboard shortcut (Windows) Keyboard shortcut (Mac)
Google Chrome F12 or Ctrl+Shift+I Command+Option+I
Mozilla Firefox
Microsoft Edge
Apple Safari Mac Only Activated via Menu

Another way to access the Developer Tools is to choose an element within your page, then Right-Click on it and choose “Inspect” in the contextual menu that appears. Why not try it here?CONGRATULATIONS! You've found hidden content!

What is in Developer Tools?

The Developer Tools is divided in several tabs (which might be labeled differently depending on browsers):

  • Console is generally used to work with JavaScript, which is not covered in this course, but it sometimes shows useful error reports.
  • Elements (labeled Inspector in Firefox) is the most useful tab for our course. Possibilities include:
    • You can check the structure of the HTML Tree (the Document Object Model or DOM) and fold or unfold it.
    • You can copy the relevant piece of HTML code to reuse it.
    • You can edit the HTML code and see the results immediately. Be careful, it won’t be saved.
    • You can also check which styles are applied to an element (you’ll learn about styles in Part 3).
  • Sources show you all the elements that were loaded alongside the HTML code of the page. This includes all the images, fonts and stylesheets that are needed to achieve the page’s visual aspect.

Try it out!

Using the Elements tag in Developer Tools, try answering the following questions:

  1. Which heading level is used just above (<h1>, <h2>… <h6>)?
  2. Which class(es) does this heading have?
  3. Which element does it have as a parent?
  4. How deep/far is it in the whole document’s tree?

Using the Sources tab, check the following:

  1. How many additional resources are loaded alongside this page?
  2. Which of these are images?
  3. Which of these are loaded from the same website (buas-media-interactive.github.io)?
  4. From which other websites are resources loaded? These are called CDNs (Content Delivery Networks).

Hint!

This is what it looks like in the Chrome Developer tools:

A screenshot of Chrome Developer Tools

2.4

Avoid Errors

film icon Watch on Microsoft Stream
  • Name the files and folders in your project correctly.
  • Check what the most common HTML errors are.
  • Many errors result in having an improper HTML structure.
  • Use validation tools to identify these errors.

File and folder good practices

In order to avoid issues, the first thing to do is to follow good practices when naming and structuring files and folders. There are multiple reasons to do so:

  • If all workers in the same company, or all students in the same course follow the same naming conventions, it becomes easier to collaborate. In industry, companies may have their own conventions which might be different from the ones below.
  • Different operating systems letter case (i.e. capital vs. lowercase), accents and other special characters differently, so your files might not work identically on a Mac, on a PC or when you upload it to GitHub
  • One very common mistake is to work on the wrong file. This can be avoided in part by having a clear and sensible folder structure.
  • This will also be very convenient when, as described in the next section, you start adding images and making links to other pages within your folder.

In this course, we require that you stick to the following conventions:

  • Your landing page must be in the root folder of your website and named index.html.
  • All other HTML pages are in the same folder.
  • All CSS style files are within a folder named css.
  • All image files are within a folder named images.
  • All file names are lowercase only. This means that you might have to rename external images before adding them to your website.
  • No spaces, no accents. The only special characters you can use are hyphen (-) and underscore (_).

Examples

Folder structure
  • folder website
    • file index.html
    • file page-1.html
    • file page-2.html
    • folder css
      • file styles.css
    • folder images
      • image file image-1.jpg
      • image file image-2.png
      • image file image-3.svg
File names
  • All lowercase:
    • wrong Welcome.html
    • right welcome.html
  • No spaces, use hyphens instead:
    • wrong BUas logo.png
    • right buas-logo.png
  • No accents or special characters:
    • wrong From Liège to Köln.jpeg
    • right from-liege-to-koeln.jpeg

Common HTML mistakes

These are errors that everyone makes, including experienced web developers. Being able to identify and correct mistakes is one of the hardest skills in HTML development.

  • Missing closing tags. For example, you start a link with <a href="…"> but then you forget to close it and the rest of your page becomes one giant link.
  • Mismatch between an opening tag and a closing tag: For example, you start with <h1> and you finish with </h2>. This often happens when you try to substitute an element for another but you don’t do it completely.
  • Typos or incorrect tag names. <h1> and <p> exist, but not <p1>, this is considered an error.
  • Errors with attributes: When writing an attribute, such the source of an image or a class on an element (e.g. <p class="my-class">), spaces, quotation marks and/or the equal sign are missing.
  • Code that doesn’t follow your intent. Sometimes the structure is correct, but the result is not what you intend because elements are not in the right place in the tree of the document. For example, this bullet point here is not aligned because the current list item is not within the rest of the list.
  • Many errors won’t be visible because your browser will try to fix them — note that this is specific to HTML, other languages are not error-tolerant and will break if there is an error.

    However, computers rely on binary logic and cannot guess your intent if your code is wrong. In other words, code that doesn’t follow standards may give unpredictable results.

    Detecting errors: Validation

    You can use several tools to detect errors:

    • Dreamweaver will show you errors. Read the description of the error, and check whether it corresponds to one of the errors listed here.
    • Check what the structure of your DOM Tree is and if it fits your intent. You can see it in Dreamweaver using the DOM panel, or in the Developer tools in a browser.
    • Finally, always check if your code conforms to standards at validator.w3.org. Again, error information can be interpreted by comparing it with the list of common mistakes.

    For the assignments: your code must be free of errors. Please double-check with before handing in using validator.w3.org. If your page still has “warnings” (in yellow), we will accept it.

    Click here to test the current page

    Yes, this page has an intentional error!

    What you should see when things are correct:

    Document checking completed. No errors or warnings to show.

    Preventing errors: Indentation

    Indentation is a very simple good practice that helps you keep track of the structure of your code and avoid errors.

    To use indentation, make sure you add spaces or tabs at the start of a line every time you go down one level in the structure of the tree, and remove them when you go up one level.

    Indentation has no impact on the output of your code: your page will look exactly the same in the browser if you have no spaces at the start of a line.

    When zooming out on the source code, the indentation shows you the outline of the document.
    A screenshot of the source code for this specific page

    The example below shows the relation between indentation and structure

    (Level 0) <html>

    (Level 1) <head>

    (Level 2) <meta charset="utf-8">

    <title>This is the title</title>

    </head>

    <body>

    <header> (Level 2)

    (Level 3) <h1>Welcome to this page!</h1>

    </header>

    <main>

    (Level 3) <section>

    (Level 4) <p>This is a paragraph with some text.</p>

    <p>And here is another paragraph.</p>

    <p>

    (Level 5) <a href="https://www.buas.nl/">And another one with a hyperlink.</a>

    (Level 4) </p>

    (Level 3) </section>

    (Level 2) </main>

    </body> (Level 1)

    </html> (Level 0)

    2.6

    Manage images

    film icon Watch on Microsoft Stream
    • Use images to grab the attention of your audience.
    • Choose the right format for your images.
    • Resize them and organize them properly.

    Why use images?

    Our brains’ attention is attracted by visual content, in particular:

    • Pictures of human and animal faces, especially when they’re looking at you.
    • Bright colours and moving images.
    • Images displaying food, creating a sense of danger, or generating sexual arousal.

    Attracting one’s attention is what you want to do with your audience, therefore images are essential for web design.

    A photo of a cat
    This photo of a cat was taken by Millie Wollney and posted on Unsplash

    Image size

    The words “image size” can mean two things:

    1. The pixel dimensions. For example, the original image of this cat was 3000 pixels wide and 3000 pixels high.
    2. The file size. The same original file was 1 megabyte (MB), which is equivalent, in terms of the space needed on your hard drive, to a text made of a million letters.

    Larger images mean a higher quality, but this is limited by how big the image will be displayed in a browser.

    But larger images take longer to download and need more disk space to store, which has the following downsides:

    • From the point of view of the website visitor:
      • Pages and images take more time to load. On a typical 4G or cheap DSL subscription, the original image takes a fifth of a second to load, which starts to become noticeable. On a 3G connection, it will take more than a second and will feel very slow.
      • If the website is browsed on a mobile phone, then this will use up some of the user’ data allowance. The cheapest mobile plans tend to have a 1 GB monthly limit, or in other words, 33 high-quality cat images a day.
    • From the point of view of the owner of the website: hosting is generally charged based on how much disk space and network bandwidth you are using. Big images cost more money!

    The solution is then to reduce image size, which can be done in two ways:

    • Decreasing the pixel size
    • Choosing the right file format

    In this example, I have reduced the image to 500 pixels wide (this is 6 times smaller). The result is an image that weighs 70 kilobytes (KB), which is 15 times smaller, and therefore 15 times faster to load.

    File formats

    The file format you’ll use depends on the type of image you have.

    JPEG (Joint Photography Expert Group)

    • good JPEG is the most appropriate format for photos
    • good It uses a “lossy” compression algorithm that is very efficient at making photos smaller.
    • bad The “lossy” compression will degrade the quality of your image, and this will be especially visible on geometric shapes.
    • bad It shouldn“t be used for images that contain logos, infographics, gradients and text.

    SVG (Scalable Vector Graphics)

    • good SVG is a vector format, therefore the quality of an image is not dependent on its dimensions.
    • good SVG files can be exported directly from Adobe Illustrator.
    • good SVG can be used for logos, illustrations and infographics.
    • bad However, it doesn’t work very consistently with text.

    PNG (Portable Network Graphics)

    • good PNG is a format that uses lossless compression: images retain their original quality.
    • good PNG is very performant can be used for logos, illustrations, geometric shapes, text and infographics.
    • good Use PNG also when you have mixed content that doesn’t necessarily work well with SVG or JPEG.
    • bad The PNG compression is not very efficient with photos.

    Resizing images

    The easiest way of resizing images is to use the Crop tool in Photoshop. Click here for a tutorial on this tool [adobe.com].

    When the same image is used multiple times at different sizes for different purposes, it is recommended that you create separate copies. If you have pages with multiple images, such as a gallery, you should all resize them to the same size and aspect ratio.

    The aspect ratio of an image is how wide is it versus how high it is. A square image has a 1:1 aspect ratio, a TV (at least the ones sold in the last 15 years) has a 16:9 aspect ratio.

    Original W: 3000px H: 4000px ratio: 3:4 Portrait W: 480px H: 640px ratio: 2:3 Thumbnail W: 300px H: 300px ratio: 1:1
    The image above has been resized in two different versions: a portrait for use in a page about the subject, and a thumbnail to show within a gallery of photos.

    You should resize your images based on how big they will be on your web page. This is something you can measure using your browser’s developer tools. You can also use the dimensions of this page (see below).

    How wide are elements on this page?

    Try resizing your browser window to see the numbers below change in real time!


    full width: 000px


    half width: 000px


    1/3 000px


    1/6 000px

    Check images before publishing

    Please check the file size of all your images before publishing! Note that there is no strict guideline on how big an image should be, because it depends on the whole page.

    For example, you could have 2 large images of 500KB each, or 50 small images of 20KB each, and reach a total size of 1 megabyte, which is a reasonable total size.

    I have developed an image checker that you can use to check the properties of your image files before publishing them.

    Keep good file management practices

    The recommendations from the section above are still valid: Your images should all be in the images folder, their names should be lowercase only, with no spaces or special characters.

    If you have many images (more than 20), consider using sub-folders to make it easier to find them.