Hot Docs

Elemental HTML

Learn about the basic building blocks of every web page and how to control them on Hot Page

If you have even a little bit of experience building web pages, you may want to skip past the basics and read about the specifics of using elements on Hot Page.

The Basics

On a web page, pretty much everything is an “element.” This paragraph, the menu at the top of the window, the links in the menu—these are all elements. We create elements by writing in a computer language called HTML, which stands for HyperText Markup Language. Elements are created by so-called tags that appear in angle brackets like this and surround your content:

<p id="intro" class="big bold">The Queen of Hearts, she made some tarts</p>

Here, we have an example of a paragraph made with the <p> tag, just like the one you’re reading now. When a browser renders the page for you, the text “The queen of hearts, she made some tarts” will be the only thing that you see.

This paragraph that we just made has two so-called attributes: id and class. There are any number of attributes that you can put on an element but these are two of the most useful because they will help us identify this paragraph when it comes time to style it.

There are, of course, many other types of elements, not just paragraphs. For example, the <a> or anchor element creates a link to another page, the <h1> tag is for headings, the <em> tag is for emphasis. Here are some of the most useful:

All of the above elements are called “block” elements and are generally things that take up the full width of the page and cause the things after them to jump to a new line (although not always, depending on their styles).

The following elements are “inline” elements because they can exist within a line of text:

That’s very far from a full list of elements and if you plan on really learning this web stuff, you will probably want to consult a full list.

Picking the Right Element

All this talk about picking elements can seem a little pointless. I mean why worry about using the <main> element when you could just write <div class="main"> and visitors to your site will never know the difference. Is it just splitting hairs?

This is actually a quite controversial subject. It goes to the heart of something called the Semantic Web, or the idea that we should be adding markup that enhances the meaning of text so that machines can read it and understand it as well.

That idea is pretty much dead these days, the victim of a power struggle between the W3c (an organization created by the inventor of the web, Tim Berners-Lee) and the large tech companies like Google and Apple that took the technology in a different direction.

There are still some very good reasons to pick your tags with care, however.

So, when in doubt, pick the right tag. It’s not very difficult and it’s definitely the safer bet.

Elements on Hot Page

In the example above we had this HTML tag which creates a paragraph element:

<p id="intro" class="big bold">The Queen of Hearts, she made some tarts</p>

Since editing HTML elements like this is essentially the core of what we do on Hot Page, the editor employs a shorthand for defining elements based on the way that CSS selectors work. We can create the element above on Hot Page like this:

p#intro.big.bold
The Queen of Hearts, she made some tarts

Writing HTML like this is a bit more concise and easier to read, while giving more emphasis to the content and minimizing the markup. It also has the advantage that it looks more like the selectors we use in CSS when we style our elements.

Custom Elements

One of the newest features of the web lets you create your own elements. These elements are built in JavaScript and can do pretty much anything you can imagine. Let’s take a look at an example from the Hotfx library:

speech-bubble
Well, then, you see, a dog growls when it’s angry, and wags its tail when it’s pleased. Now I growl when I’m pleased, and wag my tail when I’m angry. Therefore I’m mad.

That will create something like this on your page:

Well, then, you see, a dog growls when it’s angry, and wags its tail when it’s pleased. Now I growl when I’m pleased, and wag my tail when I’m angry. Therefore I’m mad.

In order for this to work, you’ll need to add a bit of JavaScript to the page that defines this custom element and does the work of drawing that circle around the text. That work is all a bit complicated, but the very cool thing is that you don’t need to worry too much about the details to use these custom elements on your pages.

Custom elements, which are also called web components, are still pretty new but there are already many publicly available elements that you can use today. Here are some of the favorites around Hot Page:

If you want to build your own, LitElement can be a great way to get started.

A Word About White Space

You may have noticed a peculiar feature of the Hot Page editor is that it won’t let you type more than one consecutive space. This is not just a quirk of its design, but reflects something about the design of HTML itself: white space is not significant.

This means that in an HTML source file, you could write 10 spaces and only one would show up. The language was designed this way because it was markup, half document and half code. When people write code, they typically indent nested blocks of elements to make it easier to read—but we don’t want to show all that indentation to the reader. So if you actually want to make empty space, you’ll have to use HTML or CSS.