TExcelTAD
Home › HTML › HTML Basic Examples

HTML Basic Examples

This lesson is a quick tour of the HTML elements you will use on almost every page. Don't worry about memorising them yet — each one gets its own lesson later. The goal is to see how little code it takes to make something useful.

The document skeleton

Every HTML page shares the same outer shape. Think of it as a template you copy at the start of every new file.

html · try it yourself
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Skeleton</title>
  </head>
  <body>
    <p>Your content goes here.</p>
  </body>
</html>
Line Purpose
<!DOCTYPE html> Declares an HTML5 document. Must be the very first line.
<html lang="en"> The root element; lang helps screen readers and translators.
<meta charset="UTF-8"> Lets the page display any character, from é to 漢 to 😀.
<meta name="viewport" …> Makes the page scale properly on phones.
<title> Text on the browser tab and in search results.
<body> Everything the visitor sees.

The <!DOCTYPE> declaration is not case-sensitive, but writing it as <!DOCTYPE html> is the common convention.

Headings, paragraphs, links and images

The four most common building blocks:

html · try it yourself
<h1>Welcome to My Garden</h1>
<h2>This month</h2>
<p>The tomatoes are finally turning red.</p>
<p>Read more on the <a href="https://en.wikipedia.org/wiki/Tomato">tomato page</a>.</p>
<img alt="A red circle standing in for a tomato" width="80" height="80"
     src="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 80'%3E%3Ccircle cx='40' cy='44' r='32' fill='tomato'/%3E%3Crect x='36' y='4' width='8' height='14' fill='green'/%3E%3C/svg%3E">
  • Headings go from <h1> (most important) to <h6> (least important).
  • Paragraphs use <p>.
  • Links use <a> with the destination in the href attribute.
  • Images use <img> with the file in src, a text description in alt, and optional width and height.

Note: The image above is written as a data URI — the picture itself is embedded in the address. On a normal site you would write something like src="tomato.jpg".

Buttons and lists

html · try it yourself
<h3>Shopping list</h3>
<ul>
  <li>Bread</li>
  <li>Cheese</li>
  <li>Apples</li>
</ul>

<h3>Steps</h3>
<ol>
  <li>Slice the bread</li>
  <li>Add the cheese</li>
  <li>Toast for 3 minutes</li>
</ol>

<button type="button" onclick="alert('Enjoy your toast!')">I'm hungry</button>
  • <ul> makes an unordered (bulleted) list; <ol> makes an ordered (numbered) list. Each item is an <li>.
  • <button> creates a clickable button. The onclick attribute runs a small piece of JavaScript.

Line breaks and horizontal rules

html · try it yourself
<p>Roses are red,<br>violets are blue,<br>HTML is easy,<br>and so are you.</p>
<hr>
<p>Above this paragraph is a thematic break, drawn as a line.</p>

<br> forces a new line inside a paragraph, and <hr> marks a change of topic. Both are empty elements with no closing tag.

Quick reference

Element What it creates
<h1>–<h6> Headings
<p> Paragraph
<a href="…"> Link
<img src="…" alt="…"> Image
<ul>, <ol>, <li> Lists and list items
<button> Button
<br> Line break
<hr> Thematic break (horizontal line)

Tip: Open your browser's developer tools (F12) on any example result and click Elements to see the exact tree the browser built from your HTML.

Test yourself

Which element creates a numbered list?

  1. <ul>
  2. <ol>
  3. <li>
  4. <list>

In <a href="page.html">Go</a>, what does href hold?

  1. The link text
  2. The link's colour
  3. The destination address
  4. The tooltip

Why should every <img> have an alt attribute?

  1. It makes the image load faster
  2. It describes the image for screen readers and when it fails to load
  3. It sets the image size
  4. It is required for the image to be visible