← Back to all topics

HTML GUIDE · START HERE

Build Your First Webpage

Go from an empty folder to a page you can open, style, organize, check, and publish. Start with HTML and CSS; explore larger file structures and optional JavaScript when you are ready.

The files and tools at a glance

ItemWhat it meansWhen to use it
index.htmlThe HTML document: content and meaning.Start here. Hosting services commonly use this filename for a folder’s default page.
styles.cssA stylesheet: colors, spacing, fonts, and layout.Add when you want to change the appearance. HTML loads it through a link element.
script.jsAn optional JavaScript file: programmable behavior.Use later for behavior beyond HTML’s built-in features. A basic page needs no JavaScript.
Code editorAn application for writing plain-text source files.Use VS Code or another text editor to create and save your files.
BrowserAn application that reads and displays the page.Open the HTML file and refresh after saving changes.
Relative pathA location starting from the current file’s folder.Use to connect your own pages, stylesheets, and images.
Git / GitHub / PagesGit records changes; GitHub hosts a repository; GitHub Pages hosts the website.Use when you want version history and a public address other people can visit.

1. Create a folder and your first file

Create a folder called my-website somewhere you can find it again. In VS Code, choose File → Open Folder and open it. In the Explorer sidebar, use New File to create index.html. You can also right-click the folder to find New File and New Folder.

my-website/
└── index.html

The part after the final dot is the file extension: .html identifies an HTML file, .css a stylesheet, and .js JavaScript. Keep names lowercase and avoid spaces while learning.

Check the full filename. index.html.txt is a text file with the wrong final extension. Enable filename extensions in your file manager if they are hidden. Use a plain-text editor rather than a word processor.

2. Write the starting HTML

Paste this entire document into index.html. The head contains settings, resource references, and the browser-tab title. The body contains the visible page. Save with Ctrl+S on Windows/Linux or Command+S on macOS.

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My First Page</title>
</head>
<body>
  <h1>Hello, I’m Nikki!</h1>
  <p>I am learning to build webpages.</p>
</body>
</html>

Browser output

The doctype requests modern HTML handling. Lang declares English, charset declares UTF-8, and viewport supports mobile layouts. Title names the browser tab; h1 names the visible subject. See Document Structure for a closer explanation.

3. Open, edit, save, and refresh

  1. Find index.html in your file manager and open it with your browser. You can also drag the file into a browser tab.
  2. Return to your editor and change the paragraph to I made this page myself.
  3. Save the HTML file.
  4. Refresh the browser tab to load the saved changes.

Opening a file usually gives you a file:/// address. That page is on your computer. Sending someone that address does not give them a public website.

Editing and viewing are separate actions: the editor changes the source file, and the browser displays the saved version. Keep both open. No installation, build command, or local server is needed for this simple HTML-and-CSS page.

4. Add a separate stylesheet

In the same folder, create styles.css. Put the following CSS in that file and save it. CSS uses selectors and declarations rather than HTML tags: body selects the page body, and color sets text color.

my-website/
├── index.html
└── styles.css

styles.css

body {
  margin: 0;
  padding: 20px;
  background: #f0f7f7;
  color: #24343d;
  font-family: Arial, sans-serif;
  line-height: 1.6;
}

h1 {
  color: #176775;
  font-size: 26px;
}

Now add the stylesheet link inside the HTML head. Here is the complete updated HTML so you can see its exact position. The link’s rel identifies a stylesheet and its href gives the file location.

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>My First Page</title>
  <link rel="stylesheet" href="styles.css">
</head>
<body>
  <h1>Hello, I’m Nikki!</h1>
  <p>I am learning to build webpages.</p>
</body>
</html>

Browser output

The preview isolates the example from this guide’s own styles. Your separate CSS file produces the same styling when linked correctly. Save both files and refresh. Margins create space outside a box; padding creates space inside it. Font-family selects a font, line-height spaces lines, and background sets the background color.

5. Know where each kind of code belongs

ItemWhat it meansWhen to use it
Inside <head>Page settings and resource references.Place title, metadata, and the external stylesheet link here.
Inside <body>The content visitors read and use.Place headings, paragraphs, images, links, and controls here.
In styles.cssCSS rules without enclosing style tags.Write selectors and declarations for the linked page.
In script.jsJavaScript statements without enclosing script tags.Only create this file when you need programmable behavior.

HTML loads the other resources; they do not discover one another just because they are nearby. The filenames do not have to match: index.html can load styles.css and script.js.

Browser opens index.html
                ├── link href → styles.css → appearance
                ├── img src   → image file → visual content
                └── script src → script.js → optional behavior

6. Compare ways to organize a website

Start with the simplest arrangement that fits the page. Moving files into folders is optional; it does not make the browser understand them differently. Update their paths whenever you move them.

One HTML file

A tiny demonstration can put CSS inside a style element in head. JavaScript can go inside a script element, but neither is required. Separate files become easier to reuse as a site grows.

my-website/
└── index.html

Separate files beside each other

This is a straightforward beginner setup. The js file is optional. Delete its script reference if you are not using it.

my-website/
├── index.html
├── styles.css
└── script.js       (optional)

Folders for assets and additional pages

CSS, JavaScript, and images each get their own folder. About gets a page folder containing its own index.html. Create folders in the Explorer sidebar, then create or move the files inside them.

my-website/
├── index.html
├── about/
│   └── index.html
├── css/
│   └── styles.css
├── js/
│   └── script.js   (optional)
└── images/
    └── profile.jpg

This structure is an alternative to the flat setup above. A folder called images does not create a picture: add an actual image file and use its real name. Another valid arrangement puts about.html beside the homepage instead of creating an about folder.

7. Connect files from the right folder

