How to create an HTML page from scratch

To create an HTML file, save a plain text file with the .html extension, such as index.html, and double-click it to open the page in your browser. Steps for Windows, Mac, VS Code, and phones come first, then working code and a CSS link.

What you need: Notepad or VS Code

HTML doesn't require any special software — even plain Notepad on Windows or TextEdit on Mac works. But for a more comfortable workflow, a code editor helps:

  • Notepad / TextEdit — works, but no syntax highlighting or suggestions. Fine for a first try.
  • VS Code — free, highlights tags, suggests closing elements, shows errors. The recommended option.

The key rule: the file must be saved with a .html extension, not .txt.

How to create an HTML file on Windows, Mac, in VS Code, or on a phone

Pick the way that fits your device.

Windows: Notepad

  1. Open Notepad and choose File → Save as.
  2. Set "Save as type" to "All files", or Notepad may add .txt.
  3. Name the file index.html, check that the encoding is UTF-8, and click Save.

Mac: TextEdit

  1. Create a document and choose Format → Make Plain Text. Without this step, TextEdit saves formatting along with your text.
  2. Choose File → Save and name the file index.html.
  3. When TextEdit asks about the extension, click Use .html.

VS Code

  1. Open your project folder with File → Open Folder.
  2. Create index.html with the New File button in the file panel.
  3. Type ! and, when the suggestion appears, press Tab to insert a page skeleton.

On a phone, or without installing anything

Open the online HTML editor, paste the code from "Your first code", and tap Download. The file should save as result.html, though on a phone the result depends on the browser.

If the file doesn't open as a page

  • The file has a Notepad icon or opens as text: it's probably named index.html.txt and Windows is hiding the extension. Turn on "File name extensions" in File Explorer, then rename the file.
  • The browser shows tags or stray symbols instead of a page: the file wasn't saved as plain text. Create it again using the steps above.

Your first code

Paste the basic page skeleton into your new index.html (if VS Code already inserted one, replace it with this code):

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>My page</title>
</head>
<body>
  <h1>Hello, world!</h1>
</body>
</html>

Save the file and open it directly in a browser (double-click the file) — that's enough, no server needed.

Adding CSS

Create a file named styles.css in the same folder and link it inside <head>:

<link rel="stylesheet" href="styles.css">

Start styles.css with a simple rule:

body {
  font-family: sans-serif;
  max-width: 700px;
  margin: 0 auto;
}

Project file structure

A simple site only needs one folder with this structure:

my-site/
  index.html
  styles.css
  images/
    photo.jpg

Paths in HTML are written relative to the location of index.html, e.g. images/photo.jpg.

Common beginner mistakes

  • A forgotten closing tag — browsers often "forgive" this, but the layout can still break.
  • The file was saved as index.html.txt — check the extension in the file properties.
  • An incorrect path to CSS or an image (letter case matters on most servers).
  • Special characters show up as garbled text — a missing <meta charset="UTF-8">.
▶ Open in HTML Editor ⇩ Download the example .html

Related tools