If you are a web dev novice and want to get started with the exciting world of web design, you’ve probably heard of HTML, which is the foundation of every web page online. Any successful web developer or designer must have a strong understanding of HTML.
We will discuss the basics of HTML that you’ll use throughout your web dev career. No prerequisite knowledge of programming is required, but to be most successful with this article, a basic understanding of programming is helpful. For a quick introduction or refresher, check out The Absolute Beginner’s Guide to Programming.
Today we will cover:
Imagine a document that you would create in a word processor. That document will usually use different font sizes to indicate sections of the text, such as headers, main content, footers, table of contents, etc. HTML is the process of building that document and setting the sizes of our text.
HTML provides a website’s structure and layout. We define that structure using various elements. But in order for a browser to appear how we want it, it must be explicitly told what each piece of content is. HTML is how we communicate and tell a computer how to render. The computer can interpret our HTML elements and translate them onto the screen.
Explore HTML on your own.
You can view the HTML source code of any website by right clicking on a rendered page and selecting “View Source”. This will open a page that details the HTML foundations of that site. Try it out with this article!
Now that we know what HTML is, let’s briefly introduce a few key terms before moving onto a step-by-step guide. You will use these basics throughout your entire web dev career!
An element is an individual component of an HTML document that represents the semantics of that page. For example, the
title element translates to the title of a page.
Semantics refers to the meaning of a particular element. Syntax refers to the structure of a programming language.
To create an element, we use tags. Think of these as descriptors for each piece of content you want on your page. Most tags are quite self-explanatory.
<p>: used to describe a paragraph
<img>: add an image
<h1>: set the text to the largest size heading
<a>: an anchor will create a hyperlink to other HTML files
To use tags, we wrap the content between an opening and closing tag. The closing tag uses the forward slash
/, while the opening tag does not. HTML tags are case not sensitive so
<P> is the same as
<p> This is a paragraph element. </p>
You can nest HTML elements when you want to apply multiple tags. Say you wanted to make a paragraph that is also bold. You could write the following HTML code:
HTML attributes provide additional information about our elements. Think of these like properties of an element. Attributes are placed in the opening tag, use the
= sign, and wrap the attribute value in quotation marks
Attributes can do all sorts of things to our elements such as embed images, add color, declare the language of a page, or add a title. For example, we can add color to our text using the following format.
Note: You can add color using Hex color codes (for specific colors) or one of the 140 text color names built-into HTML.
One of the most common uses of attribute is hyperlinking. We can connect any HTML page to another HTML page using an anchor tag. The
href attribute will create a connection between the two sites.
Headings are how we specify the difference between the main header and sub-headers. The HTML standard has six text heading elements, appropriately named
h1 (the largest) through
h6 (the smallest).
Note: Headers are used to represent text semantically. This is different than specifying font size. We use CSS to change font size.
If we want to list items, either as a bulleted of numbered list, we use the
<li> tag. We can either create an unordered list (bulleted) or an ordered list (numbered).
<ul>tag and the nested
<li>tags for teach item.
<ol>tag and the nested
<li>tags for teach item.
We can add images to our webpage using the
<img> tag. We need to add a
src attribute that contains a file path to that image. You will also include an
alt attribute, which provides an alternative text description in case the image does not load.
In the example below, we also defined two
class attributes. The class attribute is used to identify specific elements with an identifier. This makes it possible to use an elements in a later part of our code. An element can have multiple class values, such as a title and a caption, as we use below.
Note: The image tag does not use a closing tag.
We can add tables to a webpage by translating a table’s data into row and columns. Each row/column pair will have a piece of data associated with it called a table cell. So, how do we build a table in HTML?
First, we declare an HTML table using the
<table> tag. Then, we add rows to our table with the
<tr> tag. From there, we specify the cells with the
<table> <tr> <td>Column 1</td> <td>Column 2</td> <td>Column 3</td> </tr> </table>
Take a look at this example below, but note that the table is not stylized at all. It will only list the data as it is provided. If we want to add style to the table (background color, padding, borders, etc.), we must use the language CSS.
Now that we know the terms of HTML, let’s discuss the basics of formatting. We will look at a basic HTML file before discussing each part below.
The first line,
<DOCTYPE! html>, is called the doctype declaration. This indicates to browser what HTML version the file is written in. This file indicates that it is written in HTML5.
On the second line, we write the opening
<html> tag to indicate the root element. From there, we branch off into other elements in a tree-like structure. To properly define an HTML file, we must place
<body> elements within that root.
<head>element contains supporting information about the file. We call this metadata. There must be a
<title>to providing a title to the page directly underneath the
<body>element contains the main content of our file that will be rendered by a browser. There can be only one
<body>element. Most of the HTML code you write will exist here.
bodyelement, we then branch off to our highest-level heading
<h1>and a paragraph
As you can see from this example, some elements are inline while others are block-level. Block-level HTML elements take the full width of a webpage and start on a new line. Some of these elements include headings, lists, and paragraphs. Inline elements do not take the full width and are in-line with text content. Some examples include anchors, images, and bolded text.
Alright, now we know the basic terms of HTML and how to format an HTML file properly. But how do you actually make a webpage? Let’s go through a step-by-step guide to learn how it’s done. We will be making a simple “About Me” webpage that includes the following:
Webpages are created using HTML editors. Think of this like a word processor but specifically for creating HTML files. There are many options for text editors that vary in complexity and robustness. If you’re just getting started, I recommend using simple text editor like TextEdit (Mac), Notepad (PC), or Atom. Most text editors are free to download.
Here, we will use Educative’s build-in text editor widget where you can explore HTML without downloading anything. You can also follow along with your own editor of choice.
Once you open your editor, start a new file and write the basics structure of an HTML page. Try writing the basic structure yourself in the code widget below using what we learned above. The answer can be found below if you get stuck. You should include:
h1) called “About Me: (Your name)”
Now, let’s add a link to your personal website or a website of your choosing. Copy the code you wrote from above and continue adding to it below. Try it yourself before checking the solution. We will add this just below your personal description. It should include:
Now, let’s add an unordered list of your skills. Copy what code you have from above and continue adding this next step of HTML code. Try writing the code yourself in the code widget below using what we learned above. The answer can be found below if you get stuck. You should include:
h3) called “My Skills”
Now, let’s add a table of your work experience. Copy what code you have from above and continue adding this next step of HTML code. Try writing the code yourself in the code widget below using what we learned above. The answer can be found below if you get stuck. You should include:
Once you complete all these steps, you’ll want to save the HTML file on your computer. Select File > Save as in the Notepad or other text editor menu. Name the file
your_name.html and set the encoding to UTF-8 (preferred for HTML files).
Once you save the file you can open it in your browser by right clicking on the file, clicking Open with, and selecting your browser. You will see your basic HTML page!
Congrats! You’ve officially made a simply webpage on your own. You’re well on your way to becoming a frontend web developer. There’s still a ton to learn, but HTML is a really important stepping stone. The next steps in your web dev journey are:
A free, bi-monthly email with a roundup of Educative's top articles and coding tips.