GithubHelp home page GithubHelp logo

phnz / flowtype.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from simplefocus/flowtype.js

0.0 2.0 0.0 254 KB

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

License: MIT License

flowtype.js's Introduction

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 subsequently the 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 and line-height

Set your own font-size and line-height using fontRatio and lineRatio variables.

When setting the font-size using fontRatio, increase the value to make the font smaller (and vice verse).

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

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

Getting Started

Step 1: 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;
   line-height: 26px;
}
h1,h2,h3,h4,h5,h6,p {
   font-family: inherit;
   font-size: inherit;
}
h1 {
   font-size: 4em;
   line-height: 1em;
}
h2 {
   font-size: 3em;
   line-height: 1em;
}
h3 { etc...

Note: Setting a specific font-size and line-height 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 and line-height numbers inline.

Step 2: Include FlowType.JS

After you have downloaded FlowType.JS, include the flowtype.jQuery.js in the head of your HTML document.

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,
   lineRatio : 1.45
});

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.

flowtype.js's People

Contributors

dciccale avatar johnbarrierwilson avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.