Scrawl-canvas v8 - Snippets test 006

Editable header text colorizer and animation effect snippets

To test accessibility, tab through this demo page

Color fonts are a real thing. However...

... Support for OpenType SVG fonts in browsers is in active development, with all the caveats that apply to such functionality - see the caniuse site for current details.

This demo does not use color font technology, nor does it attempt to replicate color font functionality. Instead it demonstrates the application of color design and animation to any text on the web page, typically in HTML header elements, through the use of Scrawl-canvas snippet modules.

Scrawl-canvas font snippets

The snippets in this demo allow developers to apply color, distortion and animation effects to HTML header text blocks. Each header element can personalize the snippet effect applied to it using both CSS classes and HTML data- attributes (which take priority), meaning each snippet can create a range of different effects.

Heads up! This technique uses Scrawl-canvas snippet modules, which are experimental. Depending on the header size, and the complexity of the pattern design and animation effect, the technique may lead to heavy computation which can result in excessive power use and slower screen refresh rates.

Note that this demo includes many header examples. The more headers that the snippets get applied to, the longer the initial computation takes, which can lead to a delay to the effects appearing on the page - resulting in an unfortunate FOUT (flash of unstyled text).

Use snippets sparingly!

DOM text and canvas text: These snippets work by matching the font characteristics of the DOM headers and recreating the text in a <canvas> element added inside the header element (progressive enhancement). For accessibility and user experience purposes the DOM text is not removed: users should be able to copy/paste the header text as normal. Users who disable Javascript in their devices should still be able to see the normal, CSS styled header text.

Canvas text functionality is severely limited, compared to DOM text. These snippets attempt to:

Accessibility controls and checks include:

Details on how to apply these Scrawl-canvas snippets to DOM elements can be found at the end of this page.

risograph-text-gradient-snippet

This effect is inspired by Risograph printing which uses a limited color palette, stippling colors to create a gradient effect.

The snippet can be customised using the following data- attributes applied using CSS variables, or directly to the HTML header element:

... And for prefers-color-scheme: dark users:

This snippet reacts to the user preference prefers-contrast: more with the following data- attributes:

Risograph effect - default values CSS: .demo-header { font-size: 2em; line-height: 1.15; border: 0; margin: 0; -webkit-hyphens: none; -ms-hyphens: none; hyphens: none; min-height: 1em; caret-color: rgba(0 0 0 / 1); background-color: rgba(0 0 0 / 0); } @media (min-width: 30em) { .demo-header { font-size: 3em; } } @media (min-width: 40em) { .demo-header { font-size: 4em; } } @media (min-width: 50em) { .demo-header { font-size: 5em; } } @media (prefers-color-scheme: dark) { .demo-header { caret-color: rgba(255 255 255 / 1); } } .header-font-sans { font-family: 'Open Sans', 'Fira Sans', 'Lucida Sans', 'Lucida Sans Unicode', 'Trebuchet MS', 'Liberation Sans', 'Nimbus Sans L', sans-serif; /* These font-specific data values can only ever be best-fit approximations - Especially when used for multiple fonts, like here */ --data-y-offset: 0.11; --data-lineheight-adjuster: 0.875; --data-underline-position: 0.75; --data-underline-width: 0.09; /* no space after the colon (unless you don't want underlined spaces) */ --data-no-underline-glyphs:gjpqy } HTML: <h4 id="header-test-1" class="demo-header header-font-sans risograph-header" contenteditable="plaintext-only" >Lorem ipsum dolor <i>sit amet</i>, consectetur <u>adipiscing elit</u> magna aliqua</h4>

Lorem ipsum dolor sit amet, consectetur adipiscing elit magna aliqua

