A CSS Primer for 2024

Let’s start with a huge caveat: CSS is a huge beast and can present many, many complicated features that are used to make the amazingly designed sites you see around the net. 

We are not planning to go that deep. This is just a primer to get you started.

What do you need?

Ok, First! Go get that html file you made on the first tutorial. We’re going to improve its looks.

You’ll need a text editor, as before. If you don’t already have a favorite one, here’s what comes with your OS: 

  • Windows, notepad.exe
  • MacOS, TextEdit
  • Linux, too many options, look for Kate or GEdit to start.

macOS and TextEdit

TextEdit really wants to save things as formatted files, like MS Word, so you have to tell it what you want to do. 

  • Open up TextEdit, make a new document.
  • Go to FORMAT -> Make Plain Text

Now, when you save your file the first time it will pop up a message about your file extension, saying:

You have used the extension “.html” at the end of the name. The standard extension is “.txt”. 

Click “Use .html”

From here it should work just fine.

STYLE me!

Open your HTML page from the previous primer in your text editor. It should look something like this (but with your favorite animals, not mine)

<!DOCTYPE html>
<html>

<head>
    <title>My Webpage</title>
</head>

<body>
<div>
    <h1>Hello World!</h1>

    <p>This is my first webpage, there are many like it but this one is mine.</p>

    <p>This is a paragraph, full of words. The paragraph will continue until the p tag closes it, like this.</p>

    <p>Here is a new paragraph. Here       Are some     Words
Even a few line breaks. Some.          Space
Here.</p>   

    <h2>Furthermore</h2>

    <p>Some pages have many headings</p>
    <p>Some headings have many subheadings</p>

    <h2>However</h2>

    <p>Not all do.</p>
</div>

<div>
    <h1>The Plan</h1>

    <ol>
        <li>Learn how to make HTML lists
        <li>Make a list of my favorite animals
        <li>Save my webpage and show it to everyone
    </ol>

    <h1>My Favorite Animals</h1>

    <ul>
        <li>Elephants
        <li>Corgis
        <li>Alpaca
    </ul>
    <p>Learn more about <a href="https://en.wikipedia.org/wiki/Elephant">Elephants on Wikipedia!</a></p>
</div>

<footer>
    <p><a href="about.html">About My Webpage</a></p>
</footer>

</body>
</html>

At the top, we are going to add a STYLE tag to the HEAD. All of the CSS we write is going to live in there. 

<head>
    <title>My Webpage</title>
    <style>
    
    </style>
</head>

CSS can be linked to the document in three ways: by the tag, by a class, or by an identifier. Let’s start with the tag. 

Tag me in!

Let’s change the font size of all the paragraphs in our webpage. First we have to tell CSS what we are modifying, in this case the P tag. Then, in parenthesis, we are going to put the changes we want. 

<style>

p {
    font-size: 18px;
}

</style>

If you hit refresh, you’ll see a change! All of the letters in paragraphs should have gotten bigger, but not the headers or the lists. 

Let’s note a few things. First there is a semi-colon at the end of the ‘font-size…’ line. This is important! The semi-colon acts like a period at the end of the sentence, and tells the browser to stop. Forgetting a semi-colon is a common problem, and should be one of the first things you should check if things aren’t going right. 

Ok, great! We changed the paragraphs! Let’s change the headings as well. Let’s make all the H tags into mono-space fonts. 

<style>

p {
    font-size: 18px;
}

h1, h2 {
    font-family: monospace;
}

</style>

For this one, you’ll notice I listed the tags together. By putting the H1 and H2 tag on the same line separated by a comma (that comma is important!), it says to apply these styles to both the H1 and H2 tags. Makes it easier if you have tags or classes that share styles.

Hit refresh! Typewriter headers are in! 

Classy changes

When you use just the tag, like we have been doing, ALL of the tagged things change. So all of the paragraphs, all of the headers, etc. But sometimes, that’s not what you want to happen. Sometimes you just want some of the things to change, some specific things. 

So let’s make a class and see what happens. 

<style>
p {
    font-size: 18px;
}

h1, h2 {
    font-family: monospace;
}

.animals {
        color: purple;
}

</style>

First thing to notice is that there is a period at the start of the word “animals.” This is important! The period is what tells CSS that this is a class. 

