HTML (HyperText Markup Language) is a markup language that is used to structure content for presentation over the web. It’s important to note that HTML is not considered a programming language because it can’t perform mathematical logic or other features that are common in programming languages. The upside is that HTML is super easy to learn! HTML is one of the main technologies used on the World Wide Web, and it’s an essential tool to know as a web developer. You’ll have to learn HTML and CSS if you want to build anything on the web. HTML code is sent to the web browser which can understand it and render a web page accordingly. Another essential technology in web development is called CSS, which is used in combination with HTML to style the resulting webpage. CSS (Cascading Style Sheets) is a style sheet language that is used to style (control the appearance) the presentation of a document that is written in a markup language like HTML. In other words, we use HTML to define the structure and the meaning of a page, while we use CSS to specify its visual style. CSS works in combination with HTML. We can create buttons, links, and other elements using HTML and then using CSS we can change those elements’ size, color, position, etc. We have to learn HTML and CSS together to really build anything that users can actually navigate! To illustrate the roles of HTML and CSS, let’s take a look at a simple webpage. If we strip away all HTML and CSS, this is the underlying text for our example page:
Using HTML, we can add some structure to any webpage we build. We can specify which pieces of text are links and buttons. We can add form inputs, images, and many other elements though our webpage is quite…plain if we just use HTML.
Using CSS, we can add in styles to alter the appearance of the HTML elements we specified.
2. HTML
We write HTML in files that end with the .html extension (like homepage.html). To write HTML and CSS code, you’ll want to install a code editor. Nowadays, one of the most popular free code editors is Visual Studio Code. Before writing any code, make sure to download and install it from this link. You can find more information about VS Code in this video tutorial. You can also use something like Sublime Text. To see the resulting page, open the .html file in a web browser. You can do this by double clicking the html file, dragging it into the browser, or using the file → open menu in your browser. One of the most popular web browsers among developers is Google Chrome. It comes with powerful debugging tools that make our lives easier. You can download and install it on your computer by following this link. If you feel like you need a more curated version of a curriculum like this and/or mentored help to learn HTML/CSS, check out this HTML/CSS course.
2.1. Syntax
HTML provides tags that are used to create elements on a rendered webpage. Remember, we are “marking up” a document in order to define structure. We often wrap tags around text to indicate which portions of a document are links, headings, bullet points, etc. An HTML element is an individual component of an HTML document that provides meaning for parts of a webpage. For example, there is an HTML element called title which is used to specify which block of text is the title of the web page/document. This is the general syntax structure for defining HTML elements, with an opening HTML tag and then a closing HTML tag:
2.1.1. Tags
Most HTML elements are written with a start tag (opening tag) and an end tag (closing tag), with content in between: The h1 (heading) element is written with the
opening tag and the
closing tag, where we place the heading content between those two HTML tags. Andesignates something as the most important heading on a page. We also have further subheadings from h2 to h6. This is what they look like rendered, though remember you can change fonts and sizes and colors via CSS:
Similarly, we use the same pattern but with
tags to create a paragram element, which represents a paragraph of text.
Some elements consist of self-closing tags, like br in the example above. The
tag is used to add a line break to our page, and it doesn’t have any custom inner content that we need to specify (like headings and paragraphs do).
As we have seen in the example above, tag names are surrounded by angle brackets. The start tag is placed inside angle brackets, as well as the end tag:
The end tag will usually be the same as the start tag, but it will have a forward slash / prefix, as seen in the HTML code above.
2.1.2. Attributes
Many elements accept HTML attributes that allow of us to define additional properties for those elements. Most attributes follow this basic pattern:
element
We can add an image element on our page using the tag. We define the source (src) attribute of an image (img) element to tell the browser which image to render to the page. The browser will go and fetch the image data using the src attribute and then display it for a user. Notice that the element consists of a single self-closing tag, rather than an opening and closing tag.
We can add a clickable link to our page using the tag. The href attribute in an tag (anchor tag/link element) defines where the link leads the user after it has been clicked: We can give our elements unique id or class attributes so we are able to specifically target and style them in our CSS code, which we will talk more about later when we learn HTML and CSS.
2.2. Page Structure
Each HTML document should start with a basic structure which is called the HTML skeleton or HTML boilerplate. You should put this in every HTML document you create: The first tag tells the browser that we are using HTML5 code (the latest ‘version’ of HTML). The next mandatory element is theelement. It has a closingthat should enclose ALL the remaining content on our page. It represents the root element of our document. Inside the html element, we always want to place the head and body elements. In the
element, we place metadata about the HTML document which isn’t supposed to be visually rendered and shown by the browser. For example, we define theNote that we used the width and height attributes to specify a size for the image element in this simple example. In the real world, once we’ve done more on our quest to learn HTML and CSS, we would use CSS to style and specify the size of our image (img) element.
2.3. Elements
In this section, we will cover some other important HTML elements and their tags. Make sure to check the MDN page about HTML to read more.
2.3.1. The div element
The HTML element
2.3.2. Headings
The HTML
– elements represent six levels of section headings. is the highest section level and is the lowest.
Here is the code demonstrating all six heading tags which are used in HTML documents:
When you save that code and open the HTML file in the browser, you should get the following result:
is the highest section level and is the lowest.
Here is the code demonstrating all six heading tags which are used in HTML documents:
When you save that code and open the HTML file in the browser, you should get the following result:
To automatically reload your HTML page after you save any changes in the Visual Studio Code editor, check out the Live Server extension presented in this video tutorial. It’s important to note that we don’t want to use the heading tags just to change the size of the element. These elements should be used to define headings on our page and provide semantic meaning. Content in an
should be a more “important” heading than content in an , for example. We can use CSS to change font-sizes when needed later on when we’re more advanced in our progression of learning HTML and CSS.
2.3.3. Paragraphs
2.3.3. Paragraphs
The HTML
element represents a paragraph of content. Here’s an example with two paragraph elements: The code above would yield the following result in the browser:
Paragraphs are block-level elements which means that each
element will take a new line and a separate block on the rendered page. Similarly to that, heading (h1–h6) elements are also block-level. If we write two headings one after another in the code, they will still be placed in separate lines on the page that is rendered in the browser.
On the other hand, we also have inline-level elements in HTML. These don’t take up their own line, but they instead get placed in the same line (content on the left and the right side of the inline element is allowed). Try putting an tag inside a and see what happens!
Read this Stack Overflow answer to learn more about inline and block elements. We can also write lists in HTML, which come in two main flavors: ordered and unordered.
To make an unordered list (with bullet points) we first write a parent 2.3.4. Lists
element. We then add individual
. Each
To make an ordered list (numbered) we follow the same pattern but use an
- element as the parent:
We can even combine and nest lists:
There is also an HTML
- element (description list) which you can learn more about on this MDN page.
2.3.5. Tables
In HTML, we can use the
, and | . You can refer to existing HTML tables in other websites if you need a refresher on this.
Inside of the
|
---|