• Stars
    star
    6,769
  • Rank 5,545 (Top 0.2 %)
  • Language
    HTML
  • Created almost 13 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A jQuery plugin for inflating web type

FitText.js, a jQuery plugin for inflating web type

FitText makes font-sizes flexible. Use this plugin on your responsive design for ratio-based resizing of your headlines.

How it works

Here is a simple FitText setup:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="jquery.fittext.js"></script>
<script>
  jQuery("#responsive_headline").fitText();
</script>

Your text should now fluidly resize, by default: Font-size = 1/10th of the element's width.

The Compressor

If your text is resizing poorly, you'll want to turn tweak up/down "The Compressor". It works a little like a guitar amp. The default is 1.

jQuery("#responsive_headline").fitText(1.2); // Turn the compressor up   (resizes more aggressively)
jQuery("#responsive_headline").fitText(0.8); // Turn the compressor down (resizes less aggressively)

This will hopefully give you a level of "control" that might not be pixel perfect, but resizes smoothly & nicely.

minFontSize & maxFontSize

FitText now allows you to specify two optional pixel values: minFontSize and maxFontSize. Great for situations when you want to preserve hierarchy.

jQuery("#responsive_headline").fitText(1.2, { minFontSize: '20px', maxFontSize: '40px' });

CSS FAQ

  • ⚠️ Run FitText before anything that hides the element you're trying to size (e.g. before Carousels, Scrollers, Accordions, Tabs, etc). Hiding an element's container removes its width. It can't resize without a width.
  • ⚠️ Make sure your container has a width!
    • display: inline elements don't have a width. Use display: block OR display: inline-block+ a specified width (i.e. width: 100%).
    • position:absolute elements need a specified width as well.
  • Tweak until you like it.
  • Set a No-JS fallback font-size in your CSS.
  • πŸ†• If your text is full width, you might want to NOT use FitText and just use CSS vw units instead. Supported in all major browsers.

Don't use jQuery?

That's okay. Check out these handy non-jQuery versions maintained by other people.

Changelog

  • v 1.2 - Added onorientationchange event
  • v 1.1 - FitText now ignores font-size and has minFontSize & maxFontSize options
  • v 1.0.1 - Fix for broken font-size.
  • v 1.0 - Initial Release

In Use:

If you want more exact fitting text, there are plugins for that! We recommend checking out BigText by Zach Leatherman or SlabText by Brian McAllister.

Download, Fork, Commit.

If you think you can make this better, please Download, Fork, & Commit. We'd love to see your ideas.

More Repositories

1

Lettering.js

A lightweight, easy to use Javascript <span> injector for radical Web Typography
JavaScript
5,393
star
2

FitVids.js

A lightweight, easy-to-use jQuery plugin for fluid width video embeds.
HTML
4,772
star
3

awesome-standalones

A curated list of awesome framework-agnostic standalone web components
1,183
star
4

Foldy960

A responsive version of the 960 grid, the Pvel way!
CSS
483
star
5

TimeJump

TimeJump – Deep-links for Podcasts
JavaScript
348
star
6

can-i-subsystem-it

313
star
7

deCSS3

A lil' bookmarklet that will strip out your CSS3 rules and show you how gracefully you're degrading.
JavaScript
311
star
8

podcast-player

An audio web component for podcasts
117
star
9

a11y-nutrition-cards

Nutrition Cards for Accessible Components
HTML
90
star
10

htmlwithsuperpowers

A guidebook to Web Components
86
star
11

Better-Art-Direction

A fork of the incredible Art Direction plugin by NoΓ«l Jackson (http://noel.io).
PHP
77
star
12

fitWeird

A window monitor bookmarklet.
JavaScript
63
star
13

WP-Dribbble

A wordpress plugin and widget that pulls in your latest Dribbble shots.
PHP
54
star
14

fit-vids

Web Component version of FitVids from the creator of FitVids
JavaScript
35
star
15

Borkers

HTML5 Boilerplate + Starkers = Borkers! A starter theme.
PHP
22
star
16

humans-vs-robots

An unpacked chrome extension for Github
JavaScript
19
star
17

wobbly-box

A web component for drawing wobbly boxes
JavaScript
16
star
18

alpha-paintlet

A CSS Paint worklet that converts alpha's your bg-color based on some variables.
HTML
14
star
19

NodebotUI

Twitter Bootstrap for Nodebot Interfaces
JavaScript
14
star
20

sortByData

A simple jQuery plugin that lets you sort a collection of elements by any data- attribute you want.
JavaScript
5
star
21

2x

A chrome extension for speedier HTML Media
JavaScript
5
star
22

worker-controller

JavaScript
4
star
23

html-with-superpowers

HTML
4
star
24

htmlwithsuperpowers-deck

Vue
4
star
25

FitGrid

3
star
26

api-screenshot

JavaScript
2
star
27

jekyll-reduced-test-case

Ruby
1
star
28

jekyll-polymer

HTML
1
star
29

davatron5000

1
star
30

12th-Street-Bakery

A non-profit bakery teaching at-risk teens the art and skill of baking.
HTML
1
star
31

begin-graphql-test

Begin app
JavaScript
1
star