How to change the font type, size, and colour on a spider web page

Updated: 08/16/2021 by Computer Hope

Font size

This page contains instructions on how to change a font and its color on a web page. With the introduction of HTML5, the proper manner to configure spider web page fonts is to use Cascading Mode Sheets. The old method, of using an inline fashion attribute or font tag, is deprecated, and should no longer exist used.

Note

Although the deprecated methods may still return correctly in modern Cyberspace browsers, they are no longer guaranteed to do so. To create spider web pages that display correctly for the maximum number of users, use the CSS methods described on this page.

Tip

The methods for changing font attributes on this folio work for text contained in most HTML tags, including <div>, <p>, and <span>. These methods likewise piece of work for text in a tabular array, using the <table>, <tr>, and <td> tags.

Using CSS for a unmarried application

If y'all plan on changing the font confront and its color for i give-and-take, judgement, or paragraph on a web folio, configure its attributes in the element tag. Using the mode attribute, you may specify the font face and color with font-family unit, colour, and the font size with font-size, as shown in the example below.

Instance code

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

Issue

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

Using CSS for one or more pages

Custom font for one page

In the head portion of your web folio, you may insert code between the <style></style> tabs to alter the appearance of your text in various elements. The next bluish box contains example code that, once called, would change your font confront to Courier and colour it cherry-red. Equally you tin see, we have defined the grade name as "custom."

<fashion type="text/css"> .custom {  font-family: Courier;  color: red;  font-size:20px; } </mode>

One time defined, this styling can be applied to most elements in your page past attaching the course "custom" to them. The following box shows two lines of lawmaking and their corresponding results.

Example

<p form="custom">This whole sentence is red and Courier</p> <p>Only the word <span class="custom">test</span> is cherry-red and Courier.</p>

Event

This whole sentence is cherry and Courier.

Only the give-and-take examination is red and Courier.

Custom font for many pages

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

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

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

Once the preceding text is placed into a .css file (nosotros have named ours basic.css), yous tin can link to it from whatever other page using a line similar to the following case.

<link rel="stylesheet" Blazon="text/css" href="http://www.instance.com/basic.css">

Tip

Users may change the attributes of elements on a folio by irresolute the code in the imported .css file.

Using the font tag

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 aspect, which describes the font to be used. In the example beneath, we are using the Courier font and the hexadecimal color code #005CB9, which is a nighttime blue.

Example lawmaking

<font color="#005CB9" face="courier" size="five">A special font example.</font>

Result

A special font instance.