Learn HTML. Build your first web page.

Learn to build a web page from a blank file. This free guide covers modern HTML with examples you can edit and exercises you can try in your browser. You don’t need to install anything.

15 lessonsFree, no sign-upBy Paul Sussex
Try the editor

HTML.net helped many people learn to build their first website. Its original tutorials are now unavailable. I used them as a reference for this updated guide, writing my own explanations, examples and exercises that you can try in the editor below.

Try the code

Change the code, select Run example and see what happens. Each lesson’s Try this example button loads its code here.

Preview

Your code stays in this tab and is not saved when you leave. Download it to keep your work. This practice space runs HTML and CSS only. Links to sections within an example work in the preview. Scripts, forms and links to other pages are disabled there.

Loading the starter preview.

Getting ready to write HTML

You need a browser and a plain text editor. Notepad on Windows works. On a Mac, switch TextEdit to plain text before saving. A code editor such as Visual Studio Code is useful once you want colour highlighting and help finding mistakes, but it is not a requirement.

Create a folder called my-first-website. Keep the page and its images together in that folder. Save your first file as index.html, with the file type set to all files if your editor offers that option. Check that it has not become index.html.txt.

Open the file in your browser. When you change the code, save the file and refresh the browser to see the result. You can also experiment in the practice editor above without installing anything. It runs HTML and CSS locally in your browser.

Try it yourself

Change the main heading in the practice editor, then select Run example. Change it again and run it a second time.

What HTML does, and where HTML5 fits

HTML describes the meaning and structure of a page. It identifies a heading, a paragraph, an image or a link so a browser can present that content. CSS controls its appearance. JavaScript adds behaviour such as a menu opening or a calculation updating.

A browser gives HTML a basic appearance even without CSS. That is why the unstyled examples here already have readable headings, lists and paragraphs. Start by getting that structure right before worrying about the design.

You may have seen older tutorials labelled HTML, XHTML and HTML5. For a new website, start with modern HTML. HTML5 introduced familiar features such as semantic page elements and native audio and video. HTML is now maintained as a Living Standard. You can learn its current features together without taking a separate HTML5 course after an older one.

Understanding elements and tags

An element often has an opening tag, some content and a closing tag. In <p>Hello there.</p>, the tags mark a paragraph and the words are its content. A closing tag includes a forward slash.

Elements can contain other elements. If a paragraph contains an emphasised phrase, close the inner element before closing the paragraph. This nesting makes the structure predictable for both browsers and people reading your code.

Some elements, including img, br and meta, are void elements. They do not contain content and do not have closing tags. Write <br>, not </br>. You do not need the XHTML-style trailing slash in modern HTML.

View and copy the code
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My first web page</title>
</head>
<body>
  <p>I like <strong>clear explanations</strong> and
    <em>time to experiment</em>.</p>
</body>
</html>

Try it yourself

Add a second paragraph. Put one meaningful phrase inside strong tags.

Show a hint

Keep the strong element inside the paragraph: <p>Start with <strong>one small change</strong>.</p>

Building a complete web page

The document starts with <!doctype html>, which tells the browser to use modern standards mode. The html element wraps the document. Its lang attribute identifies the language of the content.

The head holds information about the page. Set the character encoding to UTF-8, give the page a useful title and include the viewport setting so it displays at the device width on a phone. The title appears in the browser tab. It is different from the visible heading.

The body holds what people read and interact with. Put the page's main content in a main element. Indentation does not change the result, but it makes nested elements much easier to follow. Use this complete document as a starting point for the next lessons.

View and copy the code
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My first web page</title>
</head>
<body>
  <main>
    <h1>A little guide to Billericay</h1>
    <p>A place for my favourite local discoveries.</p>
    <h2>Start with a walk</h2>
    <p>Explore the High Street, then stop for a coffee.</p>
    <ul>
      <li>Bring your camera</li>
      <li>Look up at the old buildings</li>
      <li>Try somewhere new</li>
    </ul>
  </main>
</body>
</html>

Giving your content a clear hierarchy

Use a descriptive h1 for the main topic, h2 for its main sections and h3 for subsections within those sections. Pick the level for its place in the document, not for the size of the lettering. You can change the size with CSS later.

A p element marks a paragraph. A blank line in your source code does not create a new paragraph in the rendered page. HTML normally collapses repeated whitespace. Use separate paragraph elements rather than a run of line breaks to space out your writing.

Give each section a heading that explains what follows. This helps people scan the page and makes the document easier to navigate with assistive technology. Read the headings on their own to check that they explain the page.

View and copy the code
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My first web page</title>
</head>
<body>
  <main>
    <h1>Photographing your local High Street</h1>
    <h2>Choose a time</h2>
    <p>Early morning can give you quieter pavements.</p>
    <h2>Find a subject</h2>
    <h3>Shopfront details</h3>
    <p>Look for lettering, textures and reflections.</p>
  </main>
