Web typography at its finest: font-size and line-height based on element width.

Overview

FlowType.JS

Responsive web typography at its finest: font-size and line-height based on element width.

Check out the demo site.

What does FlowType.JS do?

Ideally, the most legible typography contains between 45 and 75 characters per line. This is difficult to accomplish for all screen widths with only CSS media-queries. FlowType.JS eases this difficulty by changing the font-size and line-height based on a specific element's width. This allows for a perfect character count per line at any screen width.

Options

Thresholds

Set minimum and maximum width thresholds to control the FlowType.JS magic within specific element widths.

In this example, FlowType.JS will stop resizing text once the element width becomes smaller than 500px or larger than 1200px.

$('body').flowtype({
   minimum : 500,
   maximum : 1200
});

Set minimum and maximum font-size thresholds to control the FlowType.JS magic within specific font sizes.

In this example, FlowType.JS will stop resizing text once the font-size becomes smaller than 12px or larger than 40px.

$('body').flowtype({
   minFont : 12,
   maxFont : 40
});

Font-size

Set your own font-size using the fontRatio variable. When using fontRatio, increase the value to make the font smaller (and vice versa).

Note: Because each font is different, you will need to "tweak" fontSize and "eye ball" your final product to make sure that your character count is within the recommended range.

Line-height (lineRatio) is set based on the fontRatio size, and defaults to 1.45 (the recommended line-height for maximum legibility). See line-height below.

$('body').flowtype({
   fontRatio : 30
});

Line-height

In v1.0 of FlowType, we made the plugin set a specific line-height in pixels. We received many statements that setting a specific line-height is very dangerous. So, what did we do? We removed support for line-height in v1.1.

What do I do now? It's quite simple: use unitless line-height in your CSS. It will automatically make changes based on the font size. Here's an example of what we suggest for line-height:

line-height: 1.45;

Getting Started

Step 1: Install FlowType.JS

To use FlowType, you'll need to make sure both the jQuery and FlowType.JS scripts are included.

#####Download FlowType.JS#####

#####Include jQuery and FlowType.JS scripts#####

<script src="//code.jquery.com/jquery-latest.min.js"></script>
<script src="flowtype.js"></script>

Step 2: Set Typography Base

Prepare for FlowType.JS by making sure that the typography is flexible. Start with this CSS and make changes as necessary:

body {
   font-size: 18px;
}

h1,h2,h3,h4,h5,h6,p {
   line-height: 1.45;
}