Now, how do we add this to our site? Let’s make one of our headers purple. Go to your favorite animal list and update the H tag like this:

<h1 class="animals">My Favorite Animals</h1>

And refresh. Purple! Some thing to point out here is that the class “animal” does NOT have a period in front of it here. Period in the CSS, no period in the HTML. 

Or, say you want a different color! There are lots of named ones you can choose from. Check out the list of named colors here.

(you can use hex code to be very specific about color, but we are keeping this simple for this tutorial)

The reason we named it animal is for us, the person. The classname can help tell you what it is for, or what it does, making it easier to use in larger websites. 

Now that you have classes, you can designate some styling to some paragraphs, different styling to others. You can add multiple classes on one tag, so you can have many ways to organize your styles.

ID Selector

The ID attribute of a CSS tag. 

The ID is unique on the page, so you can only use it once. If you take a book as an example, you may have many headings on a page, but only one Chapter heading per chapter. And only one Title per book! 

So let’s give our page a title ID tag. 

<h1 id="title">Hello World!</h1>

And then we style that, by using the # in front of the selector, like this: 

<style>
p {
    font-size: 18px;
}

h1, h2 {
    font-family: monospace;
}

.animals {
    color: purple;
}

#title {
    color: red;
}

</style>

When you hit refresh, your title is now red! 

ID selectors are unique on a page for a reason. They can be used for on page navigation, they can be linked in with Javascript to update or transform based on user input. While it may not seem useful at the moment, it will become so once your page become more complicated. 

SPACES Again!

Class and ID names in CSS cannot have spaces in them. If you do something like this, for example:

<h1 class="purple header">My Favorite Animals</h1>

You do not have one class named purple header, but instead, two classes, one purple, the other header

Some people will use what is called camel case, which is where you simply capitalize the first letter of each word, so in this case it would be purpleHeader

Others use underscores or hyphens, purple_header or purple-header. Still some do nothing at all, just simply purpleheader

These names are for you, so make them so you understand them.

Hierarchy

These three things, the tag, the class and the ID have a hierarchy amongst themselves. The ID will be on top, followed by the class and then the tag. Let’s see what that means. 

Let’s add an H1 style for color to our code: 

<style>
p {
    font-size: 18px;
}

h1, h2 {
    font-family: monospace;
}

h1 {
    color: green;
}

.animals {
    color: purple;
}

#title {
    color: red;
}

</style>

Now if you hit refresh, after you save, only one of your H1 tags should be green, the one that says “The Plan”. The first one, “Hello World” stays red, as it has an ID, and the last one, “My Favorite Animals” stays purple, as it has a class. 

But what happens if we add the class of animals to the H1 tag that has an ID? Let’s see:

<h1 id="title" class="animals">Hello World!</h1>

Now save, refresh and… nothing. No change. Because the ID, which says to make the color red is higher priority than the class that says it is purple. 

Sharp Dressed HTML

Ok, let’s start cleaning up our page for real. Here are the things we are going to do. 

  1. Change the font size
  2. Change the line spacing of the paragraphs
  3. Make some snazzy font choices

We are going to use the BODY tag for these styles so that everything in the body will be affected by them. Think of this as setting the default styles for the page. So first, let’s delete everything in our style tags and start over like this:

<style>
body {
    line-height: 1.5;
    font-size: 18px;
    font-family: Baskerville, Georgia, serif;
}
</style>

Hit refresh and boom! Isn’t that much nicer? 

Let’s see what each does. 

  • line-height is the space between lines, similar to how you space lines in Word.
  • font-size is how large your font is. Unlike Word, where text sits comfortable at 12pt, web on the text needs to be larger, 16 or 18 is your comfort zone most of the time. The px stands for ‘pixels’ and is one of the ways to do font sizes.
  • font-family is what font you want. Now you can put any font here, but it will only work if that font is installed on the viewer’s device. So the line lets you do fall backs.
  • Baskerville, Georgia, serif; What this says is first try the font Baskerville, if that isn’t installed on the viewer’s device, then try Georga, if that isn’t installed… etc, until the end where it simply says serif, meaning ‘use whatever the default serif font the browser wants.’

