Lesson 1 / 813%

Lesson 1

Introduction

10 min

Understand what HTML is and its role on the web.

What is HTML?

HTML (HyperText Markup Language) is the language used to structure the content of a web page: headings, paragraphs, images, links, forms, tables... It is not a programming language in the strict sense (no loops, no conditions), but a markuplanguage: each piece of content is wrapped in tags that indicate its role.

The word "hypertext" refers to text that contains links to other texts. This is precisely what made the web successful: every page can point to another page, whether on the same site or on the other side of the world, and it is by following these links that you "navigate" from one page to another. The word "markup" comes from the idea of placing tags (like road signs) around the text to tell the browser: "this is a heading", "this is a paragraph", "this is an image".

When you open a web page, your browser (Chrome, Firefox, Safari...) downloads an HTML file, reads it line by line, and builds a visual representation from that text: this is what we call the DOM (Document Object Model). HTML alone gives you an unstyled page; CSS then dresses it up, and JavaScript makes it interactive.

The DOM is a kind of family tree of the page: the htmlelement is the root, it contains head and body, which in turn contain other elements, and so on. Understanding this tree idea will be very useful later, when you learn to style or manipulate elements with CSS and JavaScript.

The three pillars of the web

  • HTML — structure and content (what is on the page)
  • CSS — presentation (colors, layout, animations)
  • JavaScript — behavior (interactions, dynamic logic)

To use a house analogy: HTML is the frame and the walls, CSS is the paint and the decoration, and JavaScript is the electricity that makes the lights and appliances work.

A bit of history

HTML was invented around 1990 by Tim Berners-Lee, a researcher at CERN, to let scientists easily share linked documents. The first versions were very simple: a few tags for headings, paragraphs and links. Over the years, the language evolved (HTML 2, 3.2, 4, then XHTML) to meet the needs of an ever richer web, until the arrival of HTML5.

Today, HTML is maintained by the WHATWG, a group made up of the main browser vendors. The language is described as a "Living Standard": there are no more big numbered versions, just continuous, gradual evolution. Everything you learn in this course remains valid: HTML is designed to stay compatible with older pages.

Anatomy of a tag

A tag is generally written in two parts: an opening tag <p> and a closing tag </p> (with the /), with the content placed between the two. This whole set is called an element.

Anatomy of an HTML tag

Watch your vocabulary: a tag is only the part between angle brackets (for example <p>), whereas an element includes the opening tag, the content and the closing tag. In practice, many developers use the two words interchangeably, but it is good to know the difference.

Some tags have no content and therefore no closing tag: they are called self-closing tags (or "void elements").

void-elements.html
<img src="/cat.jpg" alt="A cat" />
<br />
<hr />
<input type="text" />

Attributes

An opening tag can contain extra information called attributes. An attribute is written in the form name="value" and placed after the tag name, separated by a space. It is used to specify the behavior or appearance of the element: the address of an image, the destination of a link, the language of a page...

attributes.html
<a href="https://example.com" target="_blank">Visit the site</a>
<img src="/photo.jpg" alt="A photo of a landscape" width="300" />
<p class="intro" id="first-paragraph">A paragraph with two attributes.</p>

A few attributes you will come across very often:

  • href — the address a link points to (a tag)
  • src — the location of the file to display (image, video, script)
  • alt — the alternative text of an image, read by screen readers and displayed if the image fails to load
  • class and id — names that let you target an element with CSS or JavaScript
  • lang — the language of the content, for example en for English

Attributes are never placed in the closing tag: only the opening tag accepts them.

Nesting elements

An element can contain other elements: this is called nesting. It is what lets you build complex pages from simple building blocks. The golden rule is to always close elements in the reverse order of how they were opened: the last one opened is the first one closed, like Russian dolls.

nesting.html
<!-- Correct: the tags are properly nested -->
<p>I am <strong>very <em>happy</em></strong> to be learning HTML.</p>

<!-- Incorrect: the tags overlap -->
<p>I am <strong>very <em>happy</strong></em> to be learning HTML.</p>

To keep your code readable, indent (shift to the right) each level of nesting, usually by two or four spaces. The browser ignores this indentation, but it helps you enormously to see the structure of your document at a glance.

Minimal page structure

Minimal example

index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>My first page</title>
  </head>
  <body>
    <h1>Hello world!</h1>
    <p>This is my first paragraph.</p>
  </body>
</html>

