Use Web Font in CSS
Web font is the font that is put on the website by website designers, without installing on the user's computer.
To do this, you use a rule called @ font-face , which creates a identifier font and points to a font file stored on the Internet.
When users browse the web, they will automatically download the font and see the unique and strange font effects and may be "unique" only your website.
In this article, TipsMake.com will work with you to learn how to use @ fonf-face, invite you to follow it.
Common font formats
1. TrueType Font (TTF)
TrueType is a standard font, developed by Apple and Microsoft in the late 1980s. TrueType is the most popular font format for both MacOS and Microsoft Windows operating systems.
2. OpenType Font (OTF)
OpenType is a cross-platform computer font format and contains extended character sets, developed based on TrueType and trademarked by Microsoft. OpenType font is commonly used today on mainframe platforms.
3. The Web Open Font Format (WOFF)
WOFF is the format used to develop Webpage, developed by Mozilla and some other organizations in 2009. WOFF is essentially an OpenType or TrueType added with some descriptive data and part of its own format. yourself, making the transmission of the network lighter. W3C encourages the use of this format.
4. The Web Open Font Format (WOFF 2.0)
WOFF2 is an upgraded version of WOFF developed by Google with an average compression capability 30% higher than WOFF 1.0.
5. SVG Font / Shape
SVG Font is a font consisting of SVG characters (image - color or colorless), different from the normal font in that the letters are all images, so it has enough visual effects , such as dust effect, color, watercolor . SVG Font is never compressed and is usually quite large in size.
6. Embedded OpenType Fonts (EOT)
EOT , developed by Microsoft, is a compact OpenType format, designed to be used as embedded fonts on websites.
How to use @ font-face
To use @ font-face , we gather many CSS properties in combination with the font format to create the desired font types.
Attribute Value Description font-family name Specify a name for the font. src URL (Required) The path to where the font is located. font-stretch normalcondensed
ultra-condensed
extra-condensed
semi-condensed
expanded
semi-expanded
extra-expanded
ultra-expanded Specifies whether text is wider or narrower. The default value is "normal". font-style normal
italic
oblique (Optional) Define font-style. The default value is "normal". font-weight normal
bold
100
200
300
400
500
600
700
800
900 (Optional) Determine the font-weight. The default value is "normal". unicode-range unicode-range Specifies the range of UNICODE characters that the font supports. The default value is "U + 0-10FFFF".
For example
Example 1: Use the font you want
@font-face {
font-family: FontQuanTriMang;
src: url(sansation_light.woff);
}
div {
font-family: FontQuanTriMang;
}
Results show:
Full code:
@ font-face in CSS
My love - Westlife
An empty street
An empty house
A hole inside my heart
I'm all alone
The rooms are getting smaller
I wonder how
I wonder why
I wonder where they are
The days we had
The songs we sang together
Oh yeah
And all my love
I'm holding on forever
Reaching for the love that seems so far
So I say a little prayer
And hope my dreams will take me there
Where the skies are blue
To see you once again, my love
Over seas from coast to coast
To find the place I love the most
Where the fields are green
To see you once again, my love
Example 2: Use bold letters
@font-face {
font-family: FontQuanTriMang;
src: url(sansation_bold.woff);
font-weight: bold;
}
"sansation_bold.woff" is another font file, containing bold characters for Sansation fonts in example 1.
The browser will use this format whenever the text with the font "FontQuanTriMang" is bold.
Full code:
@ font-face in CSS
I Lay My Love on You - Westlife
Just a smile and the rain is gone
Can hardly believe it (yeah)
There's an angel standing next to me
Reaching for my heart
Just a smile and there's no way back
Can hardly believe it (yeah)
But there's an angel and she's calling me
Reaching for my heart
I know, that I'll be ok now
This time it's real
I lay my love on you
It's all I want to do
Every time I breathe I feel brand new
You open up my heart
Show me all your love, and walk right through
As I lay my love on you
Previous article: Some properties of handling Text in CSS
Next lesson: 2D Transform in CSS
You should read it
- What is Icon Font and how to create Icon Font
- Font format in Word
- Instructions for setting the default font in Microsoft Word
- Font in CSS
- How to install fonts on iPhone, iPad
- How to fix font errors Word, Excel, transcoding fonts super fast
- How to change fonts in Windows 11
- How to change the Zalo font on the phone
May be interested
- How to change fonts in Windows 11tired of windows 11's default fonts? here's how to set them to whatever you like. this article shows you how to change the windows 11 system font so that different areas of the os will use the font type you prefer.
- Microsoft released Font Maker, allowing users to freely create their own font on Windows 10font maker is a font creation application that allows windows 10 users to create their own personalized font by writing each letter and symbol.
- How to download and install Vietnamese fonts for computersfull vietnamese font set will help you not to have font error or vietnamese typing when writing, chatting, surfing the web or adding text in your graphic designs. download the full set of vietnamese fonts and install the font on your computer according to the quick instructions below.
- How to set the default font and font size on Excelon windows operating systems, excel uses the calibri font as the default font. however, if you want to use another font or simply change the default font size, you just need to adjust some settings on excel.
- Set the default font and font size in Excelevery time you open excel, you must align the font format and font size accordingly. the following article will guide you how to set the default font size and font size in excel.
- How to change the font in WordPressonce you have successfully installed and set up wordpress on localhost, you realize one thing: wordpress's default font when typing vietnamese does not look good, it is not beautiful when using large font size, or zoom in. .. or simply, we want to change the default font of wordpress, how to do it?
- How to Add Font in Microsoft Wordthis wikihow teaches you how to install a font on your windows or mac computer in order to use the font in microsoft word. download the font from a trusted website. fonts are a common way to transmit viruses, so take care to only download...
- Set the default font in Word 2007 2010 2013before drafting, you usually install the font and font size in the first font. it is simple but if you have to work a lot with word, then setting the font and font size will be very time consuming.
- How to change the system font after updating Windows 10 Creator's Updatechanging the size of the system font is probably just a small but surprisingly useful feature.
- Font format on Wordinstructions on how to format fonts in word. 1. font format before editing the text you should format the font first. to format the font perform the following steps: step 1: go to the home tab - click the font icon below (or click the