Fonts and font stacks can get complicated quickly. You can link to fonts and get fancier ones even if they aren’t installed on the viewer’s computer. You need to pick fonts that pair well together, that match your design, that are easy to read at various sizes. Whew. 

For now, we are just going to stick with some simple choices. 

Ok, let’s do the same to our headings. We want to do all of them the same, so we are going to group them together, and let’s add back in our animals class from before, like this:

<style>
body {
    line-height: 1.5;
    font-size: 18px;
    font-family: sans-serif;
}

h1, h2 {
    font-family: Arial, Helvetica, sans-serif;
}

.animals {
    color: purple;
}
</style>

Hit refresh and we are starting to look respectable! 

Not Least, but Last

The footer of your site usually has some styling to set it apart. So let’s do that for our footer, adding in a light grey color and smaller fonts

<style>
body {
    line-height: 1.5;
    font-size: 18px;
    font-family: sans-serif;
}

h1, h2 {
    font-family: Arial, Helvetica, sans-serif;
}

.animals {
    color: purple;
}

footer {
    font-size:14px;
    background-color: lightgray;
}
</style>

Reflowable Rearrangable

HTML is reflowable. That means if you resized your browser window, that the words will shift around to adjust for the new size of the window. This means as you are designing your page, you should keep that in mind. Some people are going to see your page on their 27 inch monitor. Some are going to see it on their phone. 

Let’s add some to our HTML to get a good look at what we mean. Here are the opening paragraphs to Alice in Wonderland, let’s add them in after our list of animals, but before the FOOTER tag:

<div>

<h1>Alice in Wonderland</h1>

<p>Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, "and what is the use of a book," thought Alice, "without pictures or conversations?"</p>

<p>So she was considering in her own mind, (as well as she could, for the hot day made her feel very sleepy and stupid,) whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a white rabbit with pink eyes ran close by her.</p>

<p>There was nothing so very remarkable in that; nor did Alice think it so very much out of the way to hear the Rabbit say to itself, "Oh dear! Oh dear! I shall be too late!" (when she thought it over afterwards, it occurred to her that she ought to have wondered at this, but at the time it all seemed quite natural;) but when the Rabbit actually took a watch out of its waistcoat-pocket, and looked at it, and then hurried on, Alice started to her feet, for it flashed across her mind that she had never before seen a rabbit with either a waistcoat-pocket, or a watch to take out of it, and, burning with curiosity, she ran across the field after it, and was just in time to see it pop down a large rabbit-hole under the hedge.</p>

<p>In another moment down went Alice after it, never once considering how in the world she was to get out again.</p>

<p><a href="https://en.wikisource.org/wiki/Alice%27s_Adventures_in_Wonderland_(1866)">Read Alice in Wonderland</a></p>

</div> 

Now, if you refresh your webpage you’ll see these first paragraphs near the bottom. What you should take notice of is that they stretch all the way to the end of the browser window before going to the next line. 

If you resize your window, you’ll see that they reshape themselves based on how wide the window is. This is good to some degree because that means the text you have will conform to the window it is viewed in. 

It is not good in a way because reading a line that goes from one side of your monitor to the other is not easy. Go give it a try. 

Books don’t do this, they have a set line length (caused by the page size and margins), and that length is picked to be easy to read. We are going to do the same with our page and some CSS.

So we are going to add a maximum width to the BODY tag. What this will do is prevent the text from stretching out forever, instead make a reasonable line length that is easier to read. 

It is a maximum, rather than fixed width, so that if someone looks at it on their phone, it will shrink down in size. 

body {
    line-height: 1.5;
    font-size: 18px;
    font-family: baskerville, Georgia, serif;
    max-width:650px;
}

Now, if you refresh your page, it will be much easier to read the opening to Alice in Wonderland. AND, if you resize your window, you’ll see that it will still resize if you make it smaller than it is, but when you make it larger, that maximum width value stops the lines from growing. 

Shortcuts

I want to talk about CSS shorthand propeties.

Let’s take a look at two bits of CSS code. 

First: 

line-height: 1.6;
font-size: 18px;
font-family: baskerville, Georgia, serif;

And Second: 

font: 18px/1.6 baskerville, Georgia, serif;

