Oh wow! Lettering.JS now has it’s own website with a little mini-gallery.
Check it out to see how other people are using it.
Paravel has just wrapped up an exciting secret project with three of the web’s most talented designers: Jason Santa Maria, Frank Chimero, and Naz Hamid. These designs are epic, like 18,123px epic. Working with these guys was a complete joy. There were a few fun development challenges and – as you might expect from these gentlemen – a lot of fancy typography work in the delivered PSDs.
Before Trent and I marked up the designs, we noticed that in many instances we would need to style individual letters. We decided we’d need a system to keep our markup maintainable. Something agile enough that a text change wouldn’t ruin us. Our solution was to call upon the power of Javascript to insert some easy to remember span tags.
Individual Letter Control with Lettering.js
We developed a really simple, lightweight, easy to use jQuery plugin, we’re calling it “Lettering Dot JS”, and we’re releasing it today for free over on Github. Let me demo it for you: </stevejobs>
We’ll start with some really basic markup:
<h1 class="fancy_title">Some Title</h1>After including jQuery, download and include the minified version of Lettering.js, then a script block:
<script src="path/to/jquery-1.4.2.min.js"></script>
<script src="path/to/jquery.lettering.min.js"></script>
<script>
$(document).ready(function() {
$(".fancy_title").lettering();
});
</script>The resulting code will churn your .fancy_title and output the following:
<h1 class="fancy_title">
<span class="char1">S</span>
<span class="char2">o</span>
<span class="char3">m</span>
<span class="char4">e</span>
<span class="char5"></span>
<span class="char6">T</span>
<span class="char7">i</span>
<span class="char8">t</span>
<span class="char9">l</span>
<span class="char10">e</span>
</h1>
Magical. Now the text is easy to manipulate in your CSS using an ordinal .char# pattern. This plugin assumes basic counting skills, but it’s a pretty fast and easy way to get control over every letter.
As you can imagine, it would be a pain in the ass to have all those spans littering your markup and a nightmare to maintain. If the client came by the next day and said that the SEO Expert demands that you have to change the title to “Cool Title”, it’d just be a matter of changing the original clean markup to:
<h1 class="fancy_title">Cool Title</h1>It also plays nicely with CMSs like WordPress or Expression Engine and art direction plugins.
Wrap Words with Lettering.js
Once we developed this e-solution and played with it, we found it useful enough to broaden the scope so that we could break apart and wrap words in a sentence in a span tag.
Here’s an example of the .lettering(‘words’) method:
<p class="word_split">Don't break my heart.</p>
<script>
$(document).ready(function() {
$(".word_split").lettering('words');
});
</script>Which will generate:
<p class="word_split">
<span class="word1">Don't</span>
<span class="word2">break</span>
<span class="word3">my</span>
<span class="word4">heart.</span>
</p>
You can then style each word using the .word# class.
Wrap Lines with Lettering.js
Once word wrapping was complete, noticed the need for yet another method, one that would break lines up mid-sentence. We struggled for a semantic way to do this, but then remembered <br> tag which a semantic way to say “break this line”. Similar to the above examples where lines of text are broken up by either non-breaking spaces or individual letters, the lettering('lines') method will create breakpoints at <br> tags:
<p class="line_split">Are you<br/> ready to<br/> RUMmMmMMBBLE!</p>
<script>
$(document).ready(function() {
$(".line_split").lettering('lines');
});
</script>Resulting code:
<p class="line_split">
<span class="line1">Are you</span>
<span class="line2">ready to</span>
<span class="line3">RUMmMmMMBBLE!</span>
</p>
Kern Well
If you’re going through the trouble to load a fancy font and that word or phrase is the largest on the site, then it’s important for it to be kerned well. With Lettering.js, kerning is a breeze. You can simply use $("#id-of-what-i-want-to-kern").lettering(); and then on each .char#, you can set relative position or left/right margin. Works like a charm.
Best Practices
We’ve found this to be a pretty quick and elegant solution to create typographical CSS3 posters. It’s also a great solution for really custom type headings, while keeping the text selectable.
Be smart and use sparingly. You’ll probably break your browser if you try to tried to do wrap every letter on your page in a span tag, so don’t do that. Look to use this in your Headings, Blockquotes, Asides, etc.
Non-Javascript Fallback
As with any kind of Javascript, have a fall back plan in case the user doesn’t have javascript enabled. The bottom line is up to you, my bottom line would be “legible and on the screen”. Also, use lettering.min.js: Download the minified version of Lettering.js here.
Performance Anti-Pattern
Web performance patterns advise that you put Javascripts at the bottom of your page before your </body> tag. There is an unfortunate side effect where you may experience a FOUT (Flash of Unstyled Text) when you’re manipulating your text after the DOM has loaded. Unfortunately, we found the best solution to avoid/minimize the FOUT caused by this plugin is to put your scripts (jQuery, Lettering.js) in the document <head>. On the one hand, your page will load slower. On the other hand, a flash/restyling makes your site feel slow. Users might ultimately feel the site is faster if they don’t see the FOUT.
Download, Fork, Commit, Please.
We really want Lettering.js to be a quality helper for web typography. If you have any feedback or suggestions, please leave those over on the Github. We’re excited about typography on the web and want to help make it print quality.
Thanks to Paul Irish for code review!
Sounds awesome! Excited to see Operation Condor launch in it’s full glory and seeing this technology in action.
Nice! This is a pretty ingenious way to easily toggle on and off ticky typographical issues.
It would be interesting too, to see the ability to identify which character you were dealing with via the span’s class, ie class=”e” or class=”e-1″. This could come in very hand when you’re dealing with a recurring kerning issue for certain glyphs. You could make sure that all “e”‘s were kerned an extra 2px tighter, for example.
Thanks a ton!
That’s a great idea. It’s a little tricky because there are so many exceptions. If you did `class=”e”` that would be for both upper & lowercase E’s which would need to be kerned differently. So maybe the solution is something like `letter-upper-e` or something similar. There’s also a small issue with punctuation. `letter-!` wouldn’t validate. So that’d have to get changed to `letter-exclaim`.
I’ll keep this in my brain, but it might get made real soon. You’ve got my gears turning. Do you know any default fonts that have a terrible kern I can test with?
I think you’d actually be able to do this in javascript. It could slow things up if you have a lot of individual letters to check, so you’d need to use it REALLY sparingly, but you could do something like this:
$(function() { //add fancy lettering $(“.fancy_title”).lettering(); //cycle through your fancy letters $(‘.fancy_title span’).each(function(){ //check if the letter is E if($(this).html() == ‘E’){ //if it is, change the margin $(this).css(‘margin-right’,'-2px’); } }); });I hope you find that helpful! Maybe there’s a more efficient way to do this, but this is just what I came up with (and haven’t tested either)
@Sean Rice – nice e-solution there! (i combined your comments btw) That works great for detecting an ‘E’. You could also automate adding classes (to avoid inline styles) if there’s no punctuation, by just chaining methods like :
$(document).ready(function() { $(".fancy_title").lettering().children("span").each(function() { $(this).addClass('letter-'+$(this).text()); }); });might blow up your browser. but it’d work. you could probably have some regex in there too so that only letters and numbers are get the addClass(). something to think about!
I cannot stress enough how much Lettering.js saved our asses. Great work, Rupe!
I’m excited to see how people put this to work on their own projects. Hmm, maybe this warrants a Dribbble rebound contest :)
Wow, what an awesome plugin – brilliant job!
This sounds amazing! Can’t wait to start using it.
Makes you wish that CSS had pseudo-elements for characters, words, and lines, doesn’t it? :)
Nice work! This looks really useful when used well.
We actually had high hopes for pseudo-elements, but unfortunately :first-letter is about as far as it goes (and even that has some limitations we found :)
It works pretty well and there will be some great examples once Operation Condor flies onto your screen.
@Sean McBride I had the exact same thought initially… some way to target :letter-3 or something like that. I don’t know whether or not it’d be overkill in most cases, but in some it’s a game-changer.
Great idea and stellar work, men. I can definitely see myself using this in the future, and I’ll be sharing this with fellow designers / developers.
This looks pretty fantastic. I’ve got a couple projects I can use this on now. Great work!
Holy hell, Batman! Slick work, gentlemen — looking forward to designing reasons to use this :)
Thanks, Dan! Means a lot coming from you. You’re my idol. Can’t wait to see what you come up with :)
Awesome addition to the Web Art Director’s Toolkit.
Web Art Director’s Toolkit.. hmmm…
Great move, and thank you. I wish I new more Js and could participate…
This is an answer to the question of why is it good to have so many typefaces on the web now if we can’t kern the letters correctly, isn’t it ?
One concern though : you’ve covered the SEO side of things, but I guess accessibility is affected by this too. Maybe there could be a conditional comment shortcutting this Js for the less lucky of us who can’t enjoy great typography ?
This is way awesome, great job guys!
Looks very tidy :)
I wrote something like this a while back but didn’t get round to giving you more control. It just just wraps words and letters with class names in the form of:
.letter-a, .word-the, .letternum-2, .wordnum-1 etc…
It gives you classes for the letter, the word but also the number of that letter or word should it recur with the word or sentence respectively. It also gives you the .letter-special class for things like ampersands and punctuation though more specific classes would be better. Maybe in another release.
My crappy ugly demo is at http://sanchothefat.com/dev/code/g3t.html but maybe it’ll give you some ideas should you ever extend the plugin further.
Very interesting effect. I probably use it for my personal website.
Thanks for your works :)
What are these art direction plugins for ExpressionEngine you speak of?
I may have failed you. I saw Veerle Pieters (and then maybe Yaron Schoen) post about it once, but I can’t find the link anywhere on the whole internet. I imagine a custom field that you echo in the
would work… I’ll keep looking though.Got this look with it. Love it:
http://timmelideo.com/stuff/icecream/
You’ve unlocked the First Rebound Achievement!! +20G Keep it up!
It’s very very nice, I love merci beaucoup pour ce beau travail !
The .js plugin was a smart solution. I like the demo at the top of this page — delightful to see the letters bounce. I also appreciate your taking kerning into consideration. And regarding FOUT, my personal preference is to avoid it at all costs. My perception is that it’s better to have the page load consistently as FOUT is an unwelcome surprise that I’m not expecting.
This is great. I was wondering how the type was done on the El Dorado page.
Just a thought …. by injecting a span element around individual letters, is this going to work nicely with screen readers? AFAIK, a similar technique (Cufon – which broke up words by letter) caused some screen readers to read Each. Letter. As. A. Word. By. Itself. So, a note of caution – check the effect of applying lettering.js with a screen reader, just in case it does something untoward. Sorry, don’t mean to be a party-pooper, just thought you’d rather know *if* it causes such problems.
@Ian, thanks for bringing this up. I googled Cufón’s problem, I tested Lettering.JS and confirmed the results. Screen. Readers. Break. Up. Span. Tags. That was quite unexpected.
Don’t worry about being a party-pooper on these sorts of things. Thanks for the heads up. I lost a little sleep thinking about it last night, but don’t you worry about that. This is now Job #1.
Probably the most frequent thought on web type by coders but finally someone just brought it to life in a usable manner. !!1K
Really good news, this is really pretty and beautiful. I’ll use it on my website.
This is awesome. Simply awesome.
I like the plugin a lot, but this page is MESSED UP in Safari 5 and Chrome 6.0.472.59 for PC.
Looks great in Firefox!
Thanks, Clint. I’ll double check it in those guys again.
I’d add the following classes to the javascript to output like so:
S
o
m
e
T
i
t
l
e
So you could target the first character, all instances of a character, of the nth instance of a character.
Crap: the comment box ate my example!
h1 class=”fancy_title”
span class=”char1 char_S char_S_1″ S /span
span class=”char2 char_o char_o_1″ o /span
span class=”char3 char_o char_o_2″ m /span
span class=”char4 char_e char_e_1″ e /span
span class=”char5 char_space char_space_1″ /span
span class=”char6 char_T char_T_1″ T /span
span class=”char7 char_i char_i_1″ i /span
span class=”char8 char_t char_t_1″ t /span
span class=”char9 char_l char_l_1″ l /span
span class=”char10 char_e char_e_2″ e /span
/h1
The 80s called. They want their plain US-ASCII way of thinking back…
@Roland – I’m actually tri-lingual and have a degree in Japanese from the University of Texas at Austin. After living 3 years in a remote village in Japan, I’d say the Japanese language has quite a presence in my everyday thinking. I’m very aware of making this plugin UTF-8 aware and compatible. And in my initial tests it worked pretty well.
I’m sorry to be such a stick-in-the-mud, but wouldn’t breaking up the text into individual letters defeat the purpose of using text as opposed to images in the first place? Or does the google ignore the script and gets served “Some Title” in its entirety?
It’s tough to say what Google does. Not only is it an inline tag (that’s allowed), and it’s all manipulation after the DOM is ready. If it worries you, feel free to use it on non-essential content.
It’s not only everything that unicode offers that would make it more complicated, but also the possibility of having more than just a text node to work with. I can see the niche in which lettering.js can be helpful, but that won’t include solutions with a wide range of dynamic content, and for a limited range of content it has a lot in common with solutions where using an image could be considered to get even more improved typographic results.
Great tool. Thanks for sharing, guys!
This page is in desperate need of some screenshots and demos.
Explained Well…But Kindly Show Preview Of Each Code After the Code..
Great idea, and great work guys, but it seems that this approach is still a bit hacky. Internet browsers need to simply keep up with the ever changing needs and styles of web designers and our need to use more fonts for typography, and properly that load code.
Great thanks , i added a link from my personal list in
http://www.ajaxshake.com
It looks fun, but I can’t seem to get it functioning in IE?
Was that intentional?
It was actually designed for and implemented first on IE (specifically IE9 beta) over at the Lost World’s Fair http://lostworldsfairs.com
There’s also a slightly older version of the script guaranteed to work if the 0.6.1 is failing, but it shouldn’t.
Gosh, I sure as heck hope so! :)
awesome and unfortunately its not practicable
Very nice.
I’ll try to use it as soon as possible
Fringe design at its best. Can’t wait to play with this on my next project.
This is wonderful. Really came in useful on a project I was working on. Thanks!
Glad to hear, please share!
This is great!…I’ve always avoided plugins that have the need for Flash(cufon etc)…nice one Dave
This is really cool, thanks for sharing
Great plugin, Will definitely use it in the future. Thanks for the hard work!
a Ha~,a great plugin for jquery.I like it.
Very impressive guys! Now to think up excuses to use this.
Thanks for this wonderful plugin . I downloaded it today and noticed few things
1) If the text is unicode , It is just displaying the question marks
2) with latest Jquery “words” option is not working .
Thanks a lot again
Regards
Kiran
was your page encoded in UTF-8?
can you give me a sample of the code you used for “words”?
It may be that I haven’t tried hard enough, but is it possible to combine words and characters? When I apply .lettering() to the same id as .lettering(‘lines’), it seems to miscount and I get random span breaks. So, “Why’d you /do/ that” becomes Why’d /you/ do that.
If that makes sense…
It sure is! You’ll want to look into chaining the words and characters methods… have a look at https://github.com/davatron5000/Lettering.js/wiki/Chaining-with-lettering%28%29 on the Wiki. I think it’ll do what you’d want.
I’m confused because the files in this code are differently named than the files in the minified pack.
If you don’t mind, i’m asking for your help and the most important part is i’m a newbie, a little familiar with javascript or jQuery.
Question is how should i start or from where.
first i made a html file, with basic codes head and body. then this “Some Title” in body with this “<script src="pat…
” in head.
now what ?
how this these codes will generate something and where will be the “wow!” code.
if you don’t write me then that’s good but if you write then please please please write it elaborately.
thanks in advance.
@Zahin – You’re on the right track.
Use something like Firebug or Web Inspector (for Chrome and Safari) to confirm both jQuery and Lettering are loading into your page.
Good Luck!
“It is very hard to do a work or to tell someone about that if you have a little knowledge.”
okay i start again.
first i made a file named test.html. then added scripts sources and script in header section. and h1 code at body section. full code is:
is it right ? i dont think so.
what in my mind is it’s just a page, not a software. how will it generate codes. please say where’s i’m doning wrong.