Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Design Web Typography Laying Out Type for the Web Responsive Typography

Josie Nagy
Josie Nagy
14,992 Points

How should I use FitText.js? ( Web Typography -> Responsive Typography )

Hi everyone!

So I was watching 'Responsive Typography' when Mattox Schuler mentioned FitText (from this website: http://fittextjs.com/) as begin really useful when it comes to scaling display text.

Sounds great! But how do I actually use it?

I tried copy pasting this code into my CodePen project's html:

<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>

... but nothing happened. I also downloaded their files from GitHub.

So what should I do now?

1 Answer

Boonsuen Oh
Boonsuen Oh
18,788 Points

You wanted to use Fittext.js in CodePen. Notice that you are using a relative path instead of a CDN link or any link that points to the Fittext.js file.

<script src="jquery.fittext.js"></script>

Instead, use this one in CodePen.

<script src="https://cdnjs.cloudflare.com/ajax/libs/FitText.js/1.2.0/jquery.fittext.min.js"></script>

In the environments where you can edit/modify the folder and files, like Treehouse Workspaces or your local computer, you can put the Fittext.js file anywhere you want, but remember to use a path that points correctly to the that file in the SRC attribute.

Josie Nagy
Josie Nagy
14,992 Points

Thank you for replying so fast. What about the <script> jQuery("#responsive_headline").fitText(); </script> part? Should I also delete that? I added the new code and I've tried all combinations, with the jQuery part and without it, but it still doesn't seem to work. :( Did it work on your side?