Windows.  Viruses.  Laptops.  Internet.  Office.  Utilities.  Drivers

11/27/14 88.7K

In html, font size plays an important role. It allows you to draw the user's attention to important information posted on the site page. Although not only the size of the letters is important, but also their color, thickness and even family.

Tags and attributes when working with html fonts

Hypertext language has a wide range of tools for working with fonts. After all, text formatting is the main task of html.

The reason for the creation of the HTML language was the problem of displaying text formatting rules in browsers.


Let's look at the tags that are used to work with fonts in HTML and their attributes. The main one is the tag . Using the values ​​of its attributes, you can set several characteristics of the font:
  • color – sets the text color;
  • size – font size in conventional units.

Positive attribute values ​​from 1 to 7 are supported.

  • face – used to set the text font family that will be used inside the tag . Several values ​​are supported, separated by commas.

Only the text that is located between the parts of the paired font tag is formatted. The rest of the text is displayed in the standard default font.


Also in html there are a number of paired tags that specify only one formatting rule. These include:
  • — sets bold font in html. Tag similar in action to the previous one;
  • — the size is larger than the default;
  • — smaller font size;
  • — italic text (italics). Similar tag ;
  • — text with underlining;
  • - crossed out;
  • — display text only in lower case;
  • - in upper case.

Plain text

Thumbnail

Thumbnail

More than usual

Less than usual

Italics

Italics

With underscore

Crossed out

Style attribute capabilities

In addition to the described tags, there are several more ways to change the font in html. One of them is to use the generic style attribute. Using the values ​​of its properties, you can set the font display style:

1) font-family – the property sets the font family. It is possible to list multiple values.
Changing the font in html to the next value will occur if the previous family is not installed on the user's operating system.

Writing syntax:

font-family: font-name [, font-name[, ...]]

2) font-size – the size is set from 1 to 7. This is one of the main ways you can increase the font in HTML.
Writing syntax:

font-size: absolute size | relative size | meaning | interest | inherit

You can also set the font size:

  • In pixels;
  • In absolute terms ( xx-small, x-small, small, medium, large);
  • In percentages;
  • In points (pt).

Font-size:7

Font-size:24px

Font-size: x-large

Font-size: 200%

Font-size:24pt


3) font-style – sets the font writing style. Syntax:

font-style: normal | italic | oblique | inherit

Values:

  • normal – normal spelling;
  • italic – italic;
  • oblique – font slanted to the right;
  • inherit – inherits the spelling of the parent element.

An example of how to change the font in html using this property:

font-style:inherit

font-style:italic

font-style:normal

font-style:oblique


4) font-variant – converts all capital letters to capital letters. Syntax:

font-variant: normal | small-caps | inherit

An example of how to change the font in html with this property:

font-variant:inherit

font-variant:normal

font-variant:small-caps


5) font-weight – allows you to set the thickness of the text (saturation). Syntax:

font-weight: bold|bolder|lighter|normal|100|200|300|400|500|600|700|800|900

Values:

  • bold – sets the html font to bold;
  • bolder – bolder relative to normal;
  • lighter – less saturated relative to normal;
  • normal – normal spelling;
  • 100-900 – sets the font thickness in numerical equivalent.

font-weight:bold

font-weight:bolder

font-weight:lighter

font-weight:normal

font-weight:900

font-weight:100

HTML font property and font color

Font is another container property. Inside itself, it combined the values ​​of several properties intended for changing fonts. font syntax:

font: font-size font-family | inherit

The value can also be set to the fonts used by the system in the labels on various controls:

  • caption – for buttons;
  • icon – for icons;
  • menu - menu;
  • message-box – for dialog boxes;
  • small-caption – for small controls;
  • status-bar – status bar font.

What does a website visitor actually see when using a non-standard Web font at this stage of browser development?

Many people struggle when creating a website. In many cases, a website requires using a non-standard font or hieroglyph. You download a beautiful font and start laying out the page, but not all users have such fonts. Some people are not embarrassed and simply create a graphic file using the font they need, but additional graphics do not always suit the page and many already have enough of it. But there is one suitable way out! This solution is to use CSS (Cascading Style Sheets) technology or simply “Cascading Style Sheets”. Usually CSS is contained in the created file itself, the page, but you can create a CSS file (.css) separately and connect it by writing between the tag Thus:

And with the help of CSS, we need to automatically download and install the True Type Font (.ttf) font file, but the installation will only happen if the user’s computer does not detect the required font. First of all, we must specify the location of the font. To do this, we write between the tags And So:

