Skip to content
Laviyx Learn

Try

HTML course menu

Your First HTML Page: The Basic HTML Document Template

Write your first complete HTML page step by step: the DOCTYPE, html, head and body elements, the title, the charset and viewport meta tags, and a heading and paragraph. Includes a copyable HTML5 boilerplate.

Beginner5 min readUpdated
On this page

In the previous lesson you displayed a single heading. Real pages wrap their content in a standard template that tells the browser which version of HTML you use, which language the page is in, and how to handle text and small screens.

The complete template#

index.html (HTML)
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My First Page</title>
  </head>
  <body>
    <h1>Hello, world!</h1>
    <p>This is my first web page.</p>
  </body>
</html>

Save it as index.html and open it in your browser. Here is the result:

HTML
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My First Page</title>
  </head>
  <body>
    <h1>Hello, world!</h1>
    <p>This is my first web page.</p>
  </body>
</html>
Result

The title "My First Page" does not appear on the page itself. When you open your own file, look at the browser tab: that is where the <title> is shown.

Line by line#

LineMeaning
<!DOCTYPE html>Tells the browser this is a modern HTML document. Without it, browsers switch to an old "quirks mode" that renders some things differently.
<html lang="en">The root element that contains everything. lang="en" says the page is in English, which helps screen readers pronounce words and helps translation tools.
<head>Information about the page that is not shown in the page body.
<meta charset="utf-8">The text encoding. UTF-8 supports every language and symbol, such as é, ₹ and 😊.
<meta name="viewport" ...>Makes the page fit the width of phone screens instead of showing a zoomed-out desktop view.
<title>The text in the browser tab, in bookmarks and in search results.
<body>Everything that is visible on the page.

You will look at each part in more detail in Document Structure.

Indentation#

Notice how elements inside other elements are indented. Browsers ignore the extra spaces, but indentation makes it easy to see what is inside what. Most editors indent automatically; in VS Code, Format Document (Shift+Alt+F on Windows) tidies a whole file.

Common mistakes#

Practice#

Practice exercise

Create a page titled My Hobbies with the heading Things I Enjoy and two paragraphs, each describing one hobby. Check that the title appears in the browser tab.

Show solution
HTML
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>My Hobbies</title>
  </head>
  <body>
    <h1>Things I Enjoy</h1>
    <p>I play badminton every Sunday morning with my friends.</p>
    <p>I also like cooking, especially trying new curry recipes.</p>
  </body>
</html>
Result

Key takeaway#

Finished this lesson?