html

Specifying Font and Size in HTML Table

When the tables are created in an HTML document, the developers want to define the size of the table and font of the table content to maintain a good graphical user interface. The traditional way to create a table in HTML is to add a “<table>” element. More specifically, to specify the font and size for the table, the “<font>” element is used.

This post will demonstrate the method to specify the font and size of an HTML table.

Using “<font>” Tag to Specify Font and Size in HTML Table

The developers can specify the font and size in the HTML table through the “<font>” element in such a way that this “<font>” element covers all the table content. The size of the table can be declared by using the “size” attribute inside the “<font>” opening tag and the font style can be declared through the “face” attribute.

Example

Let’s suppose, there is the following example of an HTML table for which we will define the font and size:

<font size="2" face="Courier">

<table class="tab">

<tr>

<td><b>ClientID</b></td>

<td><b>ClientName</b></td>

<td><b>Filename</b></td>

<td><b>KeyName</b></td>

</tr>

<tr>

<td>NEW51132</td>

<td>WINDOWS2012</td>

<td>demo.pdf</td>

<td>TestKey</td>

</tr>

</table>

</font>

In the above code snippet:

  • A “font” element is added that has the attributes “size” and “face” in the opening tag to specify the size and the font style of the table respectively.
  • Inside the “font” element, add a “table” element to create the table for which the above-mentioned size and the font style attributes have to be applied.
  • In the opening “table” tag, set the “class” attribute that defines a class named “tab”.
  • Inside the “table” element, specify the “<tr>” element that adds the table rows.
  • Inside the “<tr>” element, define the “<td>” elements to add the table cells and define each value to be added to the table.
  • Lastly, specify another “<tr>” element to add a separate row, and the “<tr>” elements inside it the same way as the rows added above.
  • This will create a single table in the output.

Now, we can create another HTML table with different values defined for the “size” and “face” attribute just to differentiate the font and size of the two different tables:

<font size="5" face="consolas">

<table class="tab">

<tr>

<td><b>ClientID</b></td>

<td><b>ClientName</b></td>

<td><b>Filename</b></td>

<td><b>KeyName</b></td>

<tr>

<td>NEW51132</td>

<td>WINDOWS2012</td>

<td>demo.pdf</td>

<td>TestKey</td>

</table>

</font>

In the above code snippet:

  • Another table created exactly the same way as in the previous section of this post. The only difference is that the values defined for the “size” and “face” attributes of the “font” tag are different.
  • Here, the size has been defined as “5” and the font face has been defined as “consolas”.

The CSS properties to create a better representation for both the tables are given below:

table, th, td{

border: 2px solid darkblue;

border-collapse: collapse;

}

.tab{

margin: 8px;

width: 80%;

}

The above code will create two different tables in the output. One with the size “2” and the font “courier” and the other with the size “5” and font “consolas”:

This is how we can specify the font and size in the HTML table.

Conclusion

In the HTML table, the font and size can be specified by adding the “<font>” element in such a way that it covers all the “<table>” elements inside it. The size of the table is defined by adding the “size” attribute and the font style of the table content is defined by adding the “face” attribute in the “<font>” opening tag. This post explained how to specify the font and size of the HTML table.

About the author

Hadia Atiq

A Software Engineer and Technical Writer passionate about learning and spreading knowledge of the latest technology. I utilize my writing skills to help readers understand the importance and usage of modern technology.