This way you can use any fonts on your website. But I advise you not to get too sophisticated, since the process of downloading and installing the font also requires some time. And if your font itself “weighs” 500kb or more, then it is not recommended to use it in this case.

Honestly, it’s easier and more correct to do this:


Although Web fonts are supported by most browsers, in Opera they are buggy from the very beginning. On some systems they don’t work at all, on those that do work, when the pages are reloaded they may or may not work:

Therefore, this cannot be used in serious projects, only in personal blogs, and only for text larger than 30px, so as not to see the wonders of anti-aliasing and kerning.

At the same time Google provides an API for cross-browser connection of non-standard fonts.







Making the Web Beautiful!



Google detects the browser and provides valid CSS and font for it.

In the next project, I once again see headings and menus in a non-standard font. Make it with pictures? Sucks: awkward, inflexible, slow. Flash? I can't stand him. Javascript? The best solution for now, of course, but it’s still a crutch that reminds us of the limitations of browsers. It's time to dig into the standards: what they offer and where it already works.

The note

A custom font, in contrast, is a font that is likely to be missing from most site visitors.

Task

Implement a custom font without using images, javascript and flash. We use only the latest advances in .

Solution

But for IE it’s not so simple. Although it was the first to support the implementation of third-party fonts (since 1997 with the release of Internet Explorer 4th version!!!), it requires a special format for the font - EOT (Embedded OpenType). The EOT format solves two problems at once:

  • compresses the font file, making its weight several times smaller (judging by the tests of colleagues, this method compresses better than RAR, ZIP, and gzip methods)
  • encrypts the file: information is written to the font file where it should be used. This font will not work outside of this address.

As a result, connecting the font in styles will look like this hack:

