The Publishing Project

Creating Print CSS stylesheets

Rather than adopt a paged media model for printing HTML5/CSS pages let’s look at how to move our content to make for a better printing experience. The idea for this stylesheet came from Evernote’s simplified article capture mode.

This will be very dependent on the layout of your page but there are some common rules we can use everywhere, both css3 and HTML.

NOTE: I wrote all the material below using SASS SCSS syntax. This will allow me to use them with other SASS-based projects and stylesheets while remaining compatible with CSS.
Also note that this is by no means a complete print stylesheet. It definitely can be improved. If you have any ideas, please let me know via Twitter (@elrond25)or in a comment below

Defining the print stylesheet

At the most basic level, creating a print specific stylesheet is as simple as indicating its media type. This has been available since CSS 2.1 and it works like this:

@media print {
  /* style sheet for print goes here */

We can then use this shortened media query to style the printed output in the way we want. For example, if we want a different font size margins and line height for our printed output, we can do something like this:

body {
  font-size: 16px;
  line-height: 1.5;

@media print {
  body {
    margin: 1in;
    font-size: 16px;
    line-height: 2;

Now that we have a basic understanding of how to use the stylesheet let’s plan on what do we need to do to get a better print result for our pages.

What do we need to change?

Because we cannot predict the changes needed for all pages, I will just work on generic aspects of the printed styles.

Margins and base font sizes (body and headings)

Printed web pages usually go to the border of the paper. We can avoid that by adding margins to the body element. How much depends on how you want the page to look.

For this example we’ll set top, right and left margins to be an inch and the bottom margin to be an 1.5 inch. Most of the time I would leave my margins at 1 inch, but research into layout has made me add the extra space at the bottom.

We’ve also explicitly set the font size of the body element to be 16px (even thought this may or may not be necessary). Since I’m setting it to what the default is, I don’t think it causes too much of a problem.

To better size the headings I created a modular scale using Scott Brown’s website

One final note. I only styled h1, h2 and h3. I’ve never used headings beyond h3 and I don’t really see the need to have more than 3 levels of heading.

body {
  margin: 1in 1in 1.5in;
  line-height: 1.5;

h1 {
  font-size: 2em;

h2 {
  font-size: 1.75em;

h3 {
  font-size: 1.5em;

Removing background images and text color

Background images can be a royal pain. They use a lot of ink / toner and they may impact the way the rest of the content displays when printed.

Text color may also impact the way content appears when printed, particularly in black and white printers.

Our simple solution is to remove background and set the text color to black

body {
  background-image: none;
  color: #000;

Removing multimedia objects

Beyond images we don’t really need any more multimedia, audio, video and objects elements; printed pages can play them and they will use ink/toner unnecessarily, so we’ll hide them for our printed style sheet.

If you want your readers to see the poster images for video, the first frame of your object or the audio player ignore this rule

video,audio, object {
  display: none

Creating columns

Rather than have one long page of text we can create columns. The mixin below creates columns based on number of columns, gutter, text balance between columns and text span between the columns.

After the mixin we define classes for 2 and 3 column layouts spanning 100% of the available width of the document. We can use them as a model for more columns with different information.

We could code each column setup manually but why reinvent the wheel?

@mixin column-attribs ($cols, $gap, $fill: balance, $span: none){
  // How many columns
  -moz-column-count: $cols;
  -webkit-column-count: $cols;
  column-count: $cols;

  // Space between columns
  -moz-column-gap: $gap;
  -webkit-column-gap: $gap;
  column-gap: $gap;

  // How do we fill  our columns, 
  // default is to balance
  -moz-column-fill: $fill;
  -webkit-column-fill: $fill;
  column-fill: $fill;

  // Column span, default is not to span columns
  -moz-column-span: $span;
  -webkit-column-span: $span;
  column-span: $span;

.columns2 {
  width: 100%;
  @include column-attribs (2, 20px);

.columns3 {
  width: 100%;
  @include column-attribs (3, 10px);

Putting it all together

Putting all the elements together the style sheet may look something like this.

@media print {
  body {
    margin: 1in 1in 1.5in;
    font-size: 16px;
    line-height: 1.5;
    background-image: none;
    color: #000;

  h1 {
    font-size: 2em;

  h2 {
    font-size: 1.75em;

  h3 {
    font-size: 1.5em;

  video, audio, object {
    display: none

  .columns2 {
    width: 100%;
    @include column-attribs (2, 20px);

  .columns3 {
    width: 100%;
    @include column-attribs (3, 10px);

Where do the print stylesheets fall short?

First of all, this is a simplified view of the web page to make printing easier. It is not a dedicated printing solution like CSS Paged Media using generated content and it will not work with Antenna House or PrinceXML.

If you want to see what that type of stylesheet looks like see my CSS Paged Media update

Second, these is a generic exercise. A lot of the more detailed conversions will depend on your specific page structure and how much fidelity you want to the screen version of the site.

CSS shapes: an update and an expansion

CSS Shapes (spec) allow you a finer grained control of how you flow the text around shapes and images.

Only Chrome and Opera (both using the Blink rendering engine) and the beta version of Safari (iOS 8 and OS X 10.10) support css shapes.

To illustrate the idea of shapes, look at the following image, taken from Sara Souedan’s A List Apart article:

Examples of CSS Shapes

Look at the way the list of ingredients on the second and third recipes. That effect is achieved with shapes.

The HTML is fairly simple, we create the shape by placing the element we want to float (the paragraph) and the element we want to float around (the image)

In the CSS portion we define three elements:

  • The container for the document (#circle-shape-example)
  • paragraph text (#circle-shape-example p)
  • image (#circle-shape-example .curve).

The result can be see in the Codepen below:

See the Pen Wrapping Text Around A Circular Shape by Carlos Araya (@caraya) on CodePen.

The specification has one shape type:

  • shape-inside()
  • shape-outside()

Only shape outside is currently supported. The original specification included both shape-inside and shape-outside but the complexity of shape-inside made the CSS working group defer shape-inside until the level 2 specification is released.

There are 5 shape functions defined in the specification for outside shapes:

  • circle()
    • shape-outside: circle();

    The default version will just create a circle centererd around the object being shaped around.

    • shape-outside: circle(250px);
    • shape-outside: circle(100%);
    • shape-outside: circle(closest-side);

    • shape-outside: circle(farthest-side);

The value inside the circle function indicates the radius of the circle being used. This will in turn affect the way the shape wraps around the content, particularly if it’s an image.

You can use a percentage value instead of an absolute measurement. In the case of a circle the value is computed from the used width and height of the reference box as sqrt(width2+height2)/sqrt(2) (from the specification)

Closest and farthest side refer to two predefined values of (shape radius).

Closest side will make the content fit into the box assigned to it. The content will not clip but will be shrunk to keep within the bounding box.

Farthest side uses the length from the center of the shape to the farthest side of the reference box. For circles, this is the farthest side in any dimension.

  • shape-outside: circle(250px at center);
  • shape-outside: circle(farthest-side at center);
  • shape-outside: circle(closest-side at center);

Position values are defined in the CSS background level 3 specification. You can specify this position by using the at {position} syntax.

  • ellipse()
    • shape-outside: ellipse();
    • shape-outside: ellipse(25%);
    • shape-outside: ellipse(25% 10%)
    • shape-outside: ellipse(closest-side);
    • shape-outside: ellipse(closest-side closest-side);

Ellipse is very similar to circle in terms of syntax but it work with ellipses rather than circles and it sues 2 values to define the shape. An example can be seen below:

See the Pen CSS Shapes Demo #6 by Carlos Araya (@caraya) on CodePen.

If the floated element is a circle then an ellipse works the same way as a circle shape.

  • inset()
    • shape-outside: inset(0px round 50px) border-box;
    • shape-outside: inset(10px 10px round 50px) border-box;
    • shape-outside: inset(10px 10px 10px round 50px);
    • shape-outside: inset(10px 10px 10px 10px round 50px);

Inset allows you to create rectangular areas to float content around. This works with either for images that are a rectangles or where we want to overlap text over a rectangular shape.

Inset shapes also allow us to create rounded corners for the text to float around as show in examples 2, 3 and 4 above and in the pen below:

See the Pen CSS Shape inset demo by Carlos Araya (@caraya) on CodePen.

Pen forked from

  • polygon()

Polygon values for shape-outside allow designers to create layouts wraping text around irregularly shaped closed polygons.

The minimum number of vertices for a polygon shape is three (a triangle).

  • shape-outside: polygon(0 0, 0 300px, 300px 600px);

Using percentages makes our polygon responsive.

  • shape-outside: polygon(0 0, 0 100%, 100% 100%);

Another value imported from SVG is fill-rule which handles how to handle self-intersecting paths or enclosed shapes. Joni Trythall wrote a tutorial about Understanding the SVG fill-rule Property.

Posible values are non-zero and even-odd. Thedefault value if you choose not to fill it, is non-zero

The pen below shows one possible use for polygons where we create a trapezoid-shaped image and then float the text ouside the image which gives the full page the appearance of a magazine layout.

See the Pen CSS Shapes Demo #11 by Carlos Araya (@caraya) on CodePen.

  • url(), images and thresholds
    • shape-outside: url(path/to/image-with-shape.png);
    • shape-image-threshold: 0.5;

To me, one of the coolest features of the shape specification is the ability to use images as the object we wrap text around.

The URL to the image specified an arbitrary image that we can wrap our content around.

The image-threshold attribute indicates the minimal opacity of the pixels making up the shape that content will flow around.

See the Pen CSS Shapes Demo #9 by Carlos Araya (@caraya) on CodePen.

See the SVG section for a way to use masks in addition to the images to create more nuanced shapes to wrap the text around.

Positioning the shape

There are addition values for the shape-outside element: margin-box, border-box, padding-box and content-box can be used to place the shape within the different margins associated with an object.

According to HTML 5 Rocks’ Getting started with CSS Shapes you can also use the bounding boxes on their own or with other CSS rules to create shapes.

The author gives two examples:

The first one creates a circle shape with border-radius and shape-outside: border-box;

The second example creates a pullquote-type effect using shape-outside: content-box;

They may not be as flashy as having text wrap around a 20 vertice polygon but the effects are just as useful.

Razvan Caliman explain the different boxes, their location and how they interact with the different types of shapes currently implemented.

See the Pen CSS Shapes Demo #10 by Carlos Araya (@caraya) on CodePen.

Simulating shape-inside

When first released the shapes specification included both shape-inside and shape-outside. Shape inside has been deferred to the next level of the specification.

Even shape-inside is not part of the current specification, it can be simulated using a couple non semantic elements and two elements styled with shape-outside placed in opposite sides of the window.

To see an example of this type of use of shapes, look at Adobe’s Alice in Wonderland demo.

Be aware that performance is definitely below ideal. The way the example implements the text scrolling triggers a lot of relayout and paint events. This will reduce performance. This performance issue will be solved when native implementations of shape-inside appear in browsers. Until then we need to be aware of the performance hit the current technique implies.

CSS masks and shapes working together

The CSS Masking specification provides two additional rules we can use in working with our shapes: clip-path and mask-image.

Fortunately for us the syntax for clip-path is identical to the syntax for shape-outside so you can do the following to make sure that only the shape you select appears on screen:

img {
  -webkit-shape-outside: circle(50%);
  shape-outside: circle(50%);
  -webkit-clip-path: circle(50%);
  clip-path: circle(50%);

I code deffensively. The unprefixed versions of the code may not be necessary but I add it anyways to make sure that when/if browser vendors decide to drop prefixes my code will not break down right away.

Using masks in SVG and CSS talks about general use of masks and clip paths both generated directly from CSS and masks generated with SVG.

Sara Soueidan further explains how to use clipping in CSS and what effects you can achieve with the technique.

Rebecca Hauck shows how to use Adobe Photoshop to create more refined masking image.


Shape implementations only work with floated content. Updates to the specifications will work with non-floated content but we’re not there yet, it is expected for the second edition of the shape specification.

You must specify dimensions for the object you’re floating around. The browser will use those dimensions to establish a coordinate set for the element. This may or may not be accurate but I’ve always been a fan of coding defensively so I add explicit dimensions in the css class(es) assigned to regions, if needed, change them with Javascript later.

Browser support

Data obtained from accessed 09/15/2014

  • Firefox: Not suported
  • IE: Under Consideration (per
  • Safari / Safari Mobile: 8 (using -webkit prefix)
  • Opera: Since version 24
  • Opera Mini: Not supported
  • Chrome / Chrome for Android: Since version 37 (must enable “experimental Web Platform features” flag in chrome://flags)
  • Android Browser: Not supported

Working examples and sources of inspiration (both print and online)

Tools to create CSS shapes

Looking at the future of shapes

CSS Shapes Level 2 editor draft from the W3C CSS working group is the next iterations of the shapes specifications.

Unless it is deferred again, the next specification should contain both shape-outside and shape-inside which will make even better shape related models possible. Until then let’s play with what we have.

CSS regions, part 2

The landscape for CSS regions has changed drastically since the last time I visited the technology. Since the last post about the technology (published in October, 2013) the following events took place:

  • Google, citing concerns about performance, withdrew region support from the Blink rendering engine (Cnet posted an article about this)
  • Mozilla split some aspects of the CSS regions specification into another specification which they believe satisfies the use cases put forward by CSS Regions in a way that our team can support in a much more secure, reliable, and performant manner.
  • L. Dave Baron opposed regions as proposed in the specification in the context of performance and its use as a language primitive for the Extensible Web Movement as expressed in their manifesto
  • HÃ¥kon Wum Lie, Opera’s CTO, is also opposed to Regions as proposed (documented in this a list apart article and in this followup)
  • Microsoft has shapes under consideration

For those interested the thread that first got my attention starts with this message and it moves through this and other threads

My concern is that instead of working on improving the current spec both companies decided to go their own way, not supporting the spec as written and proposing their own versions to the W3C. Sadly, until they settle their argument, the lack of a unified specification leaves developers, who are not as opposed to the idea, having to polyfill the feature in half the modern browsers, whether evergreen or not.

Now into specifics.


Regions are a way to fragment the content of a web page into distinct containers to create magazine-like layouts without having to worry about content flow or where the content will be positioned. This feature is comparable to Fixed Layout ebooks and print magazine layouts generated with Adobe InDesign.

The biggest advantage of the specification is that we no longer have to worry about where the content will flow when it fills the current region. We will discuss how to create regions and flows this later in the article.

Creating regions consist of four steps.

  1. Create the container where the content will flow into
  2. Specify the content section that the content will flow from
  3. Set up the CSS for the containers created in step 1 and 2
  4. Style the resulting region if you so choose

An example from a project under development:

The HTML content below covers both creating the div that will hold the content and the div that has the content we’ll place.

[code lang=html]
<div class='content-overview-region' id='overview01'></div>

<div class='burningman-overview'>

<p><strong>Burning Man</strong> is a week-long annual event that began in San Francisco's Baker Beach and migrated to the Black Rock Desert in northern Nevada, in the United States. The event begins on the last Monday in August, and ends on the first Monday in September, which coincides with the American Labor Day holiday. It takes its name from the ritual burning of a large wooden effigy, which is set alight on Saturday evening. The event is described as an experiment in community, art, radical self-expression, and radical self-reliance.</p>
</div><!– Closes burningman-overview–>

The CSS part of the project has the source of the content (using the burningman-overview class) and the region we’ll create to place the content (using the content-overview-region class). We also use content-overview-region to style the content inside the region.

I also like to assign borders with different colors to each region I’m working with to create a visual layout of the content in the page as I develop the layout.

[code lang=css]
* Defines the source of the content that will flow into the
* overview region of the document
.burningman-overview {
flow-into: content-overview-region;
-webkit-flow-into: content-overview-region;
-ms-flow-into: content-overview-region;

.content-overview-region {
flow-from: content-overview-region;
-webkit-flow-from: content-overview-region;
-ms-flow-from: content-overview-region;

.content-overview-region {
position: relative;
width: 90%;
margin: 0 auto;
padding: 2em;
border: 1px solid purple;

As your content grows larger you have two options: create more regions to flow the content into (which you can use to create columns or other shapes), make the single regions you created automatically grow to fit the content using height: auto (as in the example above) or use the CSS Object Model (CSSOM) to programmatically add containers for your content to fill into. It will all depend on your design and layout goals for your current project.

A CSS Region experiment is available in this codepen. Currently it only works in Safari and Internet Explorer as it does not use the regions polyfill.

You can find an example of programmatically adding regions to existing content in the CSS Regions Polyfill Github repository and in this codepen

Alternatives: using @support

Another alternative is to use the @support css at-rule to give one set of styles, including regions, for those browsers that support them and another set of styles for those browsers that don’t.

Lea Verou wrote a tutorial on how to use the @support feature in your CSS code. Mozilla Developers Network has useful information and examples, particularly the compatibility table.

If we look at the MDN compatibility table we see the biggest weakness of the @support at-rule. It is not supported accross the board… in the case of regions, though, the browsers that we need to target as not supporting regions (Chrome and Firefox) support the @support at-rule. I would construct the rules like this:

@support not (flow-into: content-overview-region;) {
    Write rules here to accommodate browsers not supporting
    regions, maybe using media queries to address positioning
    and size

Alternative: using Modernizr or other conditional loaders

Modernizr feature detection is another tool we an use to conditionally load content based on support (or lack thereof) for a given feature.

Modernizr test for css regions under the non-core detects (you have to manually add the test as it is not added to the default build.)

To make sure that the polyfill doesn’t conflict with native implementations of the specification I use Modernizr.load to test for browser support in regions and then only load the JavaScript polyfill for browsers that do not support the feature. I placed the following JavaScript code on the head of my page.

<html class='no-js'>
  <!-- portions of the document head section omitted -->
  <script src="scripts/modernizr-region.js"></script>
      test: Modernizr.region,
      nope: 'scripts/cssregions.js'

See the Pen mHlxL by Carlos Araya (@caraya) on CodePen.

To cut the bandwidth requirements for the demo, I created a custom Modernizr build with only regions and load support. I then used Modernizr.load to test for support of regions (the test part) and only load the polyfill when the test fails (the nope section). If you’re already using Modernize you can just add the CSS regions feature test (in the non core section) and download a new build for your project.

Alternative: CSS Regions Polyfill

All is not lost if you want to move this into more serious testing or even some light production work. There is a CSS Region Polyfill available that makes regions work in all browsers.

The polyfill doesn’t change the CSS code described above. We coded defensively and added the three possible options we can use for CSS regions:

  • Unprefixed version used by the polyfill code
  • -webkit used by Safari
  • -ms used by IE

Everything is not rosy. The polyfill lacks support for some features and has some serious limitations. From the polyfill Readme file:

Some features are not supported:


Basic @region support (styling fragments based on current region)



Known issues with regions polyfill

From the polyfill Readme file:

Some caveats apply:

  • Because the code is asynchronous, the only way to be sure you can act on a NamedFlow is to listen to its regionfragmentchange event. Unlike the browser which computes the layout of the page synchronously, the JavaScript implementation is asynchronous by nature and cannot perform synchronous operations
  • Another consequence of the code executing asynchronously is that screen flashing is possible in some cases, especially during the page load if correct display:none styling is not applied to hide the source content wrapper before the content itself is flown into a region. It’s also advised to put overflow: hidden on regions when possible even if it shouldn’t be strictly required
  • The regionoversetchange event is not guaranteed to fire only when the overset actually changes. Guaranteeing this would requires storing a lot of information and compare them at runtime, and I decided it would not be worth the time
  • Dynamic elements cannot be put into a flow without harming their functionnality (this incudes forms, and a lot of interactive objects). This implementation is only suitable for static or mostly static content
  • In the same vein, hover and active style do not apply to content inside a region. This limitation could possibly be lifted in some cases but I await feedback this is actually useful before proceeding
  • Because elements are actually cloned in the regions, you may receive those clones as a result of getElementsByTagName or querySelectorAll queries, as well as methods such a elementsFromPoint. The actual ID and class names of the objects are not preserved in the fragments to reduce the risk, but this is by no mean a complete guarantee. A solution is to check the data-css-regions-fragment-of attribute and recover the original source by using the data-css-regions-fragment-source attribute
  • Because computing nested css-counters manually would be very expensive in cpu horse power, I decided to leave this case as is. Most non-nested css-counters should work fine, however

The biggest unknown for the polyfill is performance in mobile devices. Neither Adobe or the polyfill author has made statements about performance of the polyfill in mobile devices. This may not be an issue for simple layouts but will definitely become a problem for more complex layouts and designs.

The answer is the same as with many other development projects. Test, iterate, get feedback and iterate some more.

Subsetting Fonts

In creating ebooks we need to pay attention to files size… Modern fonts have many more characters than we use in normal books. Subsetting the fonts will allow us to decrease the size of the font by decreasing the number of glyphs and the the number of languages supported by the font in question.

Although for me the primary reason for subseting my fonts is reducing the overall book size, there are other reasons for doing so. Some foundry’s require subsetting and font obfuscation as part of their license for eBook embedding. This makes the font less appealing for would-be stealers as it doesn’t necessarily have all the characters you need for your project and it’s not in clear text so you can’t really use it.

We will not, for now, deal with Adobe’s WebKit fonts as the service goals are different. It doesn’t provide the granularity we need to reduce the size of the fonts to a more reasonable size. It does, however, provide basic subsetting for each web font kit you create with the service. Desktop fonts must go through the process below to be properly subset.

Before we start

Before doing any work with fonts you need to make sure that the font allows you to use it on eBooks and digital publishing. I found this out the hard way when my favorite font was not available for use in eBooks under the license I had purchased it and the cost of the license for eBook and web publishing proved prohibitive.

For the purpose of this and other eBook research projects I will use open source fonts or fonts released under the SIL open font license which is permissive and specifically allow for embedding and subsetting.

Choosing the tools

I found three tools that did what I wanted to do; make font files smaller by subsetting them to only the characters and unicode pages associated I need for my book.

Font Squirrel

Web Squirrel’s webfont generator has been the go-to tool for web font work since they were reintorduced along with the rest of the HTML5 specification. It does everything you need to get the fonts displayed in your website: Generates the formats needed for web deployment (TTF, EOT, WOFF and SVG), provides the CSS needed to include the font in your page and, most important for the purpose of this article, gives you expert settings where you can subset the font as needed.

We’ll take a look at the different features of the generator, paying particular attention to subsetting.

Font Squirrel WebFont Generator Upload and Basic selections
Font Squirrel WebFont Generator Upload and Basic selections

Before we can start working with the font subsetting tools, we need to tell Font Squirrel which font we want to work with. Only way to do this is to upload the font.

Once the font is uploaded you need to indicate wich level customization we want. For subsetting we want the expert level. Basic and optimal hide the settings we need to subset the font.

If you’re working on the web you will want to subset TrueType, WOFF and EOT compressed. SVG may be necessary if you’re supporting older iOS devices only. Newer versions of iOS support TrueType and or WOFF.

I leave the following options under subsettings as they are:

  • Truetype Hinting
  • Rendering
  • Fix Missing Glyps
  • X-height Matching
  • Protection

I choose custom subsetting to get the setting shown below.

Font Squirrel Subsetting Options
Font Squirrel Subsetting Options

You can choose to subset based on character types, languages, unicode tables, single characters or unicode ranges either individually or combined.

I normally select the following Unicode Tables

  • Basic Latin
  • Punctuation
  • Currency Symbols

If I’m only using a few characters to create a title, I may subset the font using the single characters option. You will be able to check what your subset will look like under Subset Preview

These characters will be available after subsetting
These characters will be available after subsetting

We now move into the final settings before saving our font subset.

Unless you know what you’re doing, you can leave these settings as they are:

  • OpenType Features
  • OpenType Flattening
  • CSS
  • Advanced Options
  • Shortcuts
Additional option and permission
Additional option and permission

You must check to acknowledge that the fonts you’re uploading are legal to embed. Some foundries will not allow you to use their fonts for embedding directly, prefering instead that you use their online font service (their version of TypeKit).

If you choose to lie and check anyways, Font Squirrel may still disallow you from using the font if the creator has so requested and regardless of you having a license for the desktop font.

As with many things in web development land; test the resulting fonts. Make sure that they have all the glyphs you will need and redo the subset if it doesn’t or if the subset font is larger than your original.

FontFont Subsetter

FontFont Subsetter is an online service that support subsetting fonts. I tried uploading Roboto, a TTF font from Google, and I received the result .

FontFont Subsetter result when uploading Roboto font
FontFont Subsetter result when uploading Roboto font

According to the FAQ, only certain flavors of TTF fonts are supported by the service. Specifically it states:

Make sure that you upload a FontFont with the file extension .ttf, .eot or .woff. Subsetter supports TrueType-flavoured Offc FontFonts and Web FontFonts in WOFF or EOT format.

Since I can’t be sure if the subsetter will work with the fonts I choose I have to look for something else.

FontPress 3

Fontpress has recently been open sourced and it’s available as a download in Github.

It has a drag and drop interface but after you add the fonts to subset it’s more complicated than it needs to be. The resulting font subsets were larger than the original files. I’m not 100% sure if it was the way I did it or if the software is not giving me the results I want.

TODO: Research the tool. It may do what I want but right now the subset is larger than the original font.

CSS Support and namespaces

There are two new @rules in CSS (well, they may not be new but they are new to me) that open an awesome set of possibilities for CSS development with or without a pre-processor.


CSS namespaces are the CSS implementation of XML namespaces; the technology that allows elements from different XML vocabularies to live in the same document .

In the case of CSS, namespaces allow us to style elements with the same name from different vocabularies differently. For example, let’s look at the a from both XHTML and SVG vocabularies

@namespace url(;
@namespace svg url(;

/* This matches all XHTML <a> elements, as XHTML is the default namespace */
a {}</a>

/* This matches all SVG <a> elements */
svg | a {}</a>

/* This matches both XHTML and SVG <a> elements */
*|a {}

In this example we define a default namespace @namespace url(; and a namespace for the SVG vocabulary @namespace svg url(;. This will allow us to style the elements based on whether it’s an HTML link or an SVG one.

Rather than have to build separate stylesheets or different selectors for each of our vocabularies we can now create one stylesheet and prefix our selectors based on the language they work with thus making them match only if both the namespace prefix and the selector match.

@supports (also known as feature queries)

Feature queries using the @supports at-rule make it possible to write feature detection in CSS. In principle, feature queries are similar to media queries (described in this CSS Tricks article) but with a different emphasis.

Where media queries concentrate on the device capabilities (as seen in the example below for a screen wider than 1024 pixels)

@media screen and (min-width: 1025){
/* content for devices matching the query goes here */

Feature queries work by testing for a CSS capability, similar to how we should be doing feature detection in Javascript, as show below:

@supports (display: flex) {
/* content for browsers that support the condition goes here */

Bear Travis, from Adobe, presents a more realistic example on his blog postabout feature queries, copied below:

@supports (background-blend-mode: multiply) {
body {
background-blend-mode: multiply;
background: linear-gradient(rgb(59, 89, 106), rgb(63, 154, 130)),

Furthermore we can do more complext detections using and, not and or operators. For example we can test for multiple display features by using something like this:

@supports (display: table-cell)
and (display: list-item){
/* code goes here for browsers that support
table-cell and list-item display */

One of my favorite uses of feature detection in CSS is to test for prefixed properties using the or operator. This makes the code less brittle because, as vendors drop prefixes for a property, the style will still match the unprefixed version of the rule and, at the same time, we provide backwards compatibility for those browsers that still need the prefixed properties.

This technique does not eliminate the need for Prefix Free or Autoprefixer but it allows designers to code deffensively without having to worry about which browser dropped each prefix when.

@supports (
(perspective: 10px)
or (-moz-perspective: 10px)
or (-webkit-perspective: 10px)
or (-ms-perspective: 10px)
or (-o-perspective: 10px)
) {
/* specific CSS applied when 3D transforms, eventually prefixed, are supported */

The final trick to add to the CSS feature detection arsenal is the not operator which negates the test being performed. For example, we can test for lack of support for text-align-last or its Mozilla prefixed counterpart.

@supports ( not ( (text-align-last:justify) or (-moz-text-align-last: justify)) ) {
/* selectors and rules for browsers that don't 
support text-align-last: feature */

Note the parentheses. When using compound expressions they are required, otherwise the css parser will not know how to process the query.

@support allows progressive enhancement on the CSS side of the design equation (or it will once all browsers fully support the specification). Using the CSS cascade we might be able to do something like this:

/* First we do a plain color body background for older browsers */
body {
background-color: #ff8;

/* If the browser supports rgb colors we use that */
@supports (background-color: rgb(255, 255, 255)){
background-color: rgb(255, 255, 128);

/* test for hsla color space, if supported, use it*/
@supports (background-color: hsla(50, 33%, 25%, 0.75){
background-color: hsla(50, 33%, 25%, 0.75);

/* finally we try a blended background and use it if supported. */
@supports (background-blend-mode: multiply) {
body {
  background-blend-mode: multiply;
  background: linear-gradient(rgb(59, 89, 106), rgb(63, 154, 130)),

I created a CodePen with the code above to test in different browsers. So far it does what I expected. It tested the rules in order and the last one the browser supports (and assuming that it supports the @supports at-rule) will be the one displayed.

Only the last supported rule will be used so we can set up for as many capabilities of the browser as we need to. However, the results are inconsistent in the different Macintosh browsers I’ve tested this with. As you can see below, the support is not uniform across browsers or complete in the browsers that do support the specification. Still it’s a great starting point.

Specification status and browser support.

CSS Conditional Rules Module Level 3 (the recommendation that contains feature queries) is at the Candidate Recommendation stage. I’m concerned that the @supoort rule is at risk but the blink implementation is not included on the test case suite.

As far as support the matrix looks like this:


  • Chrome: 28.0
  • Firefox (Gecko): 22
  • Internet Explorer: Not Supported
  • Opera: 12.1
  • Safari: Not Supported


  • Android: Not supported
  • Firefox Mobile (Gecko): 22
  • IE Mobile: Not supported
  • Opera Mobile: 12.1
  • Safari Mobile: Not supported