These two bits do the exact same thing. The border attribute has a similar shortcut as well with its components. 

The shorten version may save space, may make your file smaller, but the best practice for you when you are writing code, especially code for yourself, is to write it so you understand it. 

So if the line by line first version works best for you, then keep it. Don’t feel like you need to forsake readability at this stage. 

Portabile Styles!

Having these styles in the HEAD of your HTML page is fine if you are only going to have one page on your site… but let’s face it, most webpages are more than that. If you copy/pasted the code on the top of all your HTML pages it would work… and it would be a mess to try to change if you decided that purple wasn’t really your color anymore. 

So, let’s move those styles out into their own file. Make a new file in your notepad.exe called style.cssand save it to the same folder your mypage.html is in. 

Copy all the styles you made, but NOT the STYLE tags, and paste them in this file, so it looks like this: 

body {
    line-height: 1.5;
    font-size: 18px;
    font-family: Baskerville, Georgia, serif;
    max-width:650px;
}

h1, h2 {
    font-family: Arial, Helvetica, sans-serif;
}

.animals {
    color: purple;
}

footer {
    font-size:14px;
    background-color: lightgray;
}

Comments in CSS are bracketed by /* and */ markers, so let’s just add a comment to the top like this. Like HTML comments, line breaks are ok! 

/* This is a style sheet for my website! */

/* 

This is a multi-line comment, everyting inside of the markers is ignored. 

Often you'll see comments like this at the top with information on the author of the website, its URL, and license. 

*/

/* overall website typogrpahy */
body {
    line-height: 1.5;
    font-size: 18px;
    font-family: Baskerville, Georgia, serif;
    max-width:650px;
}

/* sans-serif fonts for the Headers */
h1, h2 {
    font-family: Arial, Helvetica, sans-serif;
}

/* I like purple, ok? */
.animals {
    color: purple;
}

/* Footer styles */
footer {
    font-size:14px;
    background-color: lightgray;
}

Hit save. 

I add comments into my code everywhere, like ‘notes to Jake’ about what something is or does so that in the future I can more easily remember what it was past Jake was doing. 

Because let me tell you, that guy sometimes doesn’t know what he’s doing. 

Link it to me!

But, we aren’t done yet. We have to tell the HTML page where those styles are. We are gong to do that with a LINK tag in the header. So, first delete the STYLE tags and everything inside of them all together. 

Then we will add a LINK, which similar to the A tag, will have an HREF property. it will also have a REL property, for relationship, this tells the browser what kind of file this is and how it relates to the HTML page. 

So your HEAD tag should now look like this:

<head>
    <title>My Webpage</title>
    <link rel="stylesheet" href="style.css">
</head>

And just like the previous discussion about A tags, this is a relative link, so your style.css file needs to be in the same folder as your mypage.html file. 

So now we’ve connected the two together, if you refresh your mypage.html nothing should change! 

And that’s a good thing. It means your styles, which are now in their own css file are being loaded just fine.

Share and Share Alike!

Remember we made that about page in the first tutorial? Let’s open it, add the style link to the top, same as we just did. 

<head>
    <title>About My Webpage</title>
    <link rel="stylesheet" href="style.css">
</head>

And, if you open this in your browser, boom, same style as mypage.html

Now, if you change the style.css file, both mypage.html AND about.html will update with the new changes. You can use the classes you’ve written, such as .animals to style your about.html as well. 

Most sites use a separate CSS file like this for their styling, allowing for easy change and updates to the whole site. Some will use multiple CSS files, so they are only loaded on the pages that need them. 

Bonus Round! DARK MODE

Exciting music plays

This is going to be a very, very simple dark mode bit of code, but it will help show the overall idea for dark mode. 

Dark mode is an inverse color scheme, so instead of a light background and dark text, we have a dark background and light text. 

Now you can just simply style your page to be dark, lots of sites do that. But this code will change from light to dark when the viewers device changes. So if your computer is set to dark mode, the page will be dark. If it is light, then light. If it switches based on the time of the day, like mine does, then the page will change as your computer does. 

So, here is what we are going to do. We are going to make a section that calls out new colors for background and text of everything in the body tag, using a media query. 