Let's look at the role of each part of this skeleton:

  • <!DOCTYPE html> — tells the browser that this is an HTML5 document (it is not a tag in the strict sense)
  • <html lang="en"> — the root element that contains everything else, with the language of the page
  • <head> — information about the page (title, encoding, styles...), which is not displayed in the content area
  • <meta charset="UTF-8" /> — the character encoding, essential for correctly displaying accents and special characters (é, è, à, ç...)
  • <title> — the title shown in the browser tab and in search results
  • <body> — everything visible to the visitor: text, images, links, forms

Your first elements: headings and paragraphs

The two most commonly used elements are headings and paragraphs. There are six heading levels, from h1 (the most important) to h6 (the least important). A paragraph is written with the p tag.

headings-paragraphs.html
<h1>Main title of the page</h1>
<h2>A major section</h2>
<p>A paragraph of text that develops the section.</p>
<h3>A subsection</h3>
<p>Another, more detailed paragraph.</p>

Choose a heading's level based on its importance in the document, not on the size it has on screen: size is set with CSS. By convention, a page contains only one h1, and you don't skip levels (you don't go from an h2 directly to an h4). This hierarchy helps search engines and screen readers understand your page.

Comments

You can leave notes in your code that will not be displayed in the browser: these are comments. They are used to explain a part of the code, to remind yourself of something, or to temporarily disable a piece of code without deleting it.

comments.html
<!-- This is a comment: the browser ignores it -->
<p>This paragraph, however, will be displayed.</p>

<!-- <p>This one is temporarily disabled.</p> -->

What's new in HTML5

HTML5, officially published in 2014, is the version currently used across the modern web. Compared to previous versions (HTML4, XHTML), it notably brings:

  • New semantic tags: header, nav, section, article, footer...
  • Native support for video (video) and audio (audio) without external plugins (goodbye Flash)
  • Graphics drawing via canvas (pixel-based) and svg (vector-based)
  • New input types for forms (email, date, range...)
  • A simplified <!DOCTYPE html> (previously a long, complex line)

Why semantics matter

Using the right tag for the right content is not just a matter of aesthetics. A well-structured page is better understood by search engines (better SEO), more accessible to people who use a screen reader, and easier to maintain for you and for other developers.

How to write and view HTML

You don't need any special software: a simple text editor (VS Code, for example) and a browser are enough. The process is always the same:

  • Create a file with the .html extension (by convention, the home page is called index.html)
  • Write the HTML code inside it
  • Double-click the file (or right-click → "Open with" your browser) to see the result
  • Edit the file, save it, then refresh the page in the browser to see the changes

If you use VS Code, the Live Server extension can save you from refreshing the page by hand: it automatically reloads the browser every time you save. It's a real time-saver when you run lots of small experiments.

Inspecting a page with browser tools

All modern browsers include developer tools. Right-click on any web page, then choose "Inspect" (or press F12). You will see the page's HTML code as the browser understood it, with the tree structure of the DOM. It's an excellent way to learn: you can look at how the sites you like are built, and even edit the code live to test ideas (changes disappear when you reload, so nothing gets broken).

Common beginner mistakes

  • Forgetting a closing tag: the browser tries to guess what you meant, and the result is rarely what you expected
  • Getting the closing order of nested tags wrong (see the example above)
  • Forgetting the quotes around an attribute value, or mixing quote types (an opening " with a closing ')
  • Saving the file with the wrong extension (for example index.html.txt), which prevents the browser from interpreting it as HTML
  • Forgetting to save before refreshing the page, then wondering why nothing changes
  • Typing several spaces or line breaks and expecting them to show up: in HTML, the browser collapses them into a single space

Key takeaways

  • HTML structures the content of a page using tags
  • An element = opening tag + content + closing tag (except void elements)
  • Attributes specify an element's behavior and go in the opening tag
  • Elements can be nested and are closed in the reverse order of how they were opened
  • A page is made up of a head (information) and a body (visible content)
  • A text editor and a browser are enough to get started

Exercise

Create an index.html file using the minimal structure shown above. Add a main heading with your first name and a paragraph that introduces you in one sentence. Then open it in your browser to see the result.

Going further

Add a second paragraph explaining why you are learning web development, then change the content of the <title> tag to see the effect on the browser tab.

Challenge: attributes and comments

In your page, add a link to a site you like using the <a> tag and its href attribute, then a <h2> subheading followed by a paragraph containing a word in <strong>. Finally, add a comment explaining the role of each part, then open the developer tools (F12) to find your code in the DOM.