Specifying Font and Size in HTML table

301,142

Solution 1

Enclose your code with the html and body tags. Size attribute does not correspond to font-size and it looks like its domain does not go beyond value 7. Furthermore font tag is not supported in HTML5. Consider this code for your case

<!DOCTYPE html>
<html>
<body>

<font size="2" face="Courier New" >
<table width="100%">
    <tr>
        <td><b>Client</b></td>
        <td><b>InstanceName</b></td>
        <td><b>dbname</b></td>
        <td><b>Filename</b></td>
        <td><b>KeyName</b></td>
        <td><b>Rotation</b></td>
        <td><b>Path</b></td>
    </tr>
    <tr>
        <td>NEWDEV6</td>
        <td>EXPRESS2012</td>
        <td>master</td><td>master.mdf</td>
        <td>test_key_16</td><td>0</td>
        <td>d:\Program&nbsp;Files\Microsoft&nbsp;SQL&nbsp;Server\MSSQL11.EXPRESS2012\MSSQL\DATA\master.mdf</td>
    </tr>
</table>
</font>
<font size="5" face="Courier New" >
<table width="100%">
    <tr>
        <td><b>Client</b></td>
        <td><b>InstanceName</b></td>
        <td><b>dbname</b></td>
        <td><b>Filename</b></td>
        <td><b>KeyName</b></td>
        <td><b>Rotation</b></td>
        <td><b>Path</b></td></tr>
    <tr>
        <td>NEWDEV6</td>
        <td>EXPRESS2012</td>
        <td>master</td>
        <td>master.mdf</td>
        <td>test_key_16</td>
        <td>0</td>
        <td>d:\Program&nbsp;Files\Microsoft&nbsp;SQL&nbsp;Server\MSSQL11.EXPRESS2012\MSSQL\DATA\master.mdf</td></tr>
</table></font>
</body>
</html>

Solution 2

First, try omitting the quotes from 12 and 24. Worth a shot.

Second, it's better to do this in CSS. See also http://www.w3schools.com/css/css_font.asp . Here is an inline style for a table tag:

<table style='font-family:"Courier New", Courier, monospace; font-size:80%' ...>...</table>

Better still, use an external style sheet or a style tag near the top of your HTML document. See also http://www.w3schools.com/css/css_howto.asp .

Solution 3

This worked for me and also worked with bootstrap tables

<style>
    .table td, .table th {
        font-size: 10px;
    }
</style>

Solution 4

The font tag has been deprecated for some time now.

That being said, the reason why both of your tables display with the same font size is that the 'size' attribute only accepts values ranging from 1 - 7. The smallest size is 1. The largest size is 7. The default size is 3. Any values larger than 7 will just display the same as if you had used 7, because 7 is the maximum value allowed.

And as @Alex H said, you should be using CSS for this.

Share:
301,142

Related videos on Youtube

Neil Weicher
Author by

Neil Weicher

Founder and CTO of NetLib Security Inc www.netlibsecurity.com Providing data encryption and key management for over twenty years.

Updated on January 07, 2020

Comments

  • Neil Weicher
    Neil Weicher over 4 years

    I am trying to specify the Font Face and Size for text in a table. It seems to respect the FACE= but ignores the SIZE=. For example, I have the HTML shown below. It correctly displays the text in Courier New, but both tables display with the same font size. Any clue what I am doing wrong?

    <font face="Courier New" size="12"><table width="100%"><tr><td><b>Client</b></td><td><b>InstanceName</b></td><td><b>dbname</b></td><td><b>Filename</b></td><td><b>KeyName</b></td><td><b>Rotation</b></td><td><b>Path</b></td></tr>
    <tr><td>NEWDEV6</td><td>EXPRESS2012</td><td>master</td><td>master.mdf</td><td>test_key_16</td><td>0</td><td>d:\Program&nbsp;Files\Microsoft&nbsp;SQL&nbsp;Server\MSSQL11.EXPRESS2012\MSSQL\DATA\master.mdf</td></tr>
    </table></font>
    <font face="Courier New" size="24"><table width="100%"><tr><td><b>Client</b></td><td><b>InstanceName</b></td><td><b>dbname</b></td><td><b>Filename</b></td><td><b>KeyName</b></td><td><b>Rotation</b></td><td><b>Path</b></td></tr>
    <tr><td>NEWDEV6</td><td>EXPRESS2012</td><td>master</td><td>master.mdf</td><td>test_key_16</td><td>0</td><td>d:\Program&nbsp;Files\Microsoft&nbsp;SQL&nbsp;Server\MSSQL11.EXPRESS2012\MSSQL\DATA\master.mdf</td></tr>
    </table></font>
    
  • uncoder
    uncoder over 7 years
    FYI, quotes are mandatory. But you're right, CSS, inline or otherwise, is the way to go, as FONT tag is not longer supported.
  • Neil Weicher
    Neil Weicher over 7 years
    Thanks. It was the missing <!DOCTYPE html>. Once I added that it worked.
  • Neil Weicher
    Neil Weicher over 7 years
    Looks like switching to inline CSS is the way to go.
  • LexH
    LexH almost 5 years
    Inline is OK for quick-and-dirty, but specifying a class attribute is better in the long run.
  • Mark Longmire
    Mark Longmire over 4 years
    FYI Using the inline style on table has no affect on embedded input elements. The post on in-line styling helped me a lot, just wanted to do an FYI on the INPUT element. I'm sure there are other elements that will not inherit the style from the table. And I agree, a supporting css file is the best solution.