h1 { font-size: 4em; }
h2 { font-size: 3em; }
h3 { etc...

Note: Setting a specific font-size in your CSS file will make sure that your website remains accessible in case your viewer has JavaScript disabled. These numbers will be overridden as FlowType.JS updates the font-size number inline.

Step 3: Call FlowType.JS

To begin the magic, simply call FlowType.JS before the close of your body tag:

$('body').flowtype();

Step 4: Make Changes

You will most likely want to change the default settings. To do so, simply include these options in your code and tweak away:

$('body').flowtype({
   minimum   : 500,
   maximum   : 1200,
   minFont   : 12,
   maxFont   : 40,
   fontRatio : 30
});

Note: When using FlowType.JS, it will only perform it's magic on the element and child elements that are specified in the closing document's call. For example, if you have <p> inside of an <article> and you apply FlowType.JS to <p>, it will only update <p> and not <article>. But, if you apply FlowType.JS to <article>, the entire contents including <p> will be updated. We believe that this can be used to your advantage. So, tweak and change as you feel necessary:

$('body').flowtype({
   minimum   : 500,
   maximum   : 1200,
   minFont   : 12,
   maxFont   : 40,
   fontRatio : 30
}),
$('article').flowtype({
   fontRatio : 36
}),
$('.featured-article').flowtype({
   minFont   : 12,
   fontRatio : 20
}),
$('.side-stories').flowtype({
   minFont   : 16,
   fontRatio : 30
});

Brought to you by...

This wonderful piece of magic has been brought to you by the team at Simple Focus. Follow Simple Focus on Twitter: @simplefocus.

FlowType.JS is licensed under the MIT License. See the LICENSE.txt file for copy permission.

Comments
  • Added FlowType Sass mixin

    Added FlowType Sass mixin

    New FlowType Sass mixin. For use in place of jQuery version. Brief usage documentation added to README.

    Demo can be found at http://codepen.io/bphillips201/pen/af2e044df72883cdce789e3aed455b53

    opened by bphillips201 16
  • adding package.json

    adding package.json

    Hi,

    I wrote a small package.json to be able to add FlowType.JS as a npm dependency. Now you can :

    npm install --save kane-thornwyrd/FlowType.JS
    

    Or just set your dependencies object as followed :

    dependencies": {
      "grunt": "^0.4.5",
      "grunt-contrib-jshint": "^0.10.0",
      "grunt-contrib-watch": "^0.6.1",
      "underscore": "^1.6.0",
      "FlowType.JS": "kane-thornwyrd/FlowType.JS"
     },
    

    If you agree to merge this pull request you'll find handy to replace kane-thornwyrd/FlowType.JS by simplefocus/FlowType.JS.

    Eventually you may do some tweak and a npm publish.

    opened by kane-thornwyrd 8
  • Throttle .resize()

    Throttle .resize()

    I was about to do a PR for this but then i tought submitting an issue first might be a better idea.

    What do you think about this? I think it's a good idea only to fire the resize function once every 300ms? I know that this is pretty fast, but you know... :shipit:

    Suggestion 
    opened by saibayadon 8
  • Flowtype working on H1 but not on spans (?)

    Flowtype working on H1 but not on spans (?)

    Having an odd issue popping up and must be missing something simple.

    I am using flowtype in two area of my page - once on a headline, and again on a set of spans.

    Upon resize I can see the h1 resize and watch the inline font-size value change in my inspector - I also see the inline font-size being applied/added to the spans, but on resize the font-size value doesn't change for the spans.

    So it would appear the code is working correctly on h1 and starts the process for the spans but doesn't update their values on resize - Am I missing something?

    Much thanks in advance.

    opened by sweas 5
  • pm : added bower.json

    pm : added bower.json

    Adding a manifest file for package mangement via Bower (simplefocus/FlowType.JS#4)

    Might want to change the version tag to your chosen value (be sure to use semver) and add a corresponding tag on the tree. Then run bower register Flowtype.js git://github.com/simplefocus/FlowType.JS.git from the command line to register the package.

    Should keep them happy :)

    opened by ninjatronic 5
  • Question - Tested Browsers

    Question - Tested Browsers

    Can't seem to find any information on what browser versions this has been tested on? Can anyone point me in the right direction or could this be added? Cheers.

    opened by mwhittet 4
  • Please take into account font-size

    Please take into account font-size

    FlowType works like a charm for the most part, but it overrides the font-size CSS property, so I'm forced to call flowtype() multiple times for different elements because they require different fontRatio settings. If FlowType works relative to the element's font-size, then you'll just need to call flowtype() once and fontRatio won't be required anymore in most cases.

    opened by thdoan 3
  • Use a unitless line-height

    Use a unitless line-height

    I don't think it's necessary for FlowType to update the line-height as the font-size changes. It's better to use a unitless line-height in css. This will automatically scale up/down with the font size, so the effect is the exact same.

    body {
      font-size: 18px;
      line-height: 1.45;
    }
    

    I would also suggest changing the "Set Typography Base" section of your readme because, in my opinion, suggesting people set line-height in pixels is a very bad idea. Unitless line-heights also have the advantage of much smarter and more useful cascading to other elements. http://meyerweb.com/eric/thoughts/2006/02/08/unitless-line-heights/

    opened by Lab43 3
  • Question on minFont

    Question on minFont

    I have a page with highly stylized fonts of many varying sizes. If I call flowType on the whole thing, it works, but I am confused by how minFont works:

    I set my font sizes in css first, then when I called flowType I set the fontRatio to 100 to get it back to resembling the comp I'm working from. I want to resize all text on the page, but I want each individual element to stop being resized when it gets to 12px font size. However, when I set a minFont of 12 it seems to raise the base font size (so it increases all font sizes) and then nothing is resized when I change the browser window size. Am I just not understanding what minFont is supposed to do?

    I don't know if this should matter but I have also set the body's font-size to 62.5%. The page is not live anywhere so unfortunately I can't provide a link.

    Great plugin overall, I'm just confused :) thanks in advance for help!

    question 
    opened by pelledear 3
  • Creative Commons licensing

    Creative Commons licensing

    I'm sorry to say, but I won't be using FlowType.js at work, much as I'd love to. And all because your licensing requires an attribution link. The license header in the script and its links in FlowType.js aren't enough? I know that as a developer when I want to see how someone did something on the 'net I use View Source and check out their CSS/JS.

    We aren't about to link to a script that requires us to publicly post a link on the sites we design. This library is such a tiny part of the overall design it doesn't deserve the same recognition as our link for "Web Design by..." does, when we did all the work.

    I suggest that you pick a more permissive license than CC-SA.

    opened by rk 3
  • Clashing with other javascript...

    Clashing with other javascript...

    I've successfully implemented flowtype.js on some text on a basic html page. But as soon as I try it on the same text in my website (built from a responsive template)... nothing.

    Through trial and error I have narrowed it down to an issue with: app.js vendors.js index.js

    As soon as I take the links to these out of my site it works a charm.

    Any ideas would be greatly appreciated... promlem_js.zip

    opened by chrisshaw27 2
  • Using FlowType.js with MatchHeight.js

    Using FlowType.js with MatchHeight.js

    I have a page where I have 5 blocks with text and images in them. They are organized in a row and I am using matchheight.js to keep them all the same height and Flowtext so the text will be the correct size within the boxes as they resize. However when the page first loads some of the boxes have different size text than the others - even though they all have the same base font size and the boxes are the same size. When I adjust the size of the window everything recalculates and the font sizes are all uniform. Is there a way to trigger the recalculation without resizing the window.

    Here is a codepen: http://codepen.io/dll416/pen/xgeeoz

    The viewport has to be 1200px or below to see the issue.

    opened by Dabalina 3
  • FlowType makes elements that have a padding set with em values jump on resize & reload

    FlowType makes elements that have a padding set with em values jump on resize & reload

    Check this fiddle please and possibly advise how this could be fixed.

    • 1st div has a padding value set with em.
    • 2nd div has a padding value set with px.
    • 3rd div has a padding value set with percentage.

    Run the fiddle, resize (e.g. when user changes device orientation from portrait to landscape) the viewport and then run the fiddle again (what translates to reloading the page after resizing it).

    You can see the 1st div content readjusting font-size and line-height. This creates a quite unpleasant "jump" in the overall page layout.

    Ideally regardless of resizing and then reloading the viewport, the font-size and line-height should be respected or set with regards to any values set in em for that element.

    opened by ghost 3
  • Bower advisory warning and meta mismatches

    Bower advisory warning and meta mismatches

    bower invalid-meta The "name" is recommended to be lowercase, can contain digits, dots, dashes

    bower mismatch Version declared in the json (1.0.0) is different than the resolved one (1.1.0)

    Is it me, or is it you?

    If it's not me, can you update the components please?

    Thanks

    opened by geckoseo 0
  • didnt affect tag h

    didnt affect tag h

    my h1,h2,h3,h4,h5,h6 didnt get effect with the script?did i do wrong?

    <script src="js/flowtype.js"></script> <script> $('body').flowtype({ minimum : 300, maximum : 780, minFont : 8, maxFont : 32, fontRatio : 60 }); </script>

    when i minimize my h1 font size still 32px from bootstrap.min.css

    opened by vandivicario 0
  • Support modules and npm

    Support modules and npm

    It would be great if this library were wrapped in a module. Examples in numerous JS libraries show how to support global, CommonJS and AMD in the same file. This is a good read: http://ifandelse.com/its-not-hard-making-your-library-support-amd-and-commonjs/

    Also would be nice to have a package.json to support npm. Don't have to publish on npm registry anymore as npm supports referencing a git repo. I would be happy to provide a pull request.

    opened by peacechen 3
