‹‹ homejQuery Fancy Letter Plugin


The Fancy Letter Plugin lets you prettify your web page by styling the first letter of any element while keeping the HTML markup clean and readable by both human and machine.

If you like this plugin and you're feeling generous, perhaps you'd also like to visit my amazon.com wish list?

Quick Start Guide

Include the jQuery core file and the Fancy Letter plugin in the <head> of your document. After these scripts are referenced, you can reference a custom script file to add your fancy letters (preferred) or enter the script directly in the <head> (shown below).

<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.fancyletter.js" type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function() {

  // simple example wraps the first letter of
  $('div.content p').fancyletter();


Fancy letters are wrapped in a span tag. Each span is given two classes: a common class ("fancy-letter" by default) and a "letter" class.

Add CSS to style the fancy letters.

For example, after applying the .fancyletter() method to:
<p>This paragraph</p>

it might look like this:
<p><span class="fancy-letter ltr-t">T</span>his paragraph</p>.

Add HTML markup to your page for elements that you want to begin with a fancy letter.

See API / Options for more ways to customize the behavior and appearance of the expander.

Here are four examples of the Fancy Letter Plugin in action:

This sentence begins with a fancy letter, produced by the code below:

$('#demo p:first').fancyletter();

And this sentence begins with a different fancy letter, produced by this code:

$('#demo p:eq(1)').fancyletter({commonClass: 'scarlet-letter'});    

“D”ieter Steffman has a lot of beautiful fonts like this one (Sentinal). To show it, I used the following code, along with an @font-face declaration. View source to see the styles applied.

$('#demo .steffman').fancyletter({commonClass: 'ds'});
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Tut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Code for these fancy letters is shown below. Note the use of the characters option. It takes a string that is interpreted as a regular expression.
$('#demo-divs > div').fancyletter({ltrClassPrefix: 'bg-', characters: '[A-S]'}); 

Fancy Letter Plugin API / Options

The Fancy Letter Plugin API provides a single method with a few options.

Wraps a span element (with classes) around the first letter of all elements matched by the jQuery selector.
$.fn.fancyletter.defaults = {
  commonClass:      'fancy-letter',
  ltrClassPrefix:   'ltr-',
  characters:       '[a-zA-Z0-9]',
  groupPunctuation: true,
  punctuationClass: 'punct',

  punctuationLeft: {
    '"': 'dquo',
    "'": 'squo',
    '“': 'ldquo',
    '‘': 'lsquo',
    '«': 'laquo',
    '‹': 'lsaquo',
    '(': 'lparen'
  punctuationRight: {
    '"': 'dquo',
    "'": 'squo',
    '”': 'rdquo',
    '’': 'rsquo',
    '»': 'raquo',
    '›': 'rsaquo',
    ')': 'rparen'


The Fancy Letter Plugin is available at: github.com/kswedberg/jquery-fancyletter.


If you discover a bug with the Fancy Letter Plugin, please submit a report at github.com/kswedberg/jquery-fancyletter/issues.