Setting the Font Colour, Size and Face

In HTML the font appearance was set using the <font> tag. Additional parameters being included within the opening part of the font tag to define the colour, size and font.

Colour

Throughout the use of website code, be it HTML, CSS or JavaScript the English word colour is replaced by its American spelling of color. If your text isn’t showing the colour you are expecting its worth checking your spelling.

The example below shows some text wrapped by the font tag, to set the colour to blue, followed by the rendered text.

Text some of which is <font color=”blue”>blue</font> in colour.

Text some of which is blue in colour.

In the above example the colour is set using a named colour. There is a limited set of colours which are known by their colour name.

Colour is also defined using the RGB values color=”#0000ff”. The colour is defined by 3 pairs of numbers, representing the combination of red, green and blue which forms the colour. Because the numbers used are in hexadecimal this translates to a number between 0 and 255 (decimal) for each of the three colours.

Size

The size parameter may be used to control the size of the text. size=”2″ will give a larger font than size=”1″.

The example below illustrates a part of a sentence wrapped with the font tag, with a size setting of 1. The code is given first, followed by the rendered text.

Text used to illustrate <font size=”1″>two</font> different <font size=2>sizes</font> of font.

Text used to illustrate two different sizes of font.

Using numbers to represent the font size, as in the above example, will provide for relative font sizes. Alternatively the font sizes may be defined by their point size, size=”10pt”. text defined in this way will be rendered to the defined size. The size descriptions commonly used are:

  • numeric 1 to 5
  • pixels (px)
  • points (pt)
  • relative to a fixed value (em)
  • descriptive (larger, smaller)

Font Face

To define the font-face to be used add face=”” to the tag, for example:

<font face=”arial”>Sample text</font>

Historically 10 different fonts were available across a range of operating systems. Other fonts could be specified but the availability of the font on the computer was not guaranteed and hence fonts used were restricted to these 10. The list of fonts is:

arial, arial black, comic sans ms, courier, courier new, georgia, helvetica, impact, palatino, times new roman, trebuchet ms, verdana.

Hexadecimal Numbering

It is more usual to represent the colours assigned to a font using hexadecimal notation and RGB. Examples of this are:

#ff0000 – red
#00ff00 – green
#ffff00 – yellow

In the above examples the three colour components making up the colour are given as two sets of hexadecimal numbers.

A hexadecimal number is to the power of 16. Instead of counting from 0 to 9 we count from 0 to 15. To represent this the numbers 0 to 9 and the first 6 characters of the alphabet. are used. An example is the decimal value 12, which in hexadecimal notation is c.

Table of hexadecimal numbers

HexDecimalHexDecimalHexDecimal
0010162032
1111173048
2212184064
3313195080
4414206096
55152170112
66162280128
771723ff255
881824  
991925  
a101a26  
b111b27  
c121c28  
d131d29  
e141e30  
f151f31  

Notes.

Old HTML code uses the <font> tag. However, in the latest XHTML and HTML 5 compliant code it is replaced by the <span> tag with the font parameters defined in the style parameter. An example of this change is the replacement of

some <font color=”blue”>blue</font> text

by the text

some <span style=”color:blue;”>blue</span> text

Where possible it is better to transfer the styling of fonts to the CSS flies associated with a website. Elements on a web page can then be assigned a class. This allows the styling throughout a website to be controlled from a small number of files, making changes easy to implement across the whole of a website.