Build a webpage from scratch with HTML

(If you already know HTML and CSS, try this page!)

HTML is the language that web browsers (like Firefox, Chrome, and Safari) understand. It’s a markup language, meaning you annotate content with it so that the browser treats that content in different ways. (HTML stands for hypertext markup language, if you’re curious.)

It’s not too hard to learn, and it’s fun! As always, the hardest thing about this tutorial will be arranging windows on your screen so that you can see everything at once! In one browser window or tab, leave this tutorial open so that you can refer to it as you proceed.

A sidebar on web accessibility: The principles you’ll learn today will create a website that is accessible to people using screen-reading software. But as you progress in your web development, you’ll want to read more explicitly about accessibility. These are the latest “gold standard” guidelines for accessibility, created by the W3C Web Accessibility Initiative.

Create a folder to store your web documents

A folder called "my_website."

Putting all your website documents in one place will make it easier to stay organized. Create a new folder somewhere on your computer, preferably somewhere easy to find. You can give your folder any title you like. When you’re dealing with code, though, avoiding spaces in file names often makes them easier to find.

Get set up

The Atom interface, showing a blank text document.

Download Atom and double-click it to open it. When you open Atom for the first time, three tabs will appear in the window. Please close all the tabs except for the one called “untitled.”

Atom is a (free) text editor, which is the name for the kind of program that you type code into. Just like Microsoft Word, it displays the text that you type. But unlike Microsoft Word, it doesn’t (invisibly) surround your text with formatting information. So never use Microsoft Word for your code! Instead, use Atom or one of the many alternatives, like Sublime.

Believe it or not, a plain text editor (like Sublime) and a web browser (like Chrome, Safari, or Firefox) are all you really need to build even the fanciest webpage!

Enter the document declaration and a little bit of text

A text document open in Atom, alongside a browser displaying the same code.
The text won’t look all beautiful and pink like it does in this image until you save your Atom text file as an HTML document.

In this step, we’ll type our first HTML code. This is what you’ll type:

<!DOCTYPE html>

<html>

<head>

</head>

<body>

<p>Welcome to my webpage!</p>

</body>

</html>

And here’s what it all means:

document declaration gives instructions to the web browser (like Safari or Firefox) for how to handle the document you’ve created. Luckily, they’re easy to make. Just type

<!DOCTYPE html>

at the very top of the document.

Then press return and type in

<html>

to tell the browser to expect HTML in the document that follows. Then skip a few lines and close your html tag by typing

</html>

(Your browser won’t care about spaces and returns inside the header.)

It’s considered good practice to divide up your webpage into head and body sections. Special instructions for the browser (if you have any) go in the head section. Content goes in the body section.

To make these sections, press return and enter

<head>

somewhere inside your opening and closing <html> tags.

After you create your head tag, leave a line or two blank and close your head tag by typing

</head>

Now make the body section. Below your <head> tag, type

<body>

Then skip a few lines and type

</body>

Let’s put some text in, too, so we have something to look at. Type

<p>Welcome to my webpage</p>

after your opening body tag and before the closing body tag. Perhaps you remember what <p> stands for: paragraph

Save your document to the folder you created in the first step. Name it index.html. By default, web browsers will look for an index.html file to display first.

View your document in your web browser

Code editor open in one window and browser open in the other.
To display your index.html file in a web browser, simply double-click it.

Leave your Atom document open and navigate to where you saved your index.html file. Double-click the icon for the file you saved. By default, that file should open up in a browser.

Now you should have index.html open in two different ways: 1) as a webpage and 2) as a text file, displayed in Atom.

Arrange your windows so you can see the index.html open as a text document and as a webpage, simultaneously.

On your text document, alter the text between the paragraph tags so that it says something different and save the document. Now click Refresh on your web browser. The text on the webpage should show the new text you’ve saved.

Add a header

Displaying a header by opening and closing h1 tags.

By default, headers instruct browsers to treat text inside the tags differently, to signal that it’s important. Add a header to your page by putting some text in

<h1>

tags, somewhere above your paragraph tags. (Remember to both open and close them.) Save the document and refresh your browser. You should now have a header on your page! Looking good.

You can also use

<h2>

tags, which are a bit smaller, and

<h3>

tags, which are smaller still, all the way to

<h5>

tags. Experiment with different-sized headers, saving and refreshing as you go.

How links work

Links work by opening a tag with "a href," inserting the link in quotation marks, closing the opening brackets, typing the text of your link, and then closing the a tag.

What’s a webpage without a link? They work like this:

<a href="www.google.com">text of your link</a>

In the example above, www.google.com is the URL to which you want to link and text of your link is the text that actually appears as a hyperlink.

Create a link on your page

A link displayed in the code editor and on a webpage.

Try it yourself by creating a new paragraph (using the opening and closing <p> tags) and creating a link within your new paragraph. Save your document, refresh your browser and test your link!

How images work

Images can be displayed either by entering a path in the img tag or by linking to an image on another site.

You can link to an image in one of two ways. If there’s an image out there on the Web that you’d like to embed on your page, you can grab the link to the image by right-clicking on the image and clicking Copy Image URL. Then you can embed the image by pasting the link, as above.

If you have an image on your computer that you’d like to use, you can save it in the same folder where your html file is saved and link directly to it by entering the file name, as above.

(When you enter the file name in an image tag, you’re actually providing a path to an image: that is, telling your browser where to find the image in order to display it. Because you’ve saved your image in the same place as your HTML document, you can just type the name of the file. Read more about paths here.)

You should also provide “alt text” for your image: a brief description of an image for people who are using text-to-speech readers or in case your image breaks. The alt text won’t be displayed unless the image breaks, but a person using a text-to-speech reader will be able to hear it. You can read more about writing good alt text here.

Add an image

Image tag created in the code and displayed in the browser.

Add an image to your webpage using one of the two methods from the previous step.

Add some emphasis

Em and strong tags created in the code and displayed in the browser.

Sometimes you want to highlight particular text on your page, to indicate that the browser should treat it differently. Common tags for this are

<em>

(which stands for emphasis; by default, your browser will italicize the text inside this tag) and

<strong>

(by default, your browser will bold the text inside this tag). For example:

<p>My students are <em>excellent</em> and <strong>awesome</strong>!</p>

Create more text and experiment with emphasis and headers. Just remember to always close those tags!

But wait! No one can see your page!

A website displayed via a link to a local file.

If you look closely at the URL on your webpage, you’ll see that it looks funny: it starts with

/

not

http://

That’s because you’re working on your file locally, meaning just on your own computer. No one else can see your webpage at the moment.

In order for other people to see your file, it has to be hosted on a server, meaning moved to a special computer whose job is to broadcast files to the internet. You don’t have a server yet, but you will in the fourth tutorial of today!

Before we get to that, though, let’s look at how you can make your page look more exciting.