The media query is a powerful tool that can be used to change the style of your page based on the size of the screen it is on, the orientation (landscape v portrait), the color settings and more. This is just one slice, and a simplistic one, of what this tool can do. 

At the bottom of your style.css file, add this: 

/* styles for Dark Mode */
@media screen and (prefers-color-scheme: dark) {

}

See the two curly brackets? They are important! Everything we want to add needs to go between them. 

Ok, so prefers-color-scheme: dark is the call, if your computer is set to dark mode, it should trigger this. 

Inside of those curly brackets, let’s change our webpage: 

/* styles for Dark Mode */
@media screen and (prefers-color-scheme: dark) {
    body { 
        color: white;
        background-color: black;
    }
}

This says, change the background of the body (so, everything our our basic site) to black, and change the text to white. 

If you save that, you may or may not see a change, depending on what your computer is set to. But if you are in dark mode, it will invert, black background, white text. 

Now that purple we chose for a light background is way too dark for our dark background. We need to change it as well. To keep with our color scheme, let’s change it to a not-so-dark purple, like this:

/* styles for Dark Mode */
@media screen and (prefers-color-scheme: dark) {
    body { 
        color: white;
        background-color: black;
    }
    
    .animals {
        color: mediumpurple;
    }
}

To note, we only need to put the attributes we want to change in this media query. So if animals had additional attributes, like font size or line height, we don’t have to put them here since we only want to change the color. 

Like our footer! Which is lightgray at the moment, and doesn’t fit our dark theme. Let’s make it a darker gray, called ‘dimgray’:

/* styles for Dark Mode */
@media screen and (prefers-color-scheme: dark) {
    body { 
        color: white;
        background-color: black;
    }
    
    .animals {
        color: mediumpurple;
    }
    
    footer {
        background-color: dimgray;
    }
}

We are going to tweak one last thing. You see that color: white; part doesn’t affect links. You’ll see your links are still dark blue or purple depending on if you’ve clicked on them. And they are hard to see. So, let’s add in some colors that you can see with a dark background: 

/* styles for Dark Mode */
@media screen and (prefers-color-scheme: dark) {
    body { 
        color: white;
        background-color: black;
    }
    
    .animals {
        color: mediumpurple;
    }
    
    footer {
        background-color: dimgray;
    }

    a {
        color: orange;
    }

    a:visited {
        color: yellow;
    }
}

The A tag changes any unvisited links. So we have to add in a pseudo-class, A:VISITED for the color of lines you’ve clicked. 

Save, refresh, and now your links stand out against the dark background! 

Don’t want those colors? Don’t forget the fill list of colors at MDN.

A Start

This was, even more so than the HTML primer, just a start. There are many other aspects of CSS, particularly when you get to layout, that are more complicated than this. But again, just like the HTML tutorial, just because these things are basic, they are far from useless. 

You’ll use font styles on nearly any site, colors for backgrounds and boarders, and as soon as you start your layout, the media queries will come out for responsive websites. 

With the basic structures of classes and IDs you will create a layout, moving these DIV sections all over the page. You’ll create dropdown menus, and change the way the page looks based on the device it is on. 

And inevitably, you’ll forget a semi-colon and spend an hour trying to figure out what went wrong.

An HTML Primer for 2024

HTML is a markup language that defines the structure of every webpage you’ve been to. It is a markup language where tags are used to designate the type of content they contain, thus telling your browser how to display it.

And it is not just the web, but our ebooks as well are formatted using HTML.

This is to be a quick tutorial on the basics of HTML. After this, you’ll have the tools you need to make very, very basic sites, but that is the first step into making some not so basic sites later. 

So to start, this is just HTML, no CSS (Cascading Style Sheets) or JavaScript. 

Think of the three, generally as this: 

  • HTML is how the page is structured
  • CSS is how the page is formatted
  • Javascript is how the page functions

To Start

To start, think of HTML tags as labeled parentheses. You put them around text to tell the browser what that text is. So for example, the p tag means “paragraph”, so to show that a bunch of text is a paragraph, you wrap them in p tags, like this:

<p>This is a paragraph, full of words. The paragraph will continue until the p tag closes it, like this.</p>

Notice how the end, or closing, tag contains a / (backslash). 

Those p tags tell the browser that the text inside is a paragraph and it should render it (display it to the viewer) that way. 

This differentiates the text from headers, or links, or even things that aren’t meant to be shown to the viewer, like metadata or JavaScript. 

White Space and HTML

Something to note here is that HTML ignores white space. What does that mean? It means if you push the space bar three or fifty times between words, HTML will ignore it, and render it with a single space. 

<p>Here is a new paragraph. Here       Are some     Words
Even a few line breaks. Some.          Space
Here.</p>

which renders like this:

Here is a new paragraph. Here Are some Words Even a few line breaks. Some. Space Here.

Let’s make a page!

Ok, so rather than talk generalities, let’s start by making a page. Open up a text editor, like Notepad.exe, and let’s start. If you don’t already have a favorite text editor, your operating system should come with one already:

  • Windows, notepad.exe
  • MacOS, TextEdit
  • Linux, too many options, look for Kate or GEdit to start.

macOS and TextEdit

TextEdit really wants to save things as formatted files, like MS Word, so you have to tell it what you want to do. 

  • Open up TextEdit, make a new document.
  • Go to FORMAT -> Make Plain Text

Now, when you save your file the first time it will pop up a message about your file extension, saying:

You have used the extension “.html” at the end of the name. The standard extension is “.txt”. 

Click “Use .html”

From here it should work just fine.

From the Top!

First let’s add the doctype at the top, just like this:

<!DOCTYPE html>

This tells the browser what kind of file this is. This specifically tells your browser that it is an HTML document and it should treat everything in the file as HTML stuff.

Now let’s add in our first tags, the HTML tag

<!DOCTYPE html>
<html>

</html>

This encompasses everything else we are going to write. It is the root tag, and everything on the page needs to be between those two HTML tags to get rendered to your browser. 

Now we have two major sections to our HTML document, the HEAD and the BODY. 

<!DOCTYPE html>
<html>

<head>
</head>

<body>
</body>

</html>

The HEAD is the meta data for the document. Most of the things you would add to the HEAD are more advanced than this tutorial, as this is the place you would add your CSS or JavaScript. 

But there is something we are going to add—the TITLE

<!DOCTYPE html>
<html>

<head>
    <title>My Webpage</title>
</head>

<body>
</body>

</html>

If you save this as mypage.html and open that in your browser, you’ll see a blank page… BUT at the top, it will say “My Webpage.”

The easiest way to open in the browser for most will be to simply double click the file and it will open up in your default browser. 

You can also go to FILE and OPEN in most browsers and open just like you would a file in Word. 

So, let’s add something to the body!

<!DOCTYPE html>
<html>

<head>
    <title>My Webpage</title>
</head>

<body>
    <p>Hello World</p>
</body>

</html>

Now if you refresh your browser, it will proudly display “Hello World!”

Now, remember what I said about whitespace? one thing we do when when write HTML is indent nested tags to make it easier to read—not for the computer, but for the person. You don’t have to indent, but it helps find things as the page gets longer. 

Congrats on your first web page! 

Adding More

Let’s add some more paragraphs to our site, including the one with all that whitespace from above so you can see what we meant by that:

<p>Hello World!</p>

<p>This is my first webpage, there are many like it but this one is mine.</p>

<p>This is a paragraph, full of words. The paragraph will continue until the p tag closes it, like this.</p>

<p>Here is a new paragraph. Here       Are some     Words
Even a few line breaks. Some.          Space
Here.</p>

Which should render as such:


Hello World!

This is my first webpage, there are many like it but this one is mine.

This is a paragraph, full of words. The paragraph will continue until the p tag closes it, like this.

Here is a new paragraph. Here Are some Words Even a few line breaks. Some. Space Here.


MOAR

The purpose of HTML is to add context to the content you are writing up so that it can be displayed and read. 

We’ve seen paragraph (p tags), so let’s now add headers. Headers have levels, 1 – 6, and should be used as hierarchy—that is you should only use level 2 under a level 1, etc., like an outline would require. 

This keeps things organized, and makes it easier for software such as screen readers to parse. 

The levels are just numbers on the h tag, so h1 is header level 1, h2, header level 2, etc etc. 

Let’s add some now. 

<h1>Hello World!</h1>

<p>This is my first webpage, there are many like it but this one is mine.</p>

<p>This is a paragraph, full of words. The paragraph will continue until the p tag closes it, like this.</p>

<p>Here is a new paragraph. Here       Are some     Words
Even a few line breaks. Some.          Space
Here.</p>

<h2>Furthermore</h2>

<p>Some pages have many headings</p>
<p>Some headings have many subheadings</p>

<h2>However</h2>

<p>Not all do.</p>

Now refresh your page and you should see something like this: 


Hello World!

This is my first webpage, there are many like it but this one is mine.

This is a paragraph, full of words. The paragraph will continue until the p tag closes it, like this.

Here is a new paragraph. Here Are some Words Even a few line breaks. Some. Space Here.

Furthermore

Some pages have many headings

Some headings have many subheadings

However

Not all do.


Your page now has structure. The words aren’t just words, but titles, headers and paragraphs. 

You’ll notice that the H1 and H2 tags render differently. The H2 tags are smaller, though still bigger than the p tag. It may be tempting to pick which level you want based on its presentation, but do not do this. HTML should be used for organization not for presentation. The presentation of these will be covered by CSS. 

So for now, even if you wish H1 was smaller, or H4 was larger, keep with the tag that fits the structure of your document. 

Lists!

Sometimes you have to just list things. A list is two elements. First you have to say what kind of list it is. There are two:

  • Ordered list, marked with an OL tag, these are numbered in order they are listed
  • Unordered list, like this one, marked with an UL tag

Then the elements of the list are marked with a LI, list item, tag. Let’s see how that works: 

<h1>The Plan</h1>

<ol>
    <li>Learn how to make HTML lists
    <li>Make a list of my favorite animals
    <li>Save my webpage and show it to everyone
</ol>

<h1>My Favorite Animals</h1>

<ul>
    <li>Elephants
    <li>Corgis
    <li>Alpaca
</ul>

But don’t use my list of animals make sure you put down yours! And if you need more, just start a new like with an LI tag. 

When you save and refresh your document, boom! You have LISTS, take a look: 


The Plan

  1. Learn how to make HTML lists
  2. Make a list of my favorite animals
  3. Save my webpage and show it to everyone

My Favorite Animals

  • Elephants
  • Corgis
  • Alpaca

Now, you may have noticed something about the LI tags—I didn’t close them. You can. That is

<li>list thing!</li>

Is perfectly acceptable HTML. it is just for this tag, the LI, a closing tag is not required. 

Link me!

What would a webpage be without a link? The idea of a link is at the very heart of the web itself, not just HTML. This small part of HTML is a powerful, important tool to how the whole web works. 

Links are an anchor tag, A, and are slightly more complicated than anything we’ve done before. Here’s why. For a link I need to have two bits of information: 

  1. Where is the link going?
  2. What words are in the link?

So if I wanted to have the words “Click Here!” Link to Wikipedia, it will get set up like this:

<a href=“https://wikipedia.org”>Click Here!</a>

The link still has a closing tag, </a>, but we have added additional information into the opening a tag. 

The HREF=“” (the quotes are important!) tells the browser where to redirect someone if they click on the words found in the A tag, which are “Click Here!” in this case. 

So, let’s get to linking! 

Let’s add a link at the end of our list to the Wikipedia page for our favorite. Don’t forget the P tags around your new link! 

<h1>My Favorite Animals</h1>

<ul>
    <li>Elephants
    <li>Corgis
    <li>Alpaca
</ul>

<p>Learn more about <a href="https://en.wikipedia.org/wiki/Elephant">Elephants on Wikipedia!</a></p>

Which results in this: 


My Favorite Animals

  • Elephants
  • Corgis
  • Alpaca

Learn more about Elephants on Wikipedia!


If you click that link, you’ll be learning about how awesome your favorite animal is. 

Link Types

There are two kinds of links. 

  • Absolute
  • Relative

Absolute links are links that start with an HTTP and give the full web address of your link, like the one we just did. 

Relative links are links that just contain the address of the file relative to the file that the link is on. So, if made a link to just href="about.html", then your browser would expect that in the same folder as mypage.html there is another file named about.html

So, let’s do that! At the bottom of our page before the body tag, let’s add a link:

<p><a href="about.html">About My Webpage</a></p>