A lightweight, easy to use Javascript injector for radical Web Typography

Lettering.js, a jQuery plugin for radical Web Typography We developed a lightweight, easy to use Javascript span injector for radical Web Typography,

Dave Rupert 5.4k Dec 20, 2022
A JavaScript library that lets you curve type on the web.

CircleType A JavaScript library that lets you curve type on the web. Demo: https://circletype.labwire.ca Installation In a browser: <script src="circl

Peter Hrynkow 622 Dec 17, 2022
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 resizi

Dave Rupert 6.8k Dec 30, 2022
jQuery plugin, calculates the font-size and word-spacing needed to match a line of text to a specific width.

BigText BigText Makes Text Big Read the original blog post Play around on the demo Watch the video Download bigtext.js Or use bower: bower install big

Zach Leatherman 883 Dec 15, 2022
Experimental tool inspired by Capsize, implemented in Solid JS. Generates x-height and cap-height CSS

Usage Those templates dependencies are maintained via pnpm via pnpm up -Lri. This is the reason you see a pnpm-lock.yaml. That being said, any package

Zaydek MG 2 Jul 5, 2022
null 3.9k Dec 30, 2022
An Awesome Toggle Menu created with HTML,CSS,JQuery,font-awesome and line by line comment.

Demo : https://blackx-732.github.io/AwesomeMenu/ Under open source license No ©copyright issues Anyone can be modify this code as well Specifically we

BlackX-Lolipop 2 Feb 9, 2021
一个运行在浏览器内的提词器,可翻页,可变速,可自定义字体、大小、颜色等多种选项 A teleprompter in web browser, page down, speed up , custom font family/size/color and more.

Introduction 一个运行在浏览器内的提词器,可翻页,可变速,可自定义字体、大小、颜色等多种选项 A teleprompter in web browser, page down, speed up , custom font family/size/color and more. inst

Daniel Liu 19 Aug 17, 2021
Generate font size variables for a fluid type scale with CSS clamp.

Fluid Type Scale Calculator Generate font size variables for a fluid type scale with CSS clamp. Overview Customize everything, grab the output CSS, an

Aleksandr Hovhannisyan 136 Dec 31, 2022
Simple, buffered, line-by-line file reader with customizable buffer size.

simple-line-reader Simple, buffered, line-by-line file reader with customizable buffer size. Install npm install simple-line-reader yarn add simple-li

null 3 Jan 15, 2022
基于vue3.0-ts-Element集成的简洁/实用后台模板!《带预览地址》vue-admin;vue+admin;vue-element;vue+element;vue后台管理;vue3.0-admin;vue3.0-element。

一、基于vue3.0+ts+Element通用后台admin模板 二、在线预览地址:http://admin.yknba.cn/ 三、下载使用: 1、克隆代码 通过git将代码克隆到本地;或者使用下载安装包模式进行下载。 2、进入目录 进入项目的根目录:vue3.0-ts-admin 3、安装依

null 64 Dec 16, 2022
A lightweight, easy to use Javascript injector for radical Web Typography

Lettering.js, a jQuery plugin for radical Web Typography We developed a lightweight, easy to use Javascript span injector for radical Web Typography,

Dave Rupert 5.4k Dec 20, 2022
This is a Pokemon cards website. There are 800+ pokemon sprites with their name, moves height, weight, and picture

Hi ?? , I'm Rayan Hossain A passionate Full Stack developer with expertise in WordPress ?? I’m currently working on codes_tips ?? I regularly write ar

Rayan Hossain 2 Oct 5, 2022
BMI Calculator can give us the bmi result of our bmi on the basis of our corresponding height and weight.

BMI means body mass index. Body Mass Index (BMI) is a person's weight in kilograms divided by the square of height in meters.

Bipronath Saha 1 Jan 20, 2022
Exposes theming options available in Joy UI by providing color palette and typography controls.

Joy Theme Creator Note: Joy UI is currently in alpha - some things may not be finished or working as expected. This project exposes the theming option

Oliver Benns 10 Dec 28, 2022
It's a repository to studies. Its idea is to learn about Nx and its plugins.

StudyingNx This project was generated using Nx. ?? Smart, Fast and Extensible Build System Adding capabilities to your workspace Nx supports many plug

Open-ish 4 May 13, 2022
Gatsby-starter-minimal-blog - Typography driven, feature-rich blogging theme with minimal aesthetics.

Gatsby-starter-minimal-blog - Typography driven, feature-rich blogging theme with minimal aesthetics. Includes tags/categories support and extensive features for code blocks such as live preview, line numbers, and line highlighting.

Priya Chakraborty 0 Jan 29, 2022
Autosize is a small, stand-alone script to automatically adjust textarea height to fit text.

Summary Autosize is a small, stand-alone script to automatically adjust textarea height to fit text. Demo Full documentation and a demo can be found a

Jack Moore 5k Jan 6, 2023
A typography stylesheet for readable content

yue.css yue.css is a typography stylesheet for readable content. It was created for my blog at first since I always designed a new theme for my blog.

Typlog 481 Dec 22, 2022
Can see everything, beware of its omniscience, kneel before its greatness.

Can see everything, beware of its omniscience, kneel before its greatness. Summary Presentation Installation Removing Credits Presentation Main goal T

Duc Justin 3 Sep 30, 2022