Favorites

Tinkering - HTML Tutorial

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee

Now that you know what each part of simple.html does, let's make some changes and see what happens.

Adding More Text

Open simple.html in your editor and add a second line of text inside the body:

Example: Adding Text
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>A Simple Web Page</title>
  </head>
  <body>
    This is a simple web page.
    And I mean really simple.
  </body>
</html>

Save the file and refresh your browser. You might expect to see two lines, but both sentences appear on the same line.

HTML and Whitespace

Spaces, tabs and line breaks are all known as whitespace. When a browser displays HTML, it collapses any run of whitespace into a single space. That means these three versions all look exactly the same in the browser:

This is a simple web page. And I mean really simple.
This    is a simple
web page.


      And I mean really simple.
This
is
a
simple
web
page.
And I mean really simple.

This can feel strange at first, but it's actually helpful. You can space out and indent your code however you like to keep it readable, and the page won't change. The browser also wraps text automatically to fit the width of the window.

To start a new paragraph or line on purpose, you use HTML elements. You'll learn how in Paragraphs and Line Breaks.

Emphasizing Text

Let's emphasize a word. Wrap the word "really" in em tags:

Example: Emphasized Text
This is a simple web page.
And I mean <em>really</em> simple.

Save and refresh. The word "really" now appears in italics. The em element marks text that you would stress if you were reading it aloud. Browsers show it in italics by default, but the important part is the meaning: this word is emphasized. You'll meet more elements like this in Formatting Text.

Note

To keep things short, most examples from now on show only the code that goes inside the body. Keep the rest of the page structure in your file as it is.

Changing the Background Color

Finally, let's add some color. Change the opening body tag so it looks like this:

Example: Background Color
<body style="background-color: lightyellow;">
  This is a simple web page.
  And I mean <em>really</em> simple.
</body>

Save and refresh, and the page background turns pale yellow. Try some other color names, such as lavender, lightblue or papayawhip.

The style="..." part is called an attribute. Attributes add extra information to an element. This one contains a small piece of CSS that tells the browser how the body should look. You'll learn more about attributes in Attributes, and much more about CSS in Chapter 3.

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee