Lesson 2: Formatting with HTML

In the previous lesson, you wrote a very basic web page using simple tags. Now let's format the elements to make the page more appealing. You'll use formatting tags to display some special types of text and add the style attribute to format other elements. The structure or syntax of these tags and attributes is very specific. You'll also learn a bit about how computers create colors and how to name those colors using hexadecimal code.

Essential Questions

target

  1. How can I make the content of an html page more attractive when displayed in a web browser?

Key Terms

Key Terms Icon: Key

 

Bold, Italic, and Other Special Formatting Tags

When you're writing a paper for class or even an email to a friend, you probably use bold or italic text to emphasize certain words. Using special formatting like bold and italic draws your reader's attention to those important words. You see this on lots of websites, too. In fact, those types of formatting are used in this web page to draw your attention to Key Terms, Essential Questions, and other text that you need to notice!

In HTML, the <strong> tag is used to make text bold and the <em> tag is used to emphasize text with italics. Take a look at this example:

HTML code using the strong and em tags and the resutls

The paragraph tags (<p>  </p>) determine the layout of the text on the page. The strong (<strong> </strong>) and emphasis (<em> </em>) tags format the text within those paragraphs. It's good coding practice to start and end formatting tags within the layout tags.

You Try It: Bold and Italic Formatting Tags

<p>When formatting text on a web page, I can use strong and emphasis formatting tags
to draw attention to a certain word or groups of words. Even full sentences can be emphasized.</p>
<p>These formatting tags can also be used together for major emphasis.</p>

When formatting text on a web page, I can use strong and emphasis formatting tags
to draw attention to a certain word or groups of words. Even full sentences can be emphasized.

These formatting tags can also be used together for major emphasis.

Result of the html code with strong and emphasis formatting/

If it doesn't look like this, go back and edit the code. Run the code again. Keep working until the display is exactly correct!

 

Formatting with the Style Attribute

Every HTML element has a default style which is used when displaying the element on the web page. For example, a paragraph by default displays black text on a white background. To change the default style of an element, the style attribute is defined within the element tag.

You Try It: Style Attribute

Besides color, there are a number of other elements which can be styled using the style attribute. Think about some of the formatting you might do in a word processing document - changing the font, for example, or centering a title on a page. These can be controlled in html using the style attribute. Let's use the Try-It Editor again to do some additional formatting with the style attribute. Click the name of each attribute in this list and experiment with the style attributes:

 

A Deeper Look at Color

When you tried the color and background-color attributes to style your html code, did you find some color names that didn't work? What happens if you try a color like 'hotpink'? or 'neonyellow'? or 'bluegreen'? And how does the computer know what we mean by these color names, anyway? The answer is hexadecimal!

All colors are actually coded for the computer using hexadecimal number codes. Let's see how the hexadecimal number system works and then we'll see how it relates to web colors.

The Hexadecimal System

The easiest way to understand the hexadecimal system is to compare it to the number system you already know - the decimal system.

Decimal System

Hexadecimal System

we use ten different digits to denote values from 'zero' to 'nine'

uses sixteen different digits to denote values from 'zero' to 'fifteen'

the digits are  0 - 9

the digits are 0 - 9 and A - F

we count single digit numbers:

0 1 2 3 4 5 6 7 8 9

we count single digit numbers:

0 1 2 3 4 5 6 7 8 9 A B C D E F

and two-digit numbers:

10 11 12 13 14 15 16 17 18 19 20 . . . 99

and two-digit numbers:

10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 . . . FF

the largest two digit number:

99

represents the value 'ninety-nine'

the largest two digit number:

FF

represents the value 'two hundred fifty-six'

It's not critical for you to be able to convert values between decimal and hexadecimal notation; but knowing that FF represents 'two hundred fifty-six' will be helpful in looking at html color codes

Color Codes, RGB, and Hexadecimal

All colors on a computer monitor are created by mixing Red, Green, and Blue light. The varying intensities of those three colors is what creates the millions of colors your eye can detect. To describe those varying colors, the html hexadecimal color codes are made up of six-digits - two for Red, two for Green, and two for Blue. Since the largest two-digit hexadecimal number is FF (or two hundred fifty-six), there are two hundred fifty-six possibilities for each of the three colors in any color code. (In case you're interested, that means that there are 256*256*256 unique possibilities for colors or 16,777, 216!) Only 140 color names are recognized by browsers (here's the list if you want to take a look) but you can indicate over 16 million colors using RGB color codes!

The RGB color system is used to designate color values like this:

Hexadecimal code

Red value

Green value

Blue value

Result

#000000

0

0

0

white

#FF0000

256

0

0

red

#008000

0

128

0

green

#0000FF

0

0

256

blue

#FF9500

256

149

0

orange

#FF00FF

256

0

256

fuchsia

#800080

128

0

128

purple

#FF6347

256

99

71

tomato

#00FF7F

0

256

127

spring green

 

You Try It! Using Color Codes

To experiment with color codes, go to the html color codes website and scroll down to the HTML Color Picker. You can click a color and see the code or type in a code to see the color.

Now let's practice designating the color value of an element using color codes instead of color names.

Click here to open the Try-It Editor. Replace the color names with their equivalent color codes in the left side of the editor. Click See Results to refresh the right side of the editor to view the result.

Experiment with other color codes to change the text color.