You are here: > >

Changing the font type, size, and color displayed on a web page

Font sizeThis document contains instructions on how to change a font and its color on a web page. The proper syntax moving forward is to use Cascading Style Sheets along with the class or ID selectors rather than an inline style attribute or font tag, which are deprecated. Although, it is worth noting that these two methods still work with most Internet browsers.

To proceed, select the method you would like to learn from or read every section.

Using CSS for a single application
Using CSS for one or more pages
The Font tag

Using CSS for a single application

If you plan on changing the font face and its color only once on a web page, you need to change its attributes within the element tag. Using the style attribute, you may specify the font face and color with font-family, color, and the font size with font-size, as shown in the example below.


<p style="font-family:Courier; color:Blue; font-size: 20px;">This text has the font Courier, is Blue, and 20px.</p>


This text has the Courier font, is Blue, and 20px in size.

Using CSS for one or more pages

Custom font for one page

In the head portion of your web page, you may insert code between the <style></style> tabs to change the appearance of your text in various elements. The next blue box contains example code that, once called, would change your font face to Courier and color it red. As you can see, we have defined the class name as "custom."

<style type="text/css">
.custom {
	font-family: Courier;
	color: red;

Once defined, this styling can be applied to most elements in your page by attaching the class "custom" to them. The following box shows two lines of code and their respective results.


<p class="custom">This whole sentence is red and Courier</p>

<p>Only the word <span class="custom">TEST</span> is red and Courier.</p>


This whole sentence is red and Courier

Only the word TEST is red and Courier.

Custom font for many pages

Importing an external CSS file can be very beneficial in that it allows users to change rules for multiple pages at the same time. The following section shows an example for creating a basic CSS file that changes the font and it's color for most elements. This file may be loaded into more than one web page, even an entire site.

Using any basic text editor, saving the following text as a .css file will prepare it for import.

@charset "utf-8";
.courier { font-family: Courier; color: #005CB9; }

Once the preceding text has been placed into a .css file (we have named ours basic.css), you can link to it from any other page using a line similar to the following example.

<link rel="stylesheet" Type="text/css" href="">

Tip:Users may change the attributes of elements on a page by changing the code within the imported .css file.

Font tag solution

Although deprecated, the HTML <font> tag can still be used and may be necessary to be used with some online services. When using the FONT tag, you must include the face attribute, which describes the font to be used. In the example below, we are using the Courier font and the hexadecimal color code #005CB9, which is a dark blue.


<font color="#005CB9" face="courier" size="5">This is a special font.</font>


This is a special font.

Additional information