Skip to content

Fluid font-size AND line-height powered by CSS Container Queries

License

Notifications You must be signed in to change notification settings

gbdrummer/fluid-typography

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

Repository files navigation

fluid-typography

This CSS Library leverages CSS Container Queries to dynamically alter font-size and line-height values in response to resizing of elements. There is no JavaScript involved, only liberal use of CSS Container Queries, Custom Properties and the calc function.

Credit for the math belongs to Chris Pearson, creator of the Golden Ratio Typography Calculator.

Usage

Just include fluid-typography.css in the <head> of your html document, and add the fluid attribute to the DOM elements you would like to exhibit the fluid behavior. See example.html for an example implementation.

For the algorithm to work in CSS, the following values are necessary:

  • min and max viewport width (--vp-width_min and --vp-width_max)
  • min and max font-size (--font-size_min and --font-size_max)
  • min and max line-height (--line-height_min and --line-height_max)
  • desired CPL (Characters Per Line) (--cpl)
  • Character Width (---char-width)

See fluid-typography.css for the default values.

NOTE: The default Character Width is 2.27. This value was chosen because it is the average character width of 135+ fonts. This value should work well in most cases, but tweaking it can sometimes provide better results. Changes to this value will affect the way line-height is calculated, in concert with --cpl.

Coming Soon

  • Automatic calculation of h1 - h6 font-size and line-height values

About

Fluid font-size AND line-height powered by CSS Container Queries

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published