HTML is the language for building the structure of a web page. HTML stands for HyperText Markup Language, a markup language for web pages. A browser reads HTML, then shows the page. This tutorial covers page structure, basic tags, and how to make your first file.

Page structure

Every HTML page has three main parts:

  1. <html> holds the whole page. Everything sits inside it.
  2. <head> holds info that is not shown on the page, like the browser tab title.
  3. <body> holds everything shown: headings, text, images, and links.
  4. <title> sits inside <head>. Its text becomes the browser tab title.

This is the smallest skeleton for one page:

<!DOCTYPE html>
<html lang="id">
<head>
  <meta charset="UTF-8">
  <title>Judul Halaman</title>
</head>
<body>
  <h1>Halo, Dunia!</h1>
  <p>Ini paragraf pertama saya.</p>
</body>
</html>

The first line, <!DOCTYPE html>, tells the browser this is an HTML document. lang=“id” means the page content is in Indonesian. <meta charset=“UTF-8”> makes letters like é and emoji show correctly.

HTML page structure tree

Basic tags

A tag is a command inside < and > signs. Most tags come in pairs: an opening tag and a closing tag. The closing tag has a slash / before the tag name.

Anatomy of a tag

The most used tags:

  1. Headings, section titles, use <h1> to <h6>. <h1> is the biggest, <h6> the smallest. One page needs only one <h1>:
<h1>Judul Utama</h1>
<h2>Subjudul</h2>
<h3>Judul Kecil</h3>
  1. A paragraph, one block of text, uses <p>:
<p>Ini satu paragraf. Tulis kalimatmu di sini.</p>
  1. A link to another page uses <a>. The target address goes in the href attribute. An attribute is extra info inside the opening tag:
<a href="https://kodename.my.id">Kunjungi Kodename</a>
  1. An image uses <img>. This tag has no closing tag. The image address goes in src, and replacement text goes in alt. The alt text shows if the image fails to load, and screen readers read it aloud for blind users:
<img src="foto.jpg" alt="Foto profil Budi">

Warning: if the file name in src is misspelled, the image will not show. Check the spelling and the upper and lower case letters.

  1. Lists use <ul> for a list with no numbers (unordered list), <ol> for a numbered list (ordered list), and <li> for each item (list item):
<ul>
  <li>Membaca</li>
  <li>Bersepeda</li>
  <li>Ngoding</li>
</ul>

<ol>
  <li>Bangun pagi</li>
  <li>Sarapan</li>
  <li>Belajar HTML</li>
</ol>

Make your first index.html file

  1. Open a text editor. Notepad on Windows, TextEdit on Mac, or VS Code all work.
  2. Copy the skeleton from the page structure section into the editor.
  3. Save it as index.html. The name index.html is special: a web server opens it by itself as the main page of a folder.

Warning: make sure the file is saved as .html, not .txt. If the name becomes index.html.txt, the browser only shows raw text. In Notepad, choose “All Files” when saving so the .txt ending is not added.

Open it in a browser

  1. Find the index.html file in the folder where you saved it.
  2. Double-click the file. The browser opens it at once.
  3. Each time you change the code, save the file, then press F5 in the browser to see the result.

Flow from file to page in the browser

If the page shows blank, the most common cause is a tag that was not closed. Check that every opening tag has its closing tag. You can also ask Muse (yue) to check the code and point out the wrong line.

Full example: a bio page

Copy the code below into an index.html file, then open it in a browser. Replace the name, text, and hobbies with your own. The foto.jpg file in this example must sit in the same folder as index.html, or the image will not show. The classes in this example (kartu, foto, nama, and the rest) will be used again in the basic CSS tutorial to style this page.

<!DOCTYPE html>
<html lang="id">
<head>
  <meta charset="UTF-8">
  <title>Biodata — Budi Santoso</title>
</head>
<body>
  <div class="kartu">
    <img class="foto" src="foto.jpg" alt="Foto profil Budi Santoso">

    <h1 class="nama">Budi Santoso</h1>
    <p class="peran">Pelajar dan Calon Web Developer</p>

    <div class="tentang">
      <h2>Tentang Saya</h2>
      <p>Saya tinggal di Jakarta dan sedang belajar HTML dasar.</p>
    </div>

    <div class="keahlian">
      <h2>Keahlian</h2>
      <ul>
        <li class="item">Membaca</li>
        <li class="item">Bersepeda</li>
        <li class="item">Belajar coding</li>
      </ul>
    </div>

    <div class="kontak">
      <h2>Kontak</h2>
      <p>Email: <a href="mailto:budi@contoh.com">budi@contoh.com</a></p>
      <p>Website: <a href="https://kodename.my.id">kodename.my.id</a></p>
    </div>
  </div>
</body>
</html>

Congrats, you now have your first web page. Next step: learn CSS to style this page.