programming-course

HTML

Basics

HTML is a markup language that describes content (web pages that include text, forms, graphics, menus, …). HTML only describes the content, and is not concerned with how the content is going to be displayed. Later, we will use CSS style sheets to customise how HTML pages are presented.

See https://developer.mozilla.org/en-US/docs/Learn/Getting_started_with_the_web/HTML_basics for details.

HTML syntax

An HTML page contains a tree of nested elements. Each element can contain text or other elements.

Summary:

Anatomy of an HTML page

This is the template of an (empty) HTML page:

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    
</head>
<body>

</body>
</html>

Forget about the first line (<!DOCTYPE html>), that’s an irregular standard requirement for backwards-compatibility. The document consists of:

Note: as with any computer language, we indent nested elements. This way, nesting relationships can be easily identified with a glance.

Important HTML elements

Three are three types of HTML tags:

  1. Inline elements: these elements do not affect text flow, and only affect their content. They can only contain text and other inline elements. The more useful ones include:

  2. Block elements: these elements denote a block of text, and therefore affect text flow. A block of text starts in a new line and is has its separate vertical space.

    • a normal paragraph is denoted with <p>. Paragraphs can only contain text and inline elements, no block elements can be inside a <p> element.

    • different levels of heading <h1> to <h6>. Headings, like parapraphs, can only contain text and inline elements, not block elements.

    • document outline (separating different parts of document) can be done with <div> elements. <div> elements can contain any other element, block or otherwise.

      There are some more outlining elements, they behave like <div> but have special use-cases: <article>, <section>, <nav>, <aside>, <header>, <footer>, <main>, <address>, <blockquote>

    • Lists can be created using <ul> for un-ordered lists (bullets), or <ol> for ordered lists (numbering). <ul> and <ol> elements can only contain <li> elements and nothing else. Each <li> denotes one item of the list. <li> itself can contain any element, block or inline.

    • Tables can be created with <table>, <tr>, <td>, <th>, <thead>, <tbody>, <tfoot>

  3. Metadata: elements like <title> and <meta> go into <head> and describe the page to machines (like browsers and search engines). They are not visible.

Common attributes

References