Risograph effect - variant 1 CSS: .header-font-serif { font-family: 'Lucida Bright', 'Lucida Fax', Palatino, 'Palatino Linotype', Palladio, 'URW Palladio', serif; --data-y-offset: 0.1; --data-lineheight-adjuster: 0.84; --data-underline-position: 0.67; --data-underline-width: 0.09; --data-no-underline-glyphs:gjpqy; } .risograph-v1 { --data-random-radius: 0.15; --data-outline-width: 0.08; --data-top-color: red; --data-bottom-color: black; --data-outline-color: gold; --data-dark-top-color: red; --data-dark-bottom-color: white; --data-dark-outline-color: gold; } .no-bold { font-weight: normal; } HTML: <h4 id="header-test-2" class="demo-header header-font-serif no-bold risograph-header risograph-v1" contenteditable="plaintext-only" >Lorem ipsum dolor <i>sit amet</i>, <b>consectetur</b> <u>adipiscing elit</u> magna aliqua</h4>

Lorem ipsum dolor sit amet, consectetur adipiscing elit magna aliqua

Risograph effect - default values with local amendments CSS: .header-font-mono { font-family: 'Fira Mono', 'DejaVu Sans Mono', Menlo, Consolas, 'Liberation Mono', Monaco, 'Lucida Console', monospace; --data-y-offset: 0.15; --data-lineheight-adjuster: 0.85; --data-underline-position: 0.72; --data-underline-width: 0.08; --data-no-underline-glyphs:gjpqy; } HTML: <h4 id="header-test-3" class="demo-header header-font-mono no-bold risograph-header" contenteditable="plaintext-only" data-outline-width="0.1" data-outline-color="darkslateblue" data-dark-outline-color="lightslateblue" data-contrast-color="darkred" data-dark-contrast-color="pink" > Lorem ipsum dolor <i>sit amet</i>, <b>consectetur</b> <u>adipiscing elit</u> magna aliqua </h4>

Lorem ipsum dolor sit amet, consectetur adipiscing elit magna aliqua

worley-text-gradient-snippet

Worley noise is a form of procedural texture which can be generated and used to simulate textures which look (a bit) like stone, water or biological cells.

The snippet can be customised using the following data- attributes applied using CSS variables, or directly to the HTML header element:

... And for prefers-color-scheme: dark users:

This snippet reacts to the user preference prefers-contrast: more with the following data- attributes:

Scrawl-canvas supports several types of noise generation, including Worley noise - see Demo canvas-060.

Worley effect - default CSS: .header-font-cursive { font-family: 'Brush Script MT', 'Brush Script Std', 'Lucida Calligraphy', 'Lucida Handwriting', 'Apple Chancery', cursive; --data-y-offset: 0.15; --data-lineheight-adjuster: 0.83; --data-underline-position: 0.65; --data-underline-width: 0.08; --data-no-underline-glyphs:gjpqy } HTML: <h4 id="header-test-4" class="demo-header header-font-cursive no-bold worley-header" contenteditable="plaintext-only" > Lorem ipsum <b>dolor sit amet</b>, consectetur <u>adipiscing elit</u> magna aliqua </h4>

Lorem ipsum dolor sit amet, consectetur adipiscing elit magna aliqua

Worley effect - variant 1 CSS: .justify-center-test { text-align: center; } .worley-v1 { --data-highlight-color: red; --data-shadow-color: slategray; --data-dark-highlight-color: red; --data-dark-shadow-color: lightslategray; --data-shadow-offset-x: 0.05; --data-shadow-offset-y: 0.05; --data-shadow-blur: 0.03; --data-noise-scale: 40; --data-noise-sum-function: none; } HTML: <h4 id="header-test-5" class="demo-header header-font-sans justify-center-test worley-header worley-v1" contenteditable="plaintext-only" > Lorem ipsum dolor <i>sit amet</i>, consectetur <u>adipiscing elit</u> magna aliqua </h4>

Scrawl-canvas Phrase entity text can be justified within the Phrase's width; these text snippets will pick up and apply the header block text-align property.

Lorem ipsum dolor sit amet, consectetur adipiscing elit magna aliqua