If you refresh your mypage.html, you’ll now see the link to About My Webpage, but it doesn’t go anywhere yet, so let’s fix that! Open up a new blank file, and add this:

(macOS folks using TextEdit, don’t forget to do the steps above again for the new file)

<!DOCTYPE html>
<html>

<head>
    <title>About My Webpage</title>
</head>

<body>

    <h1>About My Webpage</h1>
    <p>This is my first weppage!</p>
    <p>see it <a href="mypage.html">here!</a><p>

</body>

</html>

Save it as about.html in the same folder as your mypage.html. Now the links will work back and forth between the files, so long as they live in the same folder together. 

Relative links are for linking pages on the same website together. 

Absolute links can be used for pages on the same website, AND are also used for external links (to other websites all together)

DIV me up!

There is another tag that becomes more useful later that we should talk about, the DIV tag. 

The DIV, for division, is something you use to group things together for organization. Something that with pure HTML may or may not be helpful, but when you start adding in CSS or JavaScript becomes VERY helpful. 

So let’s add some DIV tags to your webpage. We are going to group the top part together and add a bottom part that will be a footer. 

<!DOCTYPE html>
<html>

<head>
    <title>My Webpage</title>
</head>

<body>
<div>
    <h1>Hello World!</h1>

    <p>This is my first webpage, there are many like it but this one is mine.</p>

    <h2>Furthermore</h2>

    <p>Some pages have many headings.</p>
    <p>Some headings have many subheadings.</p>

    <h2>However</h2>

    <p>Not all do.</p>
</div>

<div>
    <h1>The Plan</h1>

    <ol>
        <li>Learn how to make HTML lists
        <li>Make a list of my favorite animals
        <li>Save my webpage and show it to everyone
    </ol>

    <h1>My Favorite Animals</h1>

    <ul>
        <li>Elephants
        <li>Corgis
        <li>Alpaca
    </ul>
    <p>Learn more about <a href="https://en.wikipedia.org/wiki/Elephant">Elephants on Wikipedia!</a></p>
</div>

<div>
    <p><a href="about.html">About My Webpage</a></p>
</div>

</body>
</html>

When you save and hit refresh, nothing will change. So you may think “why did I do that?” And that will be more apparent when we get to CSS. But, anytime you are on a webpage and you see parts that are separated from each other, that was accomplished via DIV tags. 

That’s it?

No!

There are a lot more tags in HTML, especially if you want to make a form or any kind of user input. This is just a primer. 

A lot of the tags are functionally similar to the DIV tag, but semantic, meaning they have a specific role. This, again, is to help organization. 

So you can use a FOOTER tag to put some info at the bottom of your page. It will, however, work no different than the DIV tags that is already there. 

Let’s change the DIV tag we put around our about link to a FOOTER tag. 

<footer>
    <p><a href="about.html">About My Webpage</a></p>
</footer>

There are many of these tags you can use as you get into making your site like this. Tags like the MENU, HEADER (different from HEAD), SECTION, ARTICLE, are all available so you can organize your page by its content, as well as its function. 

But those are not things to worry about yet. Start with your basic tools for now.

A Good Start

These tags are a good start to your website making skills. They may feel basic—maybe because they are—but don’t mistake ‘basic’ for ‘useless.’ These are the very building blocks every site you’ve ever been to are built on. And even though there are other layers of complication between that site and your first html page, in the end, it is these simple tags that will define the pages you make.

And as you learn, you’ll start to use more complicated tools, you’ll learn new features and programs. You’ll probably not be spending your time in notepad.exe writing your website. 

But. Never forget. You can always open HTML in notepad.exe. That is its superpower, and what makes it so accessible as a file format. 

The MDN, a site for web developers maintained by Mozilla, is your reference book. It has all the info you could want on each of these tags, and more. If you want to start a deep dive, take a look at the links we just learned, or jump into the who thing:

The MDN https://developer.mozilla.org/en-US/docs/Web/HTML

I hope this helps get a few people started. Next time on the agenda will be some CSS! 

Bonus

While I was writing this, a fantastic tutorial called HTML for People came out, which gives a much more in-depth look at HTML for people who do not have experience with it. 

Check it out as a great next step from here!