</body>
</html>

Try it yourself

Add another h3 and paragraph under Find a subject. Keep it at the same level as Shopfront details.

Adding emphasis and making lists

Use strong when something has particular importance and em when the emphasis changes how a sentence is read. They usually appear bold and italic, but their purpose is to convey meaning. Use CSS when you only want a visual style.

Use ul for a collection whose order does not matter, and ol for a sequence such as instructions. Each item belongs in an li. A nested list belongs inside the list item it expands.

For a small piece of computer code, use code. To preserve the spacing of a longer example, place it inside pre as well. To display a literal less-than sign in your page, write &lt;. Use &amp; when you need to display an ampersand reliably in text or code examples.

View and copy the code
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My first web page</title>
</head>
<body>
  <h1>Before you go</h1>
  <p><strong>Charge your battery</strong> before leaving.</p>
  <h2>A simple routine</h2>
  <ol>
    <li>Choose a subject.</li>
    <li>Take a photograph.</li>
    <li>Look at the result and adjust.</li>
  </ol>
  <p>The paragraph tag looks like <code>&lt;p&gt;</code>.</p>
</body>
</html>

Using attributes

Attributes provide extra information in an opening tag. They usually take the form name="value". For example, lang="en" identifies English and href="about.html" gives a link its destination.

An id identifies one element on a page. Keep each ID unique. A class groups elements for styling, and the same class can be used many times. An element can have several classes separated by spaces, such as class="card featured".

Use quotation marks around values and descriptive names. An attribute's meaning depends on the element. A link uses href; an image uses src. Boolean attributes such as required are enabled by their presence. Writing required="false" still makes a form field required.

View and copy the code
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My first web page</title>
</head>
<body>
  <section id="places" class="local-guide">
    <h1>Places to explore</h1>
    <p class="intro">Start with somewhere close to home.</p>
    <p class="intro">Notice something you normally walk past.</p>
  </section>
</body>
</html>

Adding images that work for everyone

An image uses src for its location and alt for a text alternative. Describe the relevant information in the image, in the context of your page. For a purely decorative image, use an empty alternative, alt="", so it can be skipped by screen readers.

Give an image its intrinsic width and height so the browser can reserve the right proportions before it loads. CSS can then make it responsive. Use an image sized appropriately for the job. Changing a large image's display width alone does not reduce its download size.

JPEG is useful for photographs, PNG for images needing lossless detail or transparency, and SVG for vector artwork. WebP and AVIF offer further compression options. Use your own photographs or images you have permission to use. This example uses my photograph of Cristis in Billericay.

If your image does not appear, check the file name, extension and folder. Letter case can matter on a web server even if the file worked on your computer.

View and copy the code
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My first web page</title>
  <style>
img { max-width: 100%; height: auto; }
figure { margin: 0; }
  </style>
</head>
<body>
  <main>
    <h1>A local shopfront</h1>
    <figure>
      <img src="https://susnet.co.uk/images/new-cristis-sign.webp"
        alt="Cristis shop sign in Billericay"
        width="800" height="534">
      <figcaption>A photograph by Paul Sussex.</figcaption>
    </figure>
  </main>
</body>
</html>

Try it yourself

Write a short figcaption of your own. Then try a narrower preview width to see the image resize.

Presenting data in a table

Tables are for information with relationships across rows and columns, such as opening times or a price comparison. They are not a page layout tool. Use CSS Grid or Flexbox to arrange a design instead.

A table contains rows marked with tr. Use th for header cells and td for data cells. A caption explains what the table contains. The scope attribute can identify whether a header applies to a row or a column.

In this example, the day names are row headers and the top cells are column headers. That makes their relationships clearer to someone using a screen reader. Do not rely on background colour alone to indicate what a cell means.

View and copy the code
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My first web page</title>
  <style>
table { border-collapse: collapse; }
th, td { border: 1px solid #777; padding: 0.75rem; text-align: left; }
  </style>
</head>
<body>
  <table>
    <caption>Example photography sessions</caption>
    <thead>
      <tr><th scope="col">Day</th><th scope="col">Time</th></tr>
    </thead>
    <tbody>
      <tr><th scope="row">Tuesday</th><td>10:00</td></tr>
      <tr><th scope="row">Thursday</th><td>14:00</td></tr>
    </tbody>
  </table>
</body>
</html>

Try it yourself

Add a third session. Keep two cells in its row, with a row header for the day.

Building a page with meaningful sections

Use elements that describe each part of your page. A header introduces a page or section. A nav groups major navigation links. A main contains the page's primary content, and a footer holds closing information.

An article is a self-contained piece such as a news story. A section groups a topic and will usually have a heading. A div is a neutral container when you need a wrapper without those meanings.

Semantic HTML gives browsers and assistive technology useful structure without extra workarounds. It does not automatically make a website accessible. Clear writing, keyboard access, meaningful labels and sufficient contrast still matter.

One visible main landmark is normally enough. Keep your main heading descriptive and put sections in an order that makes sense when read from top to bottom.

View and copy the code
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My first web page</title>
</head>
<body>
  <header>
    <p>My local notebook</p>
    <nav aria-label="Main navigation">
      <a href="#walks">Walks</a>
      <a href="#photos">Photos</a>
    </nav>
  </header>
  <main>
    <h1>Explore your neighbourhood</h1>
    <section id="walks"><h2>Walks</h2><p>Take the scenic route.</p></section>
    <section id="photos"><h2>Photos</h2><p>Bring a camera.</p></section>
  </main>
  <footer><p>Notes and photographs by me.</p></footer>
</body>
</html>

Introducing CSS

CSS applies visual rules to HTML. A rule has a selector that chooses elements and declarations that set properties. In p { color: #333; }, the selector is p, the property is color and its value is #333.

For a quick experiment, put CSS in a style element in your document's head. For a real site with several pages, an external stylesheet lets those pages share the same design. Save it as styles.css and add <link rel="stylesheet" href="styles.css"> in the head.

The example keeps text within a readable width, centres the main content and changes the heading colour. Try editing one value at a time so you can see what it controls. The companion CSS guide takes this further with spacing, typography and responsive layouts.

View and copy the code
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>My first web page</title>
  <style>
body { font-family: system-ui, sans-serif; line-height: 1.6; color: #202820; }
main { max-width: 40rem; margin: 3rem auto; padding: 1.5rem; }
h1 { color: #52634b; }
a { color: #365b38; }
  </style>
</head>
<body>
  <main>
    <h1>A little room to breathe</h1>
    <p>Design starts with readable content and thoughtful spacing.</p>
    <a href="#next">Keep exploring</a>
    <h2 id="next">Your next discovery</h2>
    <p>Small changes can make a page feel very different.</p>
  </main>
</body>
</html>

Try it yourself

Change the heading colour and the padding on main. Run the example after each change.

Putting your page online

A file opened from your own computer is not a public website. To share it, upload the HTML, stylesheet and image files to a web host. A small static site can use a static hosting service; an existing hosting account may offer a file manager or SFTP access.

Make sure index.html is in the folder your host serves publicly. Keep relative file paths intact. If your code expects images/shop.webp, the uploaded folder needs the same name and the image must be inside it.

Follow the host's current instructions for connecting a domain and enabling HTTPS. Use the public HTTPS address to test the site from another device. Check every page, link and image after uploading. Avoid putting passwords, private documents or service credentials anywhere in the public website folder.

HTML alone cannot securely process an enquiry form or store a customer's details. Those tasks need a suitable backend or form service. We have left working form submissions out of this beginner guide.

Checking your HTML and testing your page

Start by opening your page at a narrow width and zooming the browser to 200%. Is everything readable? Can you move between links and controls with the Tab key and see where the focus is? Does the page still make sense without its images?

Use the W3C HTML checker at validator.w3.org/nu/ to check a public URL, upload a file or paste your code. It can catch missing attributes, invalid nesting and duplicated IDs. Work through errors from the top, as one mistake can cause several later messages.

Validation is useful, but it does not prove a site is accessible, attractive, secure or ready for search. Test the content and behaviour too. A browser may repair broken markup in a way that makes it look acceptable while leaving the underlying document incorrect.

Before publishing, give each page a specific title, a useful main heading and a concise description in a meta name="description" element. Write these for the people deciding whether to visit.

Your first complete project

Put the pieces together by making a one-page guide to somewhere you know. Start with the complete document from lesson four. Add an introduction, two or three sections, a photograph you own, a list of useful tips and a link to a relevant external resource.

Keep the first design simple. Finish the content, check the heading structure and text alternatives, then add CSS. Test the result at a narrow width and use the HTML checker before sharing it.

If something breaks, reduce the problem. Check the last change, read the error and compare opening and closing tags. Make small changes and keep a working copy. Change the examples as you read so you can see what each part does.

For the next step, use the CSS guide to turn this working page into a responsive design. For more detailed reference, keep MDN's HTML documentation and the HTML Living Standard handy.

Try it yourself

Build your own local guide. Include a useful title, logical headings, one image with suitable alt text, a list and working links. Download the page and open it outside this editor.

HTML quick reference

<h1>…</h1>
The main heading of your page.
<p>…</p>
A paragraph of text.
<a href="…">…</a>
A link to a page, file or section.
<img src="…" alt="…">
An image and its text alternative.
<ul><li>…</li></ul>
An unordered list and an item.
<main>…</main>
The page’s primary content.
id="places" / href="#places"
A named section and a link to it.

Style your page with CSS

Use the CSS guide to style the page you’ve made, from choosing fonts to adjusting the layout for phones.

Learn CSS

I’m Paul, a web designer, photographer and filmmaker based in Basildon. If you’d like help with a business website, explore my web design work or tell me about your project.