Editors & Your First Page
All you need to build a web page is a text editor and a browser, and both are free. In this page you will set up Visual Studio Code, create your first HTML file, open it in a browser and learn a fast way to see your changes as you work.
Choosing an editor
You could write HTML in Notepad, but a code editor helps you with colours, auto-completion and error spotting. This series uses Visual Studio Code (VS Code), a free editor from Microsoft that runs on Windows, macOS and Linux and is popular with professional developers.
- Download VS Code from code.visualstudio.com and install it with the default options.
- Create a folder for your work, for example
Documents\web-projects\first-site. - In VS Code, choose File → Open Folder… and open that folder. Everything you create now lives inside it.
No laptop? Free online editors such as CodePen let you practise HTML in a phone or cyber-café browser. You can also use the Try it yourself buttons on these pages. For real projects, a laptop with VS Code is still the best setup.
Create your first file
In the VS Code Explorer panel, click the New File icon and name the file index.html. The name matters: web servers usually send index.html when someone visits a folder without naming a file, so it is the standard name for a site's home page. Use lowercase letters and no spaces in file names.
Now type the following (or use the Emmet shortcut described below):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Baraka's Page</title>
</head>
<body>
<h1>Hello, world!</h1>
<p>This is my very first web page. I built it in Kisumu.</p>
<p>My favourite foods are ugali, sukuma wiki and fish.</p>
</body>
</html>
Save with Ctrl+S (Cmd+S on a Mac). The browser tab will show the text "Baraka's Page", and the page shows a large heading followed by two paragraphs.
The Emmet shortcut
VS Code includes Emmet, a tool that expands abbreviations. In an empty .html file, type ! and press Tab (or Enter). VS Code writes the whole starting template for you, with the doctype, <html lang="en">, the two <meta> tags and <title>Document</title>. Change the title, then add your content between <body> and </body>.
Open it in a browser
Find index.html in your file manager and double-click it. It opens in your default browser. Look at the address bar: it starts with file:/// instead of https://, because the browser is reading the file straight from your disk. No server is involved yet.
Every time you change the file, save it and press F5 in the browser to reload.
Faster: the Live Server extension
Reloading by hand gets tiring. In VS Code, open the Extensions panel (Ctrl+Shift+X), search for Live Server and install it. Then right-click index.html and choose Open with Live Server. Your page opens at an address like http://127.0.0.1:5500/index.html, served by a small web server on your own computer, and the browser reloads automatically every time you save.
Inspecting your page
Browsers come with built-in developer tools. Press F12 (or right-click the heading and choose Inspect). The Elements panel shows your HTML as a tree; hover over a line and the matching part of the page is highlighted. This is how professionals debug layouts, and you will use it constantly.
Windows may hide file extensions, so a file you named index.html in Notepad can secretly become index.html.txt, and the browser shows the raw code instead of a page. Creating files inside VS Code avoids this. In File Explorer, turn on View → Show → File name extensions to check.
Practise: edit and break things
Open the Try-it editor above and experiment:
- Add another paragraph about your hobbies.
- Change
<h1>to<h2>(both the opening and closing tags) and notice the heading gets smaller. - Delete a closing
</p>tag. The page probably still looks fine, because browsers are forgiving. That is exactly why you must check your own code carefully: hidden mistakes can cause odd problems later with CSS and JavaScript.
To check your HTML for errors, paste it into the free W3C validator at validator.w3.org (choose "Validate by Direct Input"). It lists each problem with its line number.
Key points
- An HTML page is a plain text file ending in
.html; the home page is normallyindex.html. - VS Code's Emmet turns
!plus Tab into a complete starting template. - Double-clicking opens a file with
file:///; Live Server serves it locally and reloads on save. - Developer tools (F12) show the element tree and help you find problems.
Tip: use the ← and → keys to move between pages.