In the folder-based setup, the homepage starts at the project root, while the About page starts one level deeper. ../ means “go up one folder.” Paths use forward slashes, including on Windows.

ItemWhat it meansWhen to use it
Homepage stylesheetFrom index.html: css/styles.css.Go into css from the project root.
About stylesheetFrom about/index.html: ../css/styles.css.Go up to the project root, then into css.
Homepage → AboutUse about/index.html.Go into the about folder.
About → HomepageUse ../index.html.Go up one folder and load the homepage.
About imageUse ../images/profile.jpg.Go up one folder, then into images.

Inside the homepage’s head

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

Inside the About page’s head

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

Match spelling, capitalization, and extensions exactly. Avoid a leading slash for this GitHub Pages project: /css/styles.css starts at the domain root and skips the /html-guide/ project prefix. For URLs inside an external CSS file, relative paths start from that CSS file’s location.

Optional: where JavaScript fits

Keep this section for later if you are still learning HTML. JavaScript adds programmable behavior, such as filtering results. Ordinary links, form controls, and expandable details already work through HTML. Java and JavaScript are different languages; a browser script file uses .js.

For the folder-based setup, this HTML reference belongs in the homepage’s head, after the stylesheet link. Only include it once js/script.js exists.

<script src="js/script.js" defer></script>

Src gives the script location. Defer lets this external script run after the HTML has been parsed, so page elements are available. From the About page, the path would be ../js/script.js. Write JavaScript statements inside the file without script tags.

This walkthrough does not execute JavaScript or require a script file. You can build and publish the entire HTML-and-CSS example first.

8. Find and fix common problems

ItemWhat it meansWhen to use it
Your edit does not appearThe browser may still show the previous saved file.Save in the editor, confirm you opened the correct file, then refresh.
The page has no custom stylingThe CSS reference may be missing or incorrect.Check that link is in head, rel is stylesheet, and href matches the actual file location.
An image is missingSrc may point to a missing file or wrong path.Confirm the image exists, check capitalization and extension, and resolve the path from the HTML file.
A link opens an error pageHref may lead to a file that does not exist.Count folders from the current page and check the destination filename.
Content appears in the wrong placeTags may be missing, misplaced, or incorrectly nested.Match opening and closing tags, and close inner elements before their containers.
Local changes are missing onlineThe published version may not contain your latest commit.Check that you pushed and that the GitHub Actions deployment finished successfully.

9. Use the browser’s developer tools

  1. Right-click a visible heading and choose Inspect (the wording can vary by browser).
  2. Find the selected heading in the Elements or Inspector panel. This view shows the browser’s interpreted HTML.
  3. Look at Styles or Rules to find the CSS affecting that element. A crossed-out declaration is being overridden.
  4. If a resource is missing, open Network and reload the page. Look for failed CSS or image requests; a hosted missing file commonly returns 404.

You can temporarily edit text or styles in developer tools to understand a result. Those edits normally disappear on reload and do not save back to your project. Make the lasting change in your editor, save, and refresh.

10. Check that people can use the page

These are starting checks rather than a complete accessibility audit. See Links and Images, Page Structure, and Forms for related HTML.

11. Understand local files and a live website

A local file lives on your computer. Hosting serves saved files over the internet at an HTTP or HTTPS address. A GitHub repository stores the source and its history; GitHub Pages publishes the web files. They are separate parts of the process.

This guide already has a repository and a GitHub Actions publishing workflow. For future updates to this guide:

  1. Edit and save the relevant files, then check them locally.
  2. Review changes with git diff and check filenames with git status.
  3. Stage the files you intend to publish and commit them with a short explanation.
  4. Push the commit to main on GitHub.
  5. Open the repository’s Actions tab and wait for “Publish HTML Guide” to finish successfully.
  6. Open the public website and check the changed page. Saving locally alone does not update the live site.

Example update commands for an existing clone of this guide

git status
git diff
git add index.html
git commit -m "Update homepage introduction"
git push origin main

Run these commands in the guide’s project folder after making that example edit. Replace index.html with the actual files you changed. Git add stages selected changes; commit records a local snapshot; push uploads committed changes. If your branch is behind GitHub, synchronize it and resolve any conflicts before pushing.

These commands update an already configured repository. A brand-new website first needs a repository, an initial commit, and GitHub Pages configuration. This guide’s publishing workflow copies an explicit list of website folders; add a new folder to that workflow when adding a new section.

View this guide’s repository · Check publishing runs

Further reading

Study questions

Think of your answer before opening each explanation.

Why do I start with index.html?

It is a common default filename for a folder’s main page. The .html extension tells tools what kind of file it is.

Where do visible headings belong?

Inside body. Head contains settings, the tab title, and resource references.

Does saving the CSS automatically refresh my browser?

Not when simply opening files without a live-reload tool. Save, then refresh the browser yourself.

Do HTML and CSS need the same filename?

No. The HTML stylesheet link points to the CSS file by its actual path.

When do I need JavaScript?

When you need programmable behavior beyond HTML’s built-in features. A basic HTML-and-CSS page does not need it.

Why does the About page use ../css/styles.css?

It starts inside the about folder. The ../ goes up to the project root before entering css.

Does making an images folder create an image?

No. Put an actual image file in it, then reference its exact name and extension.

Will an edit made in Inspect change my saved file?

Normally no. Developer tools edits are temporary. Make permanent changes in your code editor.

What should I check when CSS fails to load?

Check the stylesheet link, the real filename, the path from the HTML page, and failed resource requests in developer tools.

Is my file:/// address a public website?

No. It points to a file on your own computer. Publish through a hosting service to obtain a public address.

What is the difference between commit and push?

Commit records a local snapshot. Push uploads committed changes to the remote repository.

Does a successful push guarantee the site has updated?

No. Wait for the publishing workflow to succeed, then verify the live page.