/* only for Internet Explorer */ @font-face ( font-family: Scriptorama; src: local("Scriptorama"), url(path-to/Scriptorama.eot); ) /* further for all other browsers */ @ font-face ( font-family: Scriptorama; src: local("Scriptorama"), url(path-to/Scriptorama.ttf); ) [...] h1 ( font-family: Scriptorama, arial; font-weight: normal;

Instead of a hack, you can use .

update 23.08.11 A more complete font embedding syntax that takes into account some possible IE bugs and greater browser support:

@font-face ( font-family: "JournalRegular"; src: url("journal-webfont.eot"); src: url("journal-webfont.eot?#iefix") format("embedded-opentype"), url("journal-webfont.woff") format("woff"), url("journal-webfont.ttf") format("truetype"), url("journal-webfont.svg#JournalRegular") format("svg "); font-weight: normal; font-style: normal; )

The note

update 10.11.10 In IE local may not work. Moreover, because of it, the font may not be connected at all. In our projects we pay attention to this point: if it doesn’t work, we simply remove it for IE local.

Advantages:

  • flexibility - the site owner can change any texts as he pleases;
  • fast loading speed - a minimum number of external files with any amount of text in a non-standard font;
  • maximum speed of the site - zero additional elements in the DOM structure, zero scripts and flash objects slowing down the site;
  • the text behaves like text (after all, it remains text), i.e. stands out, responds to changes in color, boldness, style, etc., ideal SEO;
  • Quite simple implementation even taking into account font optimizations.

Flaws:

Font compression and conversion

If the font developers tried to please everyone, then the font will most likely contain many, many characters and, accordingly, weigh many, many. So the Arial Unicode MS font contains 51 thousand characters and weighs more than 23 megabytes! It's time to think about whether the site will use Udmurt or Finno-Ugric languages? And also various additional symbols, punctuation marks and numbers? You should also pay attention that each font has a certain number of styles: regular, italic, bold, semibold. A font can contain up to 9 types of boldness (remember the acceptable values).

What to do

We exclude from the font everything that is not needed to achieve the task. For example, if the font is used only for the menu, then punctuation marks, various additional symbols, and numbers will be superfluous.

How to do

The following may help with this:

Online service @font-face Generator

What can:

  • two operating modes: Easy - for those who don’t want to delve into it and Expert - for maximum optimization
  • different formats of results and it’s in one place! Those. no need to first compress True Type for all browsers, and then separately convert to EOT for IE
  • various options for obtaining results. Right down to protecting the font from local use and the file for Cufon!
  • precise selection of characters for a compressed font. You can specify the language and a set of additional characters, or you can specify the range of characters used, or simply list the characters that are needed, or use a symbiosis of all methods
  • for those who are weak in CSS, even style rules will form

For the experiment, I compressed a 145Kb font with the “Use for menu” test task. I left only small Russian letters. The final font size was 8Kb. Amazing!

Flaws:

  • EOT is generated without being tied to a specific domain (for serious projects you will still have to do EOT separately)
  • not all licensed fonts can be processed (this is a relative disadvantage)

Impression- fantastic, excellent, super-duper, amazing!!! I'll get myself a PayPal to donate.

Web Font Optimizer

An online service that allows you to leave only the necessary characters. Works .

Pros: simple and clear. The result is a True Type compressed font, an EOT font for IE and CSS code for connection.

On the downside: the service is only available for a strictly fixed list of fonts that they have on their website.

WEFT

Software from Microsoft. Helps convert font to EOT. Plus makes it impossible to use the font outside the specified site. You can download and get acquainted in more detail on the page dedicated to the script.

TTF2EOT

From the name it is clear that it converts a font from TTF to EOT. It works locally via the command line, which in itself is not convenient. You can download the script and read more about it on the project website.

Online Font Converter

Easy to use, allows you to convert licensed fonts. Available.

Disadvantages: registration is required.

What about font protection?

If the font is of high quality, it is developed by high professionals, often by a team of professionals, often for more than one month. Such a font can cost no less than “Zhiguli” from the assembly line. Font developers began to register them as trademarks, securing the rights of the copyright holder to the font at the level of industrial property protection.

Those. To use a font on the web, the site owner must purchase the font with the right to use it on the web. But acquisition is half the problem. The font also needs to be protected from illegal copying. There are almost no such problems if the licensed font on the site is implemented with pictures or using Javascript. But if you implement it via @font-face, the font is openly located on the server, which any user can download. And this already threatens lawsuits.

The note

For millions of small sites, the illegal use of fonts can and will pass without consequences, but cool, commercial, especially international projects should seriously think about purchasing licenses.

How to protect a font?

For IE, this problem was solved immediately - the EOT format encrypts the file. As a result, we have a font that will only work within this site.

The other day, once again, I decided to start doing push-ups. One teacher I respect claims that this exercise has an almost magical effect if done correctly.

Well, I set up an experiment on myself, and to make it harder to jump off, I decided to make the “laboratory notebook” public and posted it on an abandoned blog.

The old design did not match the new idea, and without hesitation, I took the one I more or less liked from the general WordPress repository.

Do you know what the problem is with some ready-made templates taken from there? The problem is clumsy compatibility with Cyrillic fonts. In my case, the headers suffered. Since the font referenced by the CSS did not contain Russian characters, they were taken from the default font (either Sans or Arial). As a result, the headlines were HUGE and ruined the whole look. I had to think how to replace the font.

There are several ways to do this.

Method 1: Dumb

It comes down to the fact that you find a suitable font on the Internet, install it on your computer, write it in CSS and see your site as intended.

Others continue to see it, at best, with default fonts, and at worst, even out of print.

Don't do this!

Method 2: Convert the design to a standard font

This is the most ideal option, but, unfortunately, it is not always suitable, since sometimes the “zest” of the design is lost because of it. However, ALWAYS consider this approach, because no matter how hard you try, it is possible that the client computer will still use the font that is available.

Safe fonts that are available on almost all operating systems are: Verdana (ideal for texts),Impact (sometimes very good in headlines), Arial, Arial Black, Comic Sans MS (kaka, which is very popular among beginners), Courier New (suitable for code examples and forms), Georgia, Times New Roman, Trebuchet MS.

Method 3: Picture instead of text

The option is very cross-browser and suitable for designing static elements. For example, site headers. You make a transparent PNG with text in the desired font, process it as you need and insert it into the site, not forgetting to fill in the ALT. Or the same thing, but paste the text onto some background and save it as a JPG.

In addition to the header, I needed to change the appearance of post headers and widgets. Well, why not make a separate picture with a title for each entry?

Although there are craftsmen who generate pictures with title text using server scripts, this is already a perversion.

Method 4: Cufon

These applets can be generated from a font file using the online generator http://cufon.shoqolate.com/generate/

The easiest way is to use http://www.google.com/fonts You select the desired font from those presented and get ready-made code that you need to insert into the site (in the head and in the style file), after which everything works.

But I didn’t want to use extra javascript, bother with generating applets, etc. I wanted to do everything quickly and simply. Moreover, the file with the required font had already been available for a long time.

Method 4: Connect the font to the site using CSS

The Internet is full of guides on this topic. However, having tried five of them, I came to a disastrous result. My TTF font was displayed normally only in IE. In other browsers it was mercilessly replaced by Arial.

I confess that I am not a fan of IE and consider it a browser download browser. No more! So, I had to make a small improvement.

To connect a font to the site using CSS, we need the font itself (file) and an online converter http://onlinefontconverter.com/

There can be a great variety of online font converters. Some are closed, new ones appear in their place, so if this particular one is no longer there, search in search engines for a query like “online font converter” and try to convert the fonts there. In this post, the given converters are used as an example.

1. Go to the converter website , grab the font you have and drag it into this window (it’s usually in the right column).

2. Download the font in 4 variants: EOT, OTF, TTF and WOFF. This should be enough. The browser, in the process of rendering the page, will choose and download the one that is more convenient for it.

3. Upload fonts to the website. I created a folder for this in the root of the site "f" and placed them there.

Update 02/16/2015: For now onlinefontconverter.com remade and it didn’t convert any of the proposed fonts((

I had to use the site font2web.com. This one provides all the necessary fonts at once in a pack in one archive. Comfortable!

4. Connect font loading to the site. To do this, enter this code in the css file, or in the appropriate style tags.

@font-face( font-family: EtoMoiFont; src: url(/f/myFont1.eot), url(/f/myFont1.otf), url(/f/myFont1.ttf), url(/f/myFont1. woff);

font-family: EtoMoiFont;— tells the browser what the loaded font will be called. Come up with a name yourself.

src: url(/f/myFont1.eot), url(/f/myFont1.otf), url(/f/myFont1.ttf), url(/f/myFont1.woff);— specifies the path and names of font files.

Why are the fonts in this order?

The first one I put EOT. This format is used by older versions of IE.

SecondOTF. This is a compressed font format that is supposed to weigh less.

ThirdTTF. Almost all browsers understand it. Although, it happens differently. For example, on iOS it may not open.

LastWOFF. This should read well on Macs, but I haven't had time to check it yet.

5. Designate in the style file , which font family should be used to display headings (in our case, headings h2).

h2(font-family: EtoMoiFont;)

Ready!

If the fonts are not applied, make sure: firstly, that the css file is used by the site (sometimes you need to reset the cache, sometimes look for another css file), secondly, that the font is used for the class (id or tag) you specified. are not blocked in another css file that is loaded after this.

The beauty of this method is that in the future I can set this font for any text container.


This is what happened.

The disadvantage of the method is that the browser settings of some paranoid users may prohibit loading external fonts, flash, javascript, pictures, etc.

So don't be lazy and check what your site will look like if loaded fonts are disabled. Try playing with safe ones method 2, and then load yours again. If the sizes are more or less the same and nothing has moved apart, then it’s in order.

And further! Test methods only on computers where the font you are going to work with is not installed. Otherwise it will work out method number 1.

That's all. I was with you.
Until next time.

Adding a new font to a website is not the easiest task. Where to choose, download and how to add a font to a website in CSS? In this article we will show one of the most convenient ways to install and connect the font to the site.

How to include a font on a website in CSS

For example, we have a font Raleway.ttf and we want to use it in all headers( h1) of our website. To do this, perform the following steps:

h1 ( font-family: "RalewayRegular"; }

Now all 1st level headings on the site are displayed in the font we need.

If you want to connect several fonts (or their styles), then simply add them under the previous one:

@font-face { font-family: "RalewayRegular"; src: url("../fonts/RalewayRegular.ttf" ) format( "truetype"); font-style : normal; font-weight: normal; } @font-face{ font-family: "RalewayBold"; src: url("../fonts/RalewayBold.ttf" ) format( "truetype"); font-style : normal; font-weight: normal; }

You might have noticed that there are different font formats - .ttf, .woff, .eot, .svg etc. There is also a format for modern browsers. woff2, but we will talk about it in one of the following articles. Typically, each font is connected in 3 formats at once. This is done so that the font is displayed correctly in all browsers, including. and old ones. It looks like this:

@font-face { font-family: "RalewayRegular"; src: url( "../fonts/RalewayRegular/RalewayRegular.eot") ; src: url( "../fonts/RalewayRegular/RalewayRegular.eot?#iefix") format("embedded-opentype" ), url( "../fonts/RalewayRegular/RalewayRegular.woff") format( "woff"), url( "../fonts/RalewayRegular/RalewayRegular.ttf") format( "truetype"); font-style : normal; font-weight: normal; }

Here follows Pay attention to the connection order - this is important!

We will not go into details, just remember the appearance of this design.

If you have a font in only one format, then use different font converters. Here is one of them.


How to connect a font using various services

You can also use the fonts4web service to connect fonts:


The easiest way to connect fonts


How to connect a font to a Moguta CMS template


How to add a link with Google fonts to a Moguta CMS template


Now you know how to add a font to a website using CSS and more. We will be happy to answer all your questions

If you notice an error, select a piece of text and press Ctrl+Enter
SHARE: