
Flexflex is a JavaScript-based typographic experiment that renders letters that respond to spatial requirements.
The library enables you to draw letters that continuously transform to fit inside any rectangular container, no matter how its aspect ratio changes.
Instead of using a static font file, it draws monolined, uppercase letterforms directly onto an SVG or Canvas element.
Features:
- Container-based rendering: Letters automatically scale and adapt to fit any rectangular boundary with mathematical precision.
- Dual rendering support: Works with both SVG elements and Canvas contexts, including compatibility with p5.js drawing contexts.
- Geometric consistency: All letterforms use circular arcs and maintain uniform stroke weights regardless of container dimensions.
- Real-time transformation: Characters can adapt continuously as container dimensions change. Ideal for responsive web layouts.
- Skewing and styling options: Includes parameters for letter slanting, stroke cap styles, and corner treatments.
How to use it:
1. Download the Flexflex package and include the main JavaScript file on your webpage.
<script src="flexflex.js"></script>
2. Add an <svg> or <canvas> element to your document.
<!-- For SVG --> <svg id="my-svg"></svg> <!-- Or for Canvas --> <canvas id="my-canvas"></canvas>
3. Use the global drawLetter function to render your letters. All available parameters:
el: The target<svg>or<canvas>DOM element, or a 2D rendering context if you’re using a library like p5.js.ch: The single character to draw (A-Z, case-insensitive).x,y: The top-left coordinates of the letter’s bounding box.w,h: The width and height of the letter’s bounding box.col: The stroke color, as a CSS color value.sw: The stroke width. This is drawn on the inner side of the path, so the letter never exceeds its bounding box.skewAngle(optional): An angle in degrees to slant the letter.linecap(optional): Stroke end style, either “square” (default) or “round”.linejoin(optional): Stroke corner style, either “miter” (default) or “round”.
drawLetter(el, ch, x, y, w, h, col, sw, [skewAngle], [linecap], [linejoin])
FAQs
Q: Can I use custom characters or add my own?
A: Not out of the box. The letterDescription function only defines logic for the 26 uppercase Latin letters. To add more, you would need to edit the source code and write your own SVG path logic inside the switch statement, following the same geometric constraints.
Q: How does performance hold up when drawing hundreds of letters?
A: Since Flexflex generates and renders paths in real-time using JavaScript, performance will be slower than browser-native text rendering. For SVG, adding hundreds of DOM nodes could slow down interactions. For Canvas, performance should be better, but it’s still executing drawing commands for every single letter on every frame if you’re animating. We’d recommend it for headlines or small amounts of text, not for long paragraphs.
Q: Why doesn’t it just use a variable font file?
A: Flexflex is more of a typographic experiment than a replacement for standard fonts. Its goal is to create letters that are fundamentally defined by their container, a different concept from variable fonts where a master design is interpolated along predefined axes. This library’s approach allows for unique transformations that a typical variable font might not be designed for.
Q: Can I animate the letters?
A: Yes. By calling drawLetter inside an animation loop (like requestAnimationFrame) and changing the w, h, or skewAngle parameters over time, you can create smooth animations of the letters transforming.







