How to get started with layer fonts in CSS

We might be inclined to think of highly decorative and multi-colored fonts as belonging to the digital type age. Not so. Chromatic Type which enabled the use of outlines, shadows, and multiple colors (among other things) go back to the mid-19th century. They were made up of two or more corresponding sets that were printed one over the other, to create the desired effect.

Their digital descendants are designed to work in exactly the same way. Each style in a layer font family can be combined with its complementary styles to form a composite.

There is generally a regular (or fill) style which can be used independently and then several supplementary styles, such as outlines and decorations, that can be added on top. The supplementary styles are generally not usable independently, they need to be used in conjunction with at least one other style in order to be legible. Many layer font families also come with a ready-made composite style.

 

Layer fonts in the browser

In Photoshop, Illustrator, or any other graphics programme which utilizes layers, layering fonts is straightforward enough, but how does this work in a browser?

Layering fonts with divs

One approach would be to create several <div>s and pin them to the same point like this:

<!-- HTML-->
<div id="first">
 <h1>Using Layer Fonts In CSS</h1>
</div>
<div id="second">
 <h1>Using Layer Fonts In CSS</h1>
</div>
<div id="third">
 <h1>Using Layer Fonts In CSS</h1>
</div>

/* CSS */
#first, #second, #third{
 display: block;
 position:absolute;
 top:10px;
 left:5px;
}
h1 {
 font:5em 'One';
 color:rgba(200,0,0,.85);
}
#second h1 {
 font-family:'Two';
 color:rgba(0,200,0,.85);
 }
#third h1 {
 font-family:'Three';
 color:rgba(0,0,200,.85);
}

While this does work, it involves creating a div for each layer of the font, and then repeating the same content in each div. The resulting markup is a semantic mess, failing entirely to separate content and style information.

Layering fonts with pseudo elements

There is another, relatively simple, technique that doesn’t interfere with the markup: by using the ::before and ::after pseudo elements the text can be layered without cluttering up the html.

Here’s what we’re going to build:

(If you’d like to follow along with the very short code, you can download the files here. Unfortunately the fonts I’m using (Homestead which is a comprised of 6 styles, 3 of which are specifically designed to be used together) aren’t included in the download, but you can download them as donation-ware from here. I’ve loaded each font file using the @fontface rule.)

In the markup, we create an <h1> containing the text to be layered, and then place a <div> around it. We add a text attribute to the <h1> tag and set it to match our heading text (this will later be used by the CSS to set the content of the ::before and ::after). By setting the content of the pseudo-elements in the attribute we are keeping the content in the markup (just about), this means we don’t have to set the content of the pseudo-elements in the CSS.

(If you are using JavaScript, or even something like PHP, then it’s a good idea to insert the attribute and the value at the same time to avoid typos creating mismatched text.)

<div>
 <h1 text="Using Layer Fonts In CSS">Using Layer Fonts In CSS</h1>
</div>

In the CSS, we start by styling the h1. Although the ::before and ::after pseudo classes are supported by all major browsers, it is a good idea for the h1 to use a style which will be readable on its own, to cover legacy browsers.

Layer fonts tend to contain a fair bit of detail, so it’s best to use them at large sizes. For this example I’m using Homestead Display at 5em.

h1 {
 font: 5em ‘Display’;
 color:rgba(100,60,20,1);
}

The ::before and ::after are set to use a different font and color:

h1::before {
 content: attr(text);
 font-family:'Two';
 color:rgba(150,150,100,.5);
}
h1::after {
 content: attr(text);
 font-family:'Three';
 color: rgba(180,150,50,.5);
}

In order to force the ::before and ::after to be on top of the h1, we need to give them a position of absolute with top and left positions of 0, and then wrap the whole thing in a relatively positioned div.

In order to make sure the ::before and ::after stick to the heading when the window is resized, both the h1 and its wrapper div must be displayed as block level elements:

div {
 position: relative;
 top:10px;
 left:5px;
 background-color: rgba(200,150,150,0.2);
 border-radius: 10px;
 max-width:1190px;
}

The nice thing about this technique is that it degrades gracefully. If your browser doesn’t support pseudo elements, you’ll just see the main font, which is legible by itself.

 

Layer fonts in the wild

Now that we have looked at how to implement them in the browser, here is a selection of some of the best layered fonts.

Homestead ($50 commercial use, donation for personal use)

Homestead_02

 

Canter (free)

canter02

 

Core circus (from $5 approx.)

001

 

Summit (donation)

002

 

Teip ($117 approx.)

teip

 

Frontage (from $5 approx.)

003

 

Player ($49 approx.)

004

 

Scratch (free)

scratch

 

Industry Inc ($69)

005

 

American Chromatic (from $24.95)

006

 

Detroit (from $24 approx.)

detroit

 

Identification ($59 approx.)

007

 

Naga (from $24 approx.)

naga

 

Trend (from $5 approx.)

008

 

Festivo Letters (from $17 approx.)

009

 

Lettrage (Private)

010
0 shares
  • John

    In 2012 webdesignerdepot published a great article about ‘How to make your own icon webfont.’ This inspired me to think about layered fonts. Soon I started a mini project to create the American flag with a layered font. Here is the project report.

  • Steve Mark

    Thank you for sharing such an informative knowledge. Layer fonts looking very stylish.

  • http://www.tim-holmes.com/ TimHolmesDesign

    I think from a visual perspective this looks great and could be a real nice touch when developing a brands online presence, but what about from a structural and content stand point.

    I would imagine having lots of duplicate content as per option 1, will effectively result in over optimising for a specific term. This could potentially results on some SEO / Panda style penalties… I am not sure however, how the Pseudo css layers would affect it…

    Thoughts?

    • Demongo

      I would have thought the search engines would start (or may be already) treating those “content: attr(text)” things the same way as normal text. Otherwise they’ll start missing stuff which they hate. As a result I’ll reckon they’ll have to plug their keyword spamming tools into that content as well otherwise everyone will start using it to get round them.

      About the article, I notice the Core Circus font is designed for up to 5 layers. How would the author suggest using that one? Using ::before & ::after seem to limit the technique to 3 layers maximum.

      It’s a shame that this stuff still has to be such a mighty kludge even in HTML5 and CSS3.

    • Neil Wick

      Option 1 is perhaps the most obvious solution but was rejected for the reasons you stated. I don’t believe that the CSS pseudo tags should affect SEO because they don’t actually affect the content. The only thing likely to be a problem with search engines is when the content in the HTML doesn’t match up with what the reader sees.

  • Vaughan Curd

    These effects look great, however while the use of pseudo elements helps keep the html cleaner, they do pose a usability problem for screen reader users. A number of screen readers read the content of pseudo elements, so users of screen readers could potentially be hearing the heading three times.

    • http://www.mathewporter.co.uk/ Mathew Porter

      Also from an seo prospective, having the same heading tag such as repeated multiple times would also be bad practice.

      Maybe using css content: “”; might work better targetting the h1 and :before / :after …. If possible, not got my thinking head on or I would have had a tinker.

    • http://www.mathewporter.co.uk/ Mathew Porter

      Also from an seo prospective, having the same heading tag such as repeated multiple times would also be bad practice.

      Maybe using css content: “”; might work better targetting the h1 and :before / :after …. If possible, not got my thinking head on or I would have had a tinker.

  • Steve Mark

    Thank you so much for giving us such kind of handy content which will be most useful to me as well as others.