knowledge-kitchen

HTML - The Language of the Web (For Better or For Worse)

facilitating the control the content of web pages

  1. Overview
  2. Separation of Concerns
  3. Bare Minimum Code
  4. Elements & Tags
  5. Attributes
  6. Common Tags
  7. Try It Out
  8. Conclusions

Overview

Hypertext Markup Language (HTML) is used to indicate the contents of a web page.

Separation of Concerns

The separation of concerns is a philosophy popular in technology that different tasks should be accomplished by different technologis. With regards the Web:

Bare Minimum HTML Code

At the very least, an HTML document contains the following code:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Insert the title of your page here</title>
    <link rel="stylesheet" type="text/css" href="css/some_stylesheet.css" />
  </head>
  <body>
    Insert the contents of your page here.
  </body>
</html>

doctype

Let’s start with the first line, the doctype.

<!DOCTYPE html>

html

Moving on, we see the html tags the beginning and the end.

<html>
  ...
</html>

head and body

Within the html element, indented one level further in, we see two sets of tags: head and body.

<head>
  ...
</head>

<body>
  ...
</body>

meta charset

The meta tag resides within the head.

<meta charset="utf-8" />

title

The title element is metadata indicating to the web browser the title of this document.

<title>Insert the title of your page here</title>

The link element informs the web browser of the existence of another file it should load.

<link rel="stylesheet" type="text/css" href="css/some_stylesheet.css" />

body contents

The contents of the body tag indicate the visible elements of the page.

<body>
  Insert the contents of your page here.
</body>

Elements & Tags

Elements

An HTML element is a conceptual piece of content or metadata in the document. E.g.

Tags

Tags are the code that is written to inform the browser that you wish to create an element.

Tag pairs

As a general rule, tags come in pairs - an opening and a closing tag together indicate the start and end of a conceptual element.

For example - an opening paragraph tag.

<p></p>

And its corresponding closing - closing tags use the same tag name as the opening tag, e.g. p, but place a slash / in front of it.

</p>

Self-closing tags

Some opening tags do not have a separate closing tag. These are self-closing tags.

For example - the link opening tag. There is no corresponding </link> closing tag.

<link rel="stylesheet" type="text/css" href="css/some_stylesheet.css" />

Self-closing tags (continued)

<link rel="stylesheet" type="text/css" href="css/some_stylesheet.css" />

Notice that it has a slash / within the opening tag itself at the end - this indicates that it is self-closing.

Tabs

Line breaks, multiple spaces, and tabs are ignored by the web browser.

So the following code is a valid HTML document:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>Insert the title of your page here</title>
    <link rel="stylesheet" type="text/css" href="css/some_stylesheet.css" />
  </head>
  <body>
    Insert the contents of your page here.
  </body>
</html>

Tabs (continued)

This is also valid HTML code:

<!-- prettier-ignore -->
<!doctype html>

<html
lang="en"><head                 ><meta          charset="utf-8" />
<title>Insert the title of your page here<
    /title>               <link rel="stylesheet"
            type="text/css"         href="css/some_stylesheet.css" /></head><body>Insert the contents of your page here.</body></html>

Tags (continued again)

Don’t do that! We want to be able to read and understand code easily.

Do this:

<article>
  <a href="somepage.html">
    <img src="images/donkey.jpg" />
  </a>
</article>

Not this:

<!-- prettier-ignore -->
<article><a href="somepage.html"><img src="images/donkey.jpg" /></a></article>

Tabs (continued again)

With elements that contain only text nested within them, it’s okay to write that text on one line with the element’s tags.

<h1>Platypus Endangerment</h1>

But if that text is very long and requires scrolling, break it up onto multiple lines.

<h1>
  Platypus Endangerment ipsum dolor sit amet, consectetur adipiscing elit. Nam
  posuere mauris sit amet nulla egestas blandit. Phasellus gravida dui eget nisi
  dictum
</h1>

Attributes

Concept

You may have noticed that some tags contain attributes. These are extra element settings.

For example - the img tag requires the src setting indicating which image file to load.

<img src="images/donkey.jpg" />

Specific values

Some elements require attributes with particular values in order to function properly.

Arbitrary values

Other elements can have attributes with arbitrary values that the programmer makes up.

Common Elements

Universal

Elements required to setup every HTML document:

Metadata in the head

Elements used for settings within the head:

Body content

Elements used to indicate content within the body:

Grouping

Elements used to group content within the body:

Forms

Elements used in forms within the body:

Learn more

Obviously you will want to see more information on using these in a practical sense.

Try It Out

Concept

The best way to learn to make web pages is to try. There are many ways to write code for a web page and open it in a web browser to see what it looks like.

Directly open an HTML code file in your web browser

This is the simplest way to test out a web page that you have been developing.

Run a web server on your own computer using Visual Studio Code’s Live Server extension

Having a web server serve your web pages is a more “realistic” environment within which to test your pages, and it is easy to set up on your own machine.

Run a web server on your own computer using Node.js’ http-server module

Having a web server serve your web pages is a more “realistic” environment within which to test your pages, and it is easy to set up on your own machine.

Conclusions

You now have a basic understanding of the purpose of HTML, its syntax, and some of the common elements and tags.