How to get started with layer fonts in CSS

Paddi Macdonnell.
June 20, 2014
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 id="second">
 <h1>Using Layer Fonts In CSS</h1>
<div id="third">
 <h1>Using Layer Fonts In CSS</h1>

/* CSS */
#first, #second, #third{
 display: block;
h1 {
 font:5em 'One';
#second h1 {
#third h1 {

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.)

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

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’;

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

h1::before {
 content: attr(text);
h1::after {
 content: attr(text);
 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;
 background-color: rgba(200,150,150,0.2);
 border-radius: 10px;

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.

Paddi MacDonnell

Paddi MacDonnell is a designer and entrepreneur from Northern Ireland, follow her on Twitter.

Read Next

30 Most Exciting New Tools for Designers, 2023

As we near the end of 2023, we wanted to take a look back over all the tools we collected over the past year, to pick…

3 Essential Design Trends, December 2023

While we love the holidays, too much of a seasonal theme can get overwhelming. Thankfully, these design trends strike a…

10 Easy Ways to Make Money as a Web Designer

When you’re a web designer, the logical way to make money is designing websites; you can apply for a job at an agency,…

The 10 Most Hated Fonts of All Time

Remember when Comic Sans wasn’t the butt of the jokes? Long for the days when we actually enjoyed using the Impact…

15 Best New Fonts, November 2023

2023 is almost over, and the new fonts are still coming thick and fast. This month, we’ve found some awesome variable…

Old School Web Techniques Best Forgotten

When the web first entered the public consciousness back in the 90s, it was primarily text-based with minimal design…

20 Best New Websites, November 2023

As the nights draw in for the Northern hemisphere, what better way to brighten your day than by soaking up some design…

30 Amazing Chrome Extensions for Designers and Developers

Searching for a tool to make cross-platform design a breeze? Desperate for an extension that helps you figure out the…

Exciting New Tools for Designers, November 2023

We’ve got a mix of handy image helpers, useful design assets, and clever productivity tools, amongst other treats. Some…

The Dangers of Doomscrolling for Designers and How to Break Free

As a creative professional, navigating the digital realm is second nature to you. It’s normal to follow an endless…

From Image Adjustments to AI: Photoshop Through the Years

Remember when Merriam-Webster added Photoshop to the dictionary back in 2008? Want to learn how AI is changing design…

3 Essential Design Trends, November 2023

In the season of giving thanks, we often think of comfort and tradition. These are common themes with each of our three…