How to Use Embedded Fonts for Your HTML5 and CSS3 Based Web Pages
AccuWeb's Free Web Hosting

How to Use Embedded Fonts for Your HTML5 and CSS3 Based Web Pages

Want to get away from ‘Web Safe’ fonts for some attractive headers AND do it without using an image? Use CSS3 font Embedding and embed a font-face!

NOTE: This article uses font file stored online and your browser may run slow or attempt to crash… sorry!

@font-face is not strictly speaking ‘CSS3′; it was originally born in CSS 2 and although not appearing in CSS 2.1, CSS 3 is attempting to bring it into the standards.

In order to use a font, we first must call it using the ‘@font-face’ attribute and this must be done for each individual font we wish to use. Although I’m sure you have a few, you can download some fonts to experiment with here, at dafont.com.

CSS 3 Embedded Font Face

HELLO CSS 3 WORLD!

The above header uses the SketchRockwell font with the following CSS 3 applied to it.

CSS 3 Font Embed (Example I)

@font-face {
     font-family: ‘SoftSugarplainRegular’;
     src: url(‘fonts/Softplain-webfont.ttf’);
}

.fontface {
     font: 40px ‘SoftSugarplainRegular’, Arial, sans-serif;;
     letter-spacing: 0;
     text-align:center;
}

CSS3 can render type using several font formats: “truetype” (ttf),
“opentype” (otf), “embedded-opentype” (eot) and
“scalable-vector-graphic” (svg,svgz).

HELLO CSS 3 WORLD!

We can also apply additional effects such as a Text Shadow.

CSS 3 Font Embed (Example II)

	@font-face {
	  font-family: 'SoftSugarplainRegular';
	  src: url('fonts/Softplain-webfont.ttf');
	}
	.fontface1 {
	  font: 40px 'SoftSugarplainRegular', Arial, sans-serif;
	  letter-spacing: 0;
	  text-align:center;
	  text-shadow: 3px 3px 7px #111;
	}

NOTE: For some reason, using both @font-face and text-shadow will cause problems in Google Chrome. The reason IE has been given a ‘?’ next to it for the @font-face attribute, is because it will work using the popular .eot font file.

Don’t forget to subscribe to our RSS-feed, follow us on Twitter and follow us on Facebook – for recent updates.

Written by
AsHok Jain
Join the discussion

2 comments
  • Very cool – I’d heard about this, but hadn’t tried it myself yet.

    I’m curious about browser compatibility.

    “NOTE: This article uses font file stored online and your browser may run slow or attempt to crash… sorry!” Is there a size limitation on fonts that causes that?

Let’s get social

Web design blog for professionals with topics focusing on useful design techniques, design best practices and design inspiration. Subscribe for updates!

15585

JOIN OUR GROWING LIST OF SUBSCRIBERS!

Following our blog is a great way to make sure that you are up to date on the latest and greatest Freebies and WordPress news.

15856