HTML Basics for Beginners

Frontend ~ 8 minutes

# Welcome to HTML

Hello and welcome! In this tutorial, we will learn HTML. HTML means HyperText Markup Language. It is the base of every web page in the world. When you open a website, your browser reads HTML and shows you the text, images and links.

Do not worry if you have never written code before. We will go slowly. Each step is small and easy. By the end, you will build your own first web page.

What you will learn

  • How an HTML file is built
  • How to write headings and paragraphs
  • How to add links and images
  • How to make lists

You only need a simple text editor and a web browser. Let us begin with a new folder for our work.

Create a project folder
Code Copied to Clipboard

# Why we use a folder

Great! You have made a new folder called my-first-page. A folder keeps all your files in one place. This is a good habit for every project, big or small.

Now, please open this folder in your text editor. Any editor is fine. Visual Studio Code is a free and popular choice. Inside the folder, make a new file and name it index.html. The name index is special. Web servers look for it first, so it is the usual name for the home page.

The ending .html tells the computer that the file holds HTML. Please do not forget this ending. If you save the file as index.txt, the browser will not read it as a web page.

Next, we will write the basic skeleton that every page needs.

The basic page skeleton
Code Copied to Clipboard

# Understanding the skeleton

Let us look at the code line by line. It looks long, but each part is simple.

<!DOCTYPE html> tells the browser that this page uses modern HTML. The <html> tag wraps the whole page. The lang='en' part says the page is in English.

The <head> section holds information about the page. People do not see most of it. The <title> inside it is the text you see on the browser tab. The <meta charset='UTF-8'> line helps the browser show letters and symbols correctly.

The <body> section holds everything that people can see. Here we have a big heading with <h1> and a paragraph with <p>.

Key points to remember

  • Most tags come in pairs: an opening tag and a closing tag
  • The closing tag has a slash, like </p>
  • Tags can sit inside other tags
  • The <head> is hidden, the <body> is visible

Please type the code yourself. Typing helps you learn faster than copying.

Tags and elements

A small note on words. A tag is the part inside angle brackets, like <p>. An element is the full thing: the opening tag, the content and the closing tag. So <p>Hello</p> is one paragraph element.

Some elements have no content, so they have no closing tag. We call them void elements. The line break <br> and the image <img> are two examples.

You can read more in the MDN HTML guide. It is free and very clear.

# Headings, paragraphs and lists

Now, let us add more content to the body. HTML gives us six levels of headings, from <h1> to <h6>. The <h1> is the most important, and <h6> is the smallest. Use only one <h1> on each page. It is the main title.

For normal text, use the <p> tag. Each paragraph starts on a new line. To make words stand out, use <strong> for bold meaning and <em> for gentle stress.

Lists are also very useful. Use <ul> for a list with bullets. Use <ol> for a numbered list. Every item inside goes in an <li> tag.

Common text tags

  • <h1> to <h6> for headings
  • <p> for paragraphs
  • <ul> and <ol> for lists
  • <li> for each list item

Let us see them in a small example.

Headings and lists
Code Copied to Clipboard

# Links and images

The web is full of links. That is why it is called a web! To make a link, we use the <a> tag. The word a means anchor. The href attribute tells the browser where the link goes.

An attribute gives extra information to a tag. It sits inside the opening tag and has a name and a value, like href='https://example.com'.

To show a picture, we use the <img> tag. It needs two attributes. The src says where the picture file is. The alt gives a short text description. The alt text is very important. Screen readers speak it for people who cannot see the picture. It also shows if the image fails to load.

Attributes you will use often

  • href for the address of a link
  • src for the file path of an image
  • alt for the picture description
  • class and id for naming elements

Now, please add the following lines to your body.

A link and an image
Code Copied to Clipboard

# Time to see your page

You have written a lot, so let us look at the result. The easiest way is to double click the index.html file. It opens in your browser. After each change, save the file and press refresh in the browser.

There is also another way. We can start a tiny local web server. This is closer to how real websites work. Python can do it with one line. If you have Python 3 installed, please run the command below in your terminal.

After you run it, open http://localhost:8000 in your browser. You will see your page. To stop the server, press Ctrl + C in the terminal. If the command does not work, do not worry. Opening the file by double click is perfectly fine for now.

Start a local server
Code Copied to Clipboard

# Building a small card

Let us put things together. A good page uses special semantic tags. These tags tell the browser, and search engines, what each part means. For example, <header> is for the top part, <main> is for the main content, and <footer> is for the bottom.

Why semantic tags help

  • They make code easier to read
  • They help screen readers move around the page
  • They help search engines understand your content

Below is a small page layout using these tags. Try to replace the body of your page with it. Then change the words to talk about yourself.

A semantic layout
Code Copied to Clipboard
Common mistakes to avoid

Almost every beginner makes the same few mistakes. Please read this part carefully. It can save you a lot of time.

First, do not forget to close your tags. If you open a <p> and never close it, the page may look strange. The browser tries to guess what you meant, and it often guesses wrong.

Second, always write the alt text on images. It helps many people and it is a good habit from day one.

Third, do not use headings only to make text big. Headings show the structure of the page. If you want to change size or color, you will use CSS later.

Quick checklist before you finish

  • Every opening tag has a closing tag
  • The file name ends with .html
  • Every image has an alt attribute
  • There is only one <h1> on the page

If your page looks wrong, check this list first. Most errors are found here.

# Summary and next steps

Well done! You have finished this tutorial. Let us remember what we learned today.

You know that HTML is the structure of a web page. You built the page skeleton with <html>, <head> and <body>. You wrote headings, paragraphs and lists. You added links with <a> and pictures with <img>. You also used semantic tags like <header>, <main> and <footer>.

What to learn next

  • Learn CSS to add colors, fonts and layout
  • Learn about HTML forms and inputs
  • Learn JavaScript to make pages interactive
  • Practice by building a page about your hobby

A good next stop is the MDN Learn Web Development course. Keep practicing a little every day. Small steps lead to big results. You are doing great!