Using Web Fonts

Description

In order to choose a font independant on the user's machine, you can use web fonts, where you can download a font and use it.

You specify web fonts using @font-face.

Example


<!DOCTYPE HTML>
<html>
<head>
<style>
@font-face  {
    font-family:  'MyFont';
    font-style:  normal;
    font-weight:  normal;
    src: url('http://java2s.com/MyFont.woff');
}<!--from w  w  w. j a  va 2 s .c  om-->
p  {
    padding: 5px;
    border: medium double   black;
    background-color: lightgrey;
    margin: 2px;
    float: left;
    font-size: medium;
    font-family: MyFont,  cursive;
}
#first {
    font-weight: bold;
}
#second  {
    font-style: italic;
}
</style>
</head>
<body>
    <p>
        this is a <span  id="first">test</span>.
        this is a <span  id="second">test</span>.
    </p>
</body>
</html>

Click to view the demo

Note

When you use @font-face, you use the standard font properties to set the web font.

The font-family property defines the name for the downloaded font, and the font-style and font-weight properties controls the style and weight settings.

The src property is used to specify the location of the font file.





















Home »
  HTML CSS »
    CSS »




CSS Introduction
CSS Background
CSS Border
CSS Box Layout
CSS Text
CSS Font
CSS Form
CSS List
CSS Selectors
CSS Others
CSS Table