Skip to content
Tutorials Center
My learning

Topics

Lesson 3 of 122 · Getting Started

Your First Web Page

Set up a code editor, save your first .html file and open it in a browser. Learn the basic skeleton that every HTML document starts with.

Reading about HTML is useful, but the real learning starts when you build something. In this lesson you will create an HTML file on your own computer, open it in a browser and understand every line of the standard page skeleton.

Along the way you will pick up a few habits that professionals rely on every day: naming files so they work on any server, organizing a project into folders, saving with the right character encoding and declaring the language of your page. None of them is hard, and getting them right now saves you from confusing bugs later.

What you need

Only two tools, and both are free:

  1. A code editor. Any plain-text editor works, but a code editor colors your tags, completes them for you and spots typos. Visual Studio Code is a popular choice, and there are many good alternatives.
  2. A web browser. Chrome, Firefox, Edge or Safari, whichever you already use. It is worth installing a second one later so you can check your pages in more than one browser.

You do not need a web server, a hosting account or an internet connection. A browser can open HTML files straight from your own disk.

Avoid word processors. Programs such as Microsoft Word save hidden formatting alongside your text, which turns your HTML into gibberish for the browser. Even simple editors can trip you up: some save "rich text" by default. Always use a code editor, or a plain-text editor set to plain text.

Create a folder and a file

  1. Make a new folder somewhere easy to find, for example my-website in your documents or on your desktop.
  2. Open that folder in your code editor. Most editors have a File → Open Folder command, which shows all your project files in a sidebar.
  3. Create a new file inside it and name it index.html.

The .html ending tells your computer and the browser that the file contains HTML. The name index is a convention: web servers show index.html automatically when someone visits a folder without naming a file. So when your site is online, example.com/ and example.com/index.html show the same page.

Show file extensions. Windows and macOS hide endings like .html by default, which makes it easy to end up with index.html.txt by accident. Turn on "File name extensions" (Windows File Explorer, View menu) or "Show all filename extensions" (macOS Finder settings) so you always see the real name.

Naming files and folders

File names become part of your web addresses, so they need to follow a few rules. These rules are not enforced by HTML itself, but breaking them causes broken links and missing images once your site leaves your computer:

  • Use lowercase letters. Many web servers treat About.html and about.html as two different files. Your own computer might not, so a link that works on your laptop can fail online. Lowercase everywhere avoids the problem.
  • No spaces. A space in a web address has to be encoded as %20, which is ugly and easy to get wrong. Use hyphens instead: contact-us.html, not contact us.html.
  • Hyphens, not underscores. Both work, but hyphens are the common convention and search engines treat them as word separators.
  • Stick to letters, digits and hyphens. Avoid characters such as #, ?, &, % and accented letters. Several of them have special meanings in URLs.
  • Keep the extension. Pages end in .html, images in .png, .jpg, .svg and so on.

Good names: index.html, about.html, blog-post-1.html, images/team-photo.jpg. Risky names: My Page.HTML, photo#1.jpg, Über uns.html.

Organizing with folders

A small site can live in a single folder, but as soon as you add images and stylesheets it pays to group them. A typical beginner project looks like this:

TEXT
my-website/
├── index.html
├── about.html
├── images/
│   └── logo.svg
└── css/
    └── styles.css

Keep index.html at the top of the project folder: that is the page a server shows first. The way one file refers to another, for example images/logo.svg from inside index.html, is called a path. Paths get a full lesson of their own in File Paths.

The page skeleton

Type (or copy) this into index.html and save it:

HTML
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>My first web page</title>
  </head>
  <body>
    <h1>Welcome to my website</h1>
    <p>I built this page myself.</p>
  </body>
</html>

Typing it yourself, at least once, is worth the effort. You will notice the patterns faster than by copying.

Opening your page in a browser

There are several ways to open a local HTML file, and they all do the same thing:

  • Drag and drop index.html from your file manager into an open browser window.
  • Double-click the file. It opens in your default browser.
  • Press Ctrl + O (Cmd + O on a Mac) in the browser and choose the file.

You should see a heading and a sentence, and the browser tab will show "My first web page". Look at the address bar: it starts with file:/// instead of https://. That means the browser is reading the file straight from your disk rather than downloading it from a server.

Congratulations, you have made a web page.

file:// versus a server. Opening files directly is perfect for learning HTML. A few advanced features, such as some JavaScript modules and web workers, refuse to run from file:// for security reasons. When you reach those lessons, you can run a small local web server instead. Many code editors offer one as an extension.

What each line does

<!DOCTYPE html>

This first line is a declaration, not a tag. It tells the browser to use modern HTML rules ("standards mode"). Without it, browsers fall back to an old "quirks mode" that copies the bugs of the 1990s, and your layouts can behave strangely. It is not case-sensitive, so <!doctype html> works just as well. Always start with it.

<html lang="en">

The <html> element wraps everything else on the page. It is called the root element.

The lang="en" attribute declares that the page is written in English. It matters more than it looks:

  • Screen readers use it to choose the right voice and pronunciation. Without it, a French page might be read aloud with English rules, which is close to unintelligible.
  • Browsers use it to offer translation, pick suitable fonts and apply language-specific rules, such as where words can be hyphenated.
  • Search engines use it as a hint for which audience the page serves.

Use a standard language code: en for English, es for Spanish, de for German, tr for Turkish, ja for Japanese. You can add a region when it matters, such as en-US, en-GB or pt-BR. If one passage is in a different language, mark just that element: <p lang="fr">Bonjour tout le monde</p>.

The head holds information about the page that is not shown in the page area itself:

  • <meta charset="utf-8"> tells the browser which character encoding to use, so letters such as é, ß, ğ or emoji display correctly. Put it first inside the head, because the browser needs to know the encoding before it reads any other text.
  • <title> sets the text on the browser tab, in bookmarks and as the clickable headline in search results. Make it short and specific to the page.

You will add much more to the head later, such as a viewport setting for phones, a description and links to stylesheets. See The Head Element.

<body>

Everything visible goes inside the body: text, headings, images, links, buttons and so on. A page has exactly one body.

Experiment with the skeleton

Here is the same skeleton in a live editor. Try these changes one at a time:

  • Add another paragraph inside the body.
  • Change the heading text.
  • Put some text outside the body, after </html>, and notice that the browser still shows it. It quietly moves the text into the body for you.
The HTML page skeleton

Saving with UTF-8

Your file is stored on disk as bytes. The character encoding is the rule that maps those bytes to letters. UTF-8 is the encoding of the web: it can represent every character in every language, plus emoji, and nearly all modern editors save in UTF-8 by default.

Two things have to agree:

  1. The editor must save the file as UTF-8. Most editors show the current encoding in the status bar at the bottom of the window. If it says something else, such as "Windows 1252" or "ISO-8859-1", click it and choose "Save with encoding: UTF-8".
  2. The page must declare UTF-8 with <meta charset="utf-8">.

When they disagree, you get garbled text: café turns into something like café. That kind of mess almost always means a mismatch between how the file was saved and how it was read. The Character Encoding lesson explains what is going on under the hood.

UTF-8 handles every language

Every line displays correctly because the editor on this site works in UTF-8 and the page declares it. Notice the lang attribute on each list item: it tells assistive technology which language each greeting is in.

Indentation

You may have noticed that <head> and <body> are pushed in by two spaces, and the lines inside them by four. Browsers ignore this extra whitespace completely, but people do not. Indenting each level makes it obvious which elements sit inside which, and it will save you a lot of time when hunting for a missing closing tag.

Pick one style, two spaces is common, and stick to it. Most editors can indent for you automatically with a "Format Document" command.

Saving and refreshing

The everyday rhythm of writing HTML is simple:

  1. Change the file in your editor.
  2. Save it (Ctrl + S, or Cmd + S on a Mac).
  3. Refresh the browser (F5, or Cmd + R).

If a change does not appear, the file is almost always unsaved. Many editors show a dot or circle on the file's tab when it has unsaved changes. Turning on your editor's auto save setting removes this problem entirely.

Common first-page mistakes

  • Wrong file opened. You edited index.html in one folder but opened a copy from another. Check the path in the address bar.
  • Hidden .txt ending. The browser shows your tags as plain text. Rename the file so it really ends in .html.
  • Typos in tag names. <boyd> is not an error the browser reports. It simply treats it as an unknown element. Your editor's coloring usually reveals the typo.
  • Missing angle bracket. Leaving out a > can swallow the following text. If a chunk of your page disappears, look just before it.
Spot the mistakes

The second paragraph disappears because the browser reads <p This sentence vanished ...> as one opening tag with a lot of strange attribute names. Add the missing > after <p and the sentence comes back.

Check your understanding

Quick check · 5 questions

of 5 answered You scored / 5 · perfect!

  1. 1. Why should you avoid writing HTML in a word processor such as Microsoft Word?

    Word processors store their own formatting alongside your text. A code editor saves exactly the characters you type.
  2. 2. What is the purpose of <!DOCTYPE html> at the top of a page?

    Without the doctype, browsers fall back to "quirks mode", which imitates old, buggy behavior.
  3. 3. Which file name is the safest choice for a web page?

    Lowercase letters, hyphens instead of spaces and no special characters keep URLs simple and avoid case-sensitivity problems on servers.
  4. 4. Where does the text inside <title> appear?

    The title lives in the <head> and labels the page outside the page area itself.
  5. 5. Why does <meta charset="utf-8"> matter?

    The character encoding tells the browser how to turn the file's bytes into characters. The page language is set with lang instead.

Summary

  • You need only a code editor and a browser to write HTML; open local files by dragging them into the browser.
  • Name files in lowercase with hyphens, no spaces or special characters; the main page of a folder is index.html.
  • Every document starts with <!DOCTYPE html> followed by an <html lang="..."> element containing a <head> and a <body>.
  • The lang attribute helps screen readers, browsers and search engines handle your language correctly.
  • Save files as UTF-8 and declare it with <meta charset="utf-8"> first in the head.
  • The head describes the page; the body holds what visitors see.

Next: Viewing Source and Using DevTools, the browser tools that let you look inside any page, including your own.