Click here to Skip to main content
15,906,558 members
Articles / Web Development / HTML
Article

Set a fixed text size in your HTML

Rate me:
Please Sign up or sign in to vote.
1.57/5 (16 votes)
27 Nov 2000 236.1K   30   31
A very useful tip. How to keep your fonts a fixed size so your readers cannot can change it in their browser, ensuring your page always has the same look.

Note: This article only for those who have strong web design background. If you think the font size is not very important for your webpage, just skip this article.

You may meet the following problem: After your designed your page in your computer, everything seems fine. But when others use their own browers to view your file, the font size changed! Some text goes out of control and break your table background and move the image out of the original position. Let's see the following samples:

Banner:

This is a banner sample

Menu:

   Home   |  About Us   |   Our Products   |   Our Services   |   Tech Support   |   Contact Us   

Recipe:

Image 1 Dumpling Recipe LogoWlcome
Image 4
Boiled
Deep Fried
Pan Fried
Noodle Soup
soup w / Rice
American Style
Image 11
Food Service

Our Prime Aim is Quality Food
The Chinese have long enjoyed dumplings as a basic food. They are served daily and also at festive occasions. There are restaurants that have become famous for their dumplings. Who knows, maybe you could be famous for yours. Today, Americans are also very fond of dumplings, as they come in different styles and fillings, healthy and nutritious. It surely would become everybody's favorite. PRIME FOOD is proud to offer several kinds of dumplings, to provide you with many options and choices. From pork and cabbage dumplings to our delightful seafood dumplings, together with the various types of cooking directions, there's something for everyone.

Please change the font size to see what will happen. In IE, you can open the context menu "View", then "Text size" to change the text size to "Largest". In Netscape, the same function in the context menu: "View" > "Increase Font/Decrease Font".

As you can see. the result is too bad. If you don't think this matters then this article is not for you.

This problem is caused by the text size. How to fix this problem? There are different solutions. A common way is using images to stop the font size to be changed. As you may know, when you change the font size by the browser, the image size will not be changed. That's one of the reasons why most web designers use this method to make navigator menus, banners and other design that needs to type text on the pictures.

If you just want to stop the font size being changed and you use an image, it might not be the best solution.

Let me show you another solution.

We can use CSS to solve this problem. The following is the source code:

<html>
<head>
<title>How to set a fixed text size</title>
<style type="text/css">
<!--
.fixed {font-size:12px}
-->
</style>
</head>
<body>
<span class="fixed">This is a test.</span>
</body>
</html>

Open your browser, IE and Netscape, and try it now! Changing Text Font (IE) or Increase Font/Decrease Font (Netscape), you may see, the text size is fixed!

The point is set font size unit as "px", not "pt". The .fixed is a class selector. You can use any name for a class.

Any opening tag of HTML can be used as a selector. For example, <p>, <font>, <a>, <bockquote>, <pre>, <h1>, <i>, <table> and <td> etc. You also can take <body> tag as a selector. A sample as below:

<html>
<head>
<title>How to set a fixed text size</title>
<style type="text/css">
<!--
p {font-size:12px}
pre{font-size:10px}
h1{font-size:24px}
h2{font-size:18px}
-->
</style>
</head>
<body>
<h1>This is an example of CSS</h1>
<p>CSS is really useful.</p>
<pre> I set a fixed font for my page!</pre>
</body>
</html>

To learn more about CSS, you may go to: CSS For Beginners

One might say I don't like this solution because after setting a fixed font size, others can't change it. Perhaps I should mention that when you go to a book store to buy a book you also can't change the font size on the book. You may prefer other solutions for example using an image, but one thing is clear: The result is the same by using "image-text" and by using "CSS-fixed-text". You can't change an "image-text" by your browser. Besides, if one day you or your boss or your clients want to change the text, you will have to make the image again. It will take more time to do it than changing a CSS-fixed text.

Now this is not a law, just one of solutions. You still have your rights to use other solutions or use no solution. Or you may just use it on your banners, menus and headings, and keep other contents as usual.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
www.itechcollege.com
East Timor East Timor

Comments and Discussions

 
QuestionFixed Font Issue - please help! Pin
cmorello8-May-07 14:51
cmorello8-May-07 14:51 
Questionhow to set fixed font size for tables ? Pin
Anonymous28-Jan-05 6:50
Anonymous28-Jan-05 6:50 
AnswerRe: how to set fixed font size for tables ? Pin
Anonymous2-Apr-05 16:37
Anonymous2-Apr-05 16:37 
GeneralRe: how to set fixed font size for tables ? Pin
jerychen2-Sep-05 2:50
jerychen2-Sep-05 2:50 
GeneralRe: how to set fixed font size for tables ? Pin
jerychen2-Sep-05 3:08
jerychen2-Sep-05 3:08 
GeneralDosn't realy work in IE Pin
TC100024-Mar-04 3:03
TC100024-Mar-04 3:03 
Generalfont-size to pixel conversion for browsers Pin
7-Feb-03 9:07
suss7-Feb-03 9:07 
GeneralNetscape won't work!!!! Pin
Anonymous8-Nov-02 5:26
Anonymous8-Nov-02 5:26 
GeneralRe: Netscape won't work!!!! Pin
Paul Watson8-Nov-02 5:30
sitebuilderPaul Watson8-Nov-02 5:30 
GeneralRe: Netscape won't work!!!! Pin
Anonymous8-Nov-02 5:41
Anonymous8-Nov-02 5:41 
GeneralRe: Netscape won't work!!!! Pin
Paul Watson8-Nov-02 5:48
sitebuilderPaul Watson8-Nov-02 5:48 
GeneralRe: Netscape won't work!!!! Pin
Anonymous26-Dec-03 23:19
Anonymous26-Dec-03 23:19 
GeneralComments Pin
Christopher Lord28-Sep-02 15:47
Christopher Lord28-Sep-02 15:47 
Although fixed-font designs are one valid solution to the problem, they are not the best.

Check out EM's instead of PT or PX if you want your page to scale correctly with the font size system in the browser.
GeneralPixels, Points, and Macs Pin
9-Apr-02 3:48
suss9-Apr-02 3:48 
GeneralJust saved my life!!!!!! Pin
12-Feb-02 6:59
suss12-Feb-02 6:59 
GeneralI think this is a great tip! Pin
31-Oct-01 6:11
suss31-Oct-01 6:11 
QuestionNobody cares about the visually handicapped? Pin
7-Oct-01 16:41
suss7-Oct-01 16:41 
AnswerRe: Nobody cares about the visually handicapped? Pin
27-Apr-02 16:11
suss27-Apr-02 16:11 
GeneralRe: Nobody cares about the visually handicapped? Pin
7-Jun-02 5:49
suss7-Jun-02 5:49 
GeneralRe: Nobody cares about the visually handicapped? Pin
13-Jun-02 20:54
suss13-Jun-02 20:54 
AnswerRe: Nobody cares about the visually handicapped? Pin
Anonymous20-May-03 5:06
Anonymous20-May-03 5:06 
GeneralRe: Ha ha! Pin
external thread24-Jun-04 6:38
sussexternal thread24-Jun-04 6:38 
GeneralCSS is the way to go! Pin
2-Jan-01 8:33
suss2-Jan-01 8:33 
GeneralRe: CSS is the way to go! Pin
1-Jul-01 22:41
suss1-Jul-01 22:41 
GeneralDefeats the purposes of machine-independence! Pin
Robin Hilliard19-Oct-00 2:31
Robin Hilliard19-Oct-00 2:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.