Skip to Content

Fit Text – What a difference a Dave makes

Introduction

Whilst looking into a project in which I wanted ‘large scalable responsive text’ I tried out various JavaScript packages. In the past I would have used Dave Rupert’s FitText but that utilises jQuery which I moved away from quite some time ago.

There have been other non jQuery versions along the way but they all require ‘coaxing’ to get what you need in terms of ‘full width.’

Fitty JavaScript Library Animation
Fitty JavaScript Library Animation

I finally found the Fitty Library from Rik Schennink. Perfect for what I required… To a point.

Using Fitty JS

For full width with no adjustments the library is ‘almost’ perfect. It can on occasion require a page reload which isn’t ideal. Then there’s a big issue with the height of the container parent.

The only way I could think of was to add some extra code in the section that adds the inline code making the height of the container the same size as the font…

v = function (e) {
  (e.element.style.whiteSpace = e.whiteSpace),
  (e.element.style.display = e.display),
  (e.element.style.fontSize = e.currentFontSize + "px");
},

I added…

(e.element.style.height = e.currentFontSize + "px");

So we end up with…

v = function (e) {
  (e.element.style.whiteSpace = e.whiteSpace),
  (e.element.style.display = e.display),
  (e.element.style.fontSize = e.currentFontSize + "px"),
  (e.element.style.height = e.currentFontSize + "px");
},

This was in an effort to allow for variable widths and font sizes…

          WHAT A          
     DIFFERENCE A     
 DAVE 
   MAKES   

All in all, after editing the script itself, then having to add lots of whitespaces ( ) to create the ‘padding’ needed to emulate the different ‘widths’ I decided that I was “on a hiding to nothing.”

Using SVG Text

The alternative is to use good old SVG, my only reticence is making them all accessible. If anyone has any comments about how best to handle something like the example below, please get in touch, I’m all ears.

What a WHAT A
difference a DIFFERENCE A
Dave DAVE
makes MAKES

Download sample code

I’ve assembled all the parts so that you can play with them. The standard – software is provided “as is”, without warranty of any kind – applies here.

Zip File Info
/cooper-std-black.woff2
22.3kB
/fitty.min.js
6.6kB
/index.html
2.5kB
/readme.txt
460B
/style.css
2.4kB
File: barrd-what-a-diff-dave.zip
Details: 5 files @ 30.1kB

That’s all folks

This is more of a template for me to play with but you’re welcome to have a play too. If you have any comments about making SVG‘s more accessible I’m always open to hearing about them.

// End of Project

More Information

Dave A.K.A. 'barrd'

Dave is a Bristol based Scottish Expat who has 20+ years experience of web development. Loves playing guitar, reading books, watching Sci-Fi and tinkering with tech.

About Dave A.K.A. 'barrd'

Image for Dave A.K.A. 'barrd'
Dave is a Bristol based Scottish Expat who has 20+ years experience of web development. Loves playing guitar, reading books, watching Sci-Fi and tinkering with tech.

Read more about Dave