Worley effect - variant 2 CSS: .header-font-bungee { font-family: Bungee; --data-y-offset: 0.09; --data-lineheight-adjuster: 0.86; --data-underline-position: 0.79; --data-underline-width: 0.08; } .justify-right-test { text-align: right; } .worley-v2 { --data-base-color: white; --data-dark-base-color: white; --data-highlight-color: #0760f7; --data-dark-highlight-color: #74c0f2; --data-noise-sum-function: none; --data-noise-output: YminusX; --data-noise-scale: 45; --data-contrast-color: darkred; --data-dark-contrast-color: pink; } HTML: <h4 id="header-test-6" class="demo-header header-font-bungee justify-right-test worley-header worley-v2" contenteditable="plaintext-only" > Lorem ipsum dolor <i>sit amet</i>, consectetur <u>adipiscing elit</u> magna aliqua </h4>

Lorem ipsum dolor sit amet, consectetur adipiscing elit magna aliqua

animated-highlight-gradient-text-snippet

A simple gradient effect using two colors, spaced along the gradient to make a series of bars. The gradient animates downwards in a repeating pattern.

The snippet can be customised using the following data- attributes applied using CSS variables, or directly to the HTML header element:

... And for prefers-color-scheme: dark users:

This snippet reacts to the user preference prefers-contrast: more with the following data- attributes:

Animated highlight gradient effect - default (animated) CSS: .letter-space-px-test { letter-spacing: 4px; } HTML: <h4 id="header-test-7" class="demo-header header-font-sans letter-space-px-test highlight-gradient-header" contenteditable="plaintext-only" data-is-animated="true" > Lorem ipsum dolor <i>sit amet</i>, consectetur <u>adipiscing elit</u> magna aliqua </h4>

Scrawl-canvas Phrase entitys include letter spacing functionality; these text snippets will use any CSS letter-spacing property value applied to the header element.

Lorem ipsum dolor sit amet, consectetur adipiscing elit magna aliqua

Animated highlight gradient effect - default with amendments CSS: .letter-space-em-test { letter-spacing: 0.2em; } HTML: <h4 id="header-test-8" class="demo-header header-font-serif letter-space-em-test highlight-gradient-header" contenteditable="plaintext-only" data-main-color="black" data-dark-main-color="#faf1d4" data-highlight-color="orange" data-dark-highlight-color="#e6a315" data-gradient-easing="easeInOut" data-is-animated="true" > Lorem ipsum dolor <i>sit amet</i>, consectetur <u>adipiscing elit</u> magna aliqua </h4>

Scrawl-canvas gradients support non-linear easings.

Lorem ipsum dolor sit amet, consectetur adipiscing elit magna aliqua

Animated highlight gradient effect - variant 1 CSS: .highlight-gradient-v1 { --data-main-color: lch(29.2345% 44.2 27); --data-dark-main-color: #5eadd1; --data-highlight-color: lab(52.2345% 40.1645 59.9971); --data-dark-highlight-color: #c5d6fc; --data-gradient-skew-x: -1; /* no space after the colon! */ --data-gradient-easing:easeOutIn; --data-is-animated: true; } HTML: <h4 id="header-test-9" class="demo-header header-font-bungee highlight-gradient-header highlight-gradient-v1" data-contrast-color="darkred" data-dark-contrast-color="pink" contenteditable="plaintext-only" > Lorem ipsum dolor <i>sit amet</i>, consectetur <u>adipiscing elit</u> magna aliqua </h4>

Scrawl-canvas supports the use of LAB and LCH color strings.

Lorem ipsum dolor sit amet, consectetur adipiscing elit magna aliqua

bubbles-text-snippet

An animation effect that shows bubbles appearing, rising and expanding inside the text.

The snippet can be customised using the following data- attributes applied using CSS variables, or directly to the HTML header element:

... And for prefers-color-scheme: dark users:

This snippet reacts to the user preference prefers-contrast: more with the following data- attributes:

Bubbles text effect - default values CSS: .header-font-carter-one { font-family: 'Carter One'; --data-y-offset: 0.17; --data-lineheight-adjuster: 0.73; --data-underline-position: 0.57; --data-underline-width: 0.08; --data-no-underline-glyphs:gjpqy; } HTML: <h4 id="header-test-10" class="demo-header header-font-carter-one no-bold bubbles-text-header" contenteditable="plaintext-only" data-is-animated="true" > Lorem ipsum <b>dolor</b> <i>sit amet</i>, consectetur <u>adipiscing elit</u> magna aliqua </h4>

Lorem ipsum dolor sit amet, consectetur adipiscing elit magna aliqua

Bubbles text effect - variant 1 CSS: .bubbles-text-v1 { --data-text-color: white; --data-outline-color: black; --data-bubble-color: green; --data-bubble-outline-color: gold; --data-dark-text-color: black; --data-dark-outline-color: white; --data-dark-bubble-color: lightgreen; --data-dark-bubble-outline-color: gold; --data-bubble-density: 100; --data-contrast-color: darkred; --data-dark-contrast-color: pink; --data-is-animated: true; } HTML: <h4 id="header-test-11" class="demo-header header-font-carter-one no-bold bubbles-text-header bubbles-text-v1" contenteditable="plaintext-only" > Lorem ipsum <b>dolor</b> <i>sit amet</i>, consectetur <u>adipiscing elit</u> magna aliqua </h4>

Lorem ipsum dolor sit amet, consectetur adipiscing elit magna aliqua

swirling-stripes-text-snippet

A striped 2-color gradient effect. Animation occurs when the user hovers their browser cursor over the header, which leads to a swirl filter being applied to the text.

The snippet can be customised using the following data- attributes applied using CSS variables, or directly to the HTML header element:

... And for prefers-color-scheme: dark users:

This snippet makes no attempt to react to the prefers-contrast user preference.

Swirling stripes effect - default (animated) HTML: <h4 id="header-test-12" class="demo-header header-font-sans swirling-stripes-header" contenteditable="plaintext-only" data-is-animated="true" > Lorem ipsum dolor <i>sit amet</i>, consectetur <u>adipiscing elit</u> magna aliqua </h4>

Lorem ipsum dolor sit amet, consectetur adipiscing elit magna aliqua

Applying a Scrawl-canvas snippet to HTML header elements

These header text colorizer and animation effects have been designed so they can be applied to any font (left-to-right, alphabetic) - including cloud-based fonts - at any given font size. However, every font is its own thing and the metadata included in a font can be, at times, less than helpful. The practical outcome of font-uniqueness is that we have to finesse canvas font placement so that it can match up with the HTML-rendered text as closely as possible. We can do this using a set of data- attributes applied using CSS variables, or directly to the HTML header element:

HTML elements

HTML and/or CSS font-related data- attributes/variables

Using snippets: We apply Scrawl-canvas snippets to HTML elements using Javascript:

JS: import * as scrawl from 'path/to/scrawl-canvas/library'; import myFontEffect from './path/to/required-SC-header-snippet.js'; const headers = document.querySelectorAll('.arbitrary-name'); headers.forEach(el => myFontEffect(el, scrawl));

Testing the responsiveness of the snippets: all the examples have been set up with media queries to change font size in line with browser's viewport width.

Test purpose

Note: only tested on Latin-based (alphabetical left-to-right) fonts.

Known issue 1: Resizing the browser dimensions does not have an immediate effect on each canvas's display, which only triggers when the canvas enters the viewport - leads to an unfortunate repainting and content shift.

ACTION: needs to be fixed ... but:

Known issue 2: Setting the contenteditable attribute on a DOM element makes the element editable, but leads to side effects:

ACTION: will not fix - we are not building a text editor here.

Known issue 3: Page refresh rates are significantly slower on retina-like screens. ACTION: will not fix - probably not fixable.

Known issue 4: Firefox ...

ACTION: will not fix - Firefox is Firefox.

Known issue 5: Safari ...

ACTION: will not fix - Safari is ...!

Touch test: should work as expected

Annotated code