{module 2}
Your tools: a browser and an editor
How the web works, and your tools20 min read
What you will be able to do
- Install Visual Studio Code and open your course folder in it.
- Show file extensions on your computer, and explain why
notice.htmlandnotice.txtopen differently. - Save a file in the editor, open it in the browser, change it and reload.
Why it matters
Tallinn Print House prints posters in Tallinn, Estonia. Kadri Tamm, the owner, wanted a small price page. Her assistant typed it in the plain text program that came with the computer and saved it as prices.html. When Kadri opened it, the browser showed every tag, angle brackets and all.
They spent an afternoon searching for a mistake in the HTML. There was none. The computer had quietly saved the file as prices.html.txt and hid the last part of the name. The browser did exactly what the name told it to do.
A web developer needs two tools: a browser to show pages, and an editor to write them. This lesson sets up the editor and shows you how a file's name decides what the browser does with it.
The idea
An editor writes plain text
A page is a file of plain text: letters, numbers and symbols, with no fonts or colours stored in it. A word processor is the wrong tool, because it saves much more than the letters you typed. An editor for code saves exactly what you type and nothing else.
This course uses Visual Studio Code, often called VS Code. It is free and runs on Windows, macOS and Linux.
Installing Visual Studio Code
Open the download page, https://code.visualstudio.com/download, in your browser.
Windows. Click the button for the User Installer. It needs no administrator password. Run the file it downloads, whose name starts with VSCodeUserSetup. Keep the choices the installer suggests. If it shows a page about the GitHub Copilot command, choose "Don't add the copilot command": this course does not use it. When it finishes, open Visual Studio Code from the Start menu.
macOS. Click the button for the .dmg file. Double-click the downloaded file to open it, then drag Visual Studio Code.app into your Applications folder. Open it from Applications by double-clicking its icon. To keep it in the Dock, Control-click its icon in the Dock and choose Options, then Keep in Dock.
Linux. On Ubuntu, Debian and similar systems, download the .deb file and install it with your software centre. On other systems, follow the steps for your system on the page "Visual Studio Code on Linux" in the VS Code documentation.
A folder for the course
Keep all your work for this course in one folder, so you always know where a file is.
- Windows. Press the Windows logo key and E to open File Explorer. Go to Documents and select New, then Folder. Type
free-trackand press Enter. - macOS. Open a Finder window and go to Documents. Choose File, then New Folder, or press Shift-Command-N. Type
free-trackand press Return. - Linux. In your file manager, make a folder called
free-trackin your home folder.
Now open it in VS Code. Choose File, then Open Folder..., select free-track and click Select Folder (Windows) or Open (macOS). VS Code asks whether you trust the authors of the files in this folder. You are the author, so choose Yes, I trust the authors.
Files and file extensions
A file name usually ends with a full stop and a few letters, such as .html or .txt. That ending is the file extension. It does not change what is inside the file. It tells programs what kind of file it is, and so what to do with it. A browser shows a .txt file as plain text, exactly as typed. It reads a .html file as HTML and draws a page.
Windows and macOS hide extensions unless you ask to see them. A developer always wants to see them:
- Windows 11. In File Explorer, select View, then Show, then File name extensions.
- Windows 10. In File Explorer, open the View tab and, in the Show/hide group, tick File name extensions.
- macOS. In the Finder, choose Finder, then Settings, click Advanced, and tick Show all filename extensions.
Linux file managers show the whole name.
Worked example
You will make the same two lines into two files and open both in the browser.
In VS Code, click the Explorer view in the bar on the left, then the New File... button. Type notice.txt and press Enter. A new, empty tab opens. Type these two lines:
<h1>Tallinn Print House</h1>
Posters printed while you wait, from $12.Save the file with Ctrl+S (Cmd+S on a Mac). While a file has unsaved changes, its tab shows a dot. The dot goes away when the file is saved.
Make a second file, notice.html, and type exactly the same two lines in it. Save it too.
<h1>Tallinn Print House</h1>
Posters printed while you wait, from $12.Now open each one in the browser. In your file manager, open the free-track folder and double-click the file. Or, in Chrome or Edge, press Ctrl+O (Cmd+O on a Mac) and choose the file. The address bar starts with file://, because the page comes from your own disk and not from a server.
This is what the browser shows for notice.txt:
<h1>Tallinn Print House</h1>
Posters printed while you wait, from $12.And this is what it shows for notice.html:
Tallinn Print House
Posters printed while you wait, from $12.The insides of the two files are identical, character for character. Only the extension differs. For the .txt file the browser shows every character. For the .html file it reads <h1> and </h1> as instructions, shows the words between them as a large, bold heading, and hides the tags. Lesson 3 explains tags properly.
Change, save, reload
The browser shows the file as it was when the page was opened. To see a change, you do three things in order:
- Change the file in VS Code.
- Save it.
- Reload the page in the browser with F5 or Ctrl+R (Cmd+R on a Mac).
Try it: change $12 to $14 in notice.html, save, and reload.
Common mistakes
A hidden second extension
Kadri's assistant saved a file that looked like prices.html. With extensions shown, its real name appears: prices.html.txt. Here is what the browser shows:
<h1>Poster prices</h1>
A2 poster $12. A1 poster $20.Only the last extension counts, and it is .txt. So the browser shows the text as typed. The HTML is correct. To fix it, show extensions, then rename the file to prices.html. In VS Code, right-click the file in the Explorer and choose Rename. Then the browser shows a page:
Poster prices
A2 poster $12. A1 poster $20.A change that does not appear
You change a price, reload, and the page still shows the old one. The usual cause is that the file was not saved. Look at the tab in VS Code: a dot means unsaved changes. Save, then reload. If you would rather not think about it, choose File, then Auto Save, and VS Code saves a moment after each change.
The file opens in the editor, not the browser
After you install VS Code, double-clicking a .html file may open it in VS Code again. Nothing is wrong with the file. Open it from the browser instead, with Ctrl+O (Cmd+O on a Mac), or drag the file onto the browser window.
Think it through
Aiko, a learner, wants a second file for the print house, hours.html, that shows the heading "Opening hours" and the line "Monday to Friday, 9:00 to 18:00". She wants to see it as a page.
Understand. In: two lines she types. Out: a page in the browser with a heading and a line of text, and no tags visible.
Break down. Make the file in the right folder with the right name. Type the lines. Save. Open it in the browser.
Plan. Use New File... in the Explorer, so the file lands in free-track. Copy the shape of notice.html: the heading inside <h1> and </h1>, then the plain line.
Build. She makes hours.html, types the two lines and presses Ctrl+S. The dot on the tab disappears.
Test. She opens it with Ctrl+O. The heading is large and bold and no tags show: the case she expected. Then an odd case: she renames a copy to hours.txt and opens that. The tags show, just as the lesson said.
Reflect. The name of the file did as much as its contents. From now on she checks two things before she looks for a mistake in the HTML: the extension, and the dot on the tab.
At work
A good question says what you expected and what happened instead. Either half alone is not enough. "It shows the tags" does not say what should have happened. "I want a heading" does not say what went wrong.
Here is the message Kadri's assistant could have sent:
I expected
prices.htmlto open as a page with the heading "Poster prices". Instead, the browser shows the text exactly as I typed it, including<h1>and</h1>. The address bar ends inprices.html.txt.
The reader can compare the two halves and see where the fault is. The last sentence, copied from the screen, answers the question before anyone asks it.
Your tasks
Task 1: Install and open your folder
Install Visual Studio Code, make the free-track folder and open it in VS Code with Open Folder....
You are done when the Explorer view in VS Code shows FREE-TRACK at the top, with no files in it yet.
Task 2: Show extensions
Follow the steps for your system to show file extensions.
You are done when your file manager shows the names of files you already have with their extensions, such as .pdf or .jpg.
Task 3: One text, two files
Make notice.txt and notice.html with the same two lines, but use a business you know in place of the print house. Open both in the browser.
You are done when the .txt file shows its tags and the .html file shows a heading without them.
Task 4: Predict, then check
Add a third line, <h1>Open every day</h1>, to both of your files, and save them. Before you reload either one, write down what you expect each to show, and why. Then reload both.
You are done when you have written your two predictions and what really happened, and one sentence that explains any difference.
Recap
- Write pages in an editor, such as VS Code, that saves plain text and nothing else.
- Keep the course in one folder, and open that folder in VS Code.
- The extension tells the browser what a file is:
.txtis shown as typed,.htmlis drawn as a page. - Show file extensions, so that a hidden
.txtcannot fool you. - Change, save, reload. A dot on the tab means the change is not saved yet.
Go deeper
- VS Code: Download has the installers for every system.
- VS Code on Linux gives the steps for each family of Linux systems.
- Microsoft: Common file name extensions in Windows shows how to see extensions in File Explorer.
- Apple: Show or hide filename extensions on Mac shows the same in the Finder.
- MDN: Dealing with files explains how to name and organise the files of a website.