nathanford / type.js

Type.js – Typographic tools for better web type.
http://typejs.org
1.13k stars 69 forks source link

Type.js

Type.js adds new type properties to your CSS, giving you the control you need for type on the web. You can write these properties in your CSS and they will work like any other property.

View index.html to see these new properties in action.

Properties

Kerning Pairs

Adjust the space between specific glyphs with a clear syntax. Just type in the two glyphs you want to kern, then the amount space you want.

Properties

kerning-pairs accepts a comma separated list of two glyphs, then the distance you want between them. Accepts positive or negative distances.

kerning-pairs: az 0.02em; 

Values: {Any glyph}{Any glyph} {Any distance}{Any CSS unit}

Example CSS

h1 {
  font-size: 3em;
  line-height: 1.2;
  kerning-pairs: az 0.02em,
                 zy 0.01em,
                 th 0.01em,
                 ov -0.02em; 
}

Rag Adjust

Set rules for where you want your lines to break in a paragraph.

Properties

rag-adjust accepts four values that describe where your lines should break.

rag-adjust: small-words;

Values:

Example CSS

p, li, h3, dd {
  max-width: 35em;
  rag-adjust: small-words;
}

Widow Adjust

Set rules for how you want to adjust styles to eliminate widows – or any grouping of less than 14 characters on the last line of a paragraph – in your text.

Properties

widow-adjust accepts the style property you want to use to fix your paragraph.

widow-adjust: padding-right;

Values:

Example CSS

p, li, h3, dd {
  max-width: 35em;
  widow-adjust: padding-right;
}

Min/max font-size

Set a minimum and maximum font-size for text when using a viewport unit for font-size.

Properties

min-font-size and max-font-size accepts any font-size value and CSS unit. Does not accept viewport units.

min-font-size: 20px;

Values: {Any value}{Any css unit}

Example CSS

h1 {
  font-size: 3em;
  font-size: 4vw;
  max-font-size: 50px;
  min-font-size: 30px;
}

Issues

Type.js only works within style tags on a page. For now. You can try using your external stylesheets by changing an option in the type.js file. Change:

stylefill.options({

  externalCSS : false

});

To:

stylefill.options({

  externalCSS : true

});

Note: This will cause the browser to download your external CSS files twice. Once, as per usual, and again to read the type.js property values.