Skip to content

Snippets

Nuggets of useful CSS and JavaScript to bring into your projects as starting points. For brevity, JavaScript code illustrates the core idea without dealing with invalid arguments.

bareTag()
a tag function for template literals that works as if the template was untagged.
debug.css
CSS styles to point out problems with the HTML markup.
deepGet/Set()
get and set values of deep properties in an object.
downloadFile()
download a runtime-generated file with JavaScript.
encodeHTML*()
encode untrusted strings using HTML entities, for insertion in HTML contexts.
formDataMap()
get useful values out of form fields.
getDOMEvents()
get all events attached to a DOM element (Chromium-only).
highlight​Elements​Matching()
highlight DOM elements matching a function.
isCssContainingBlock()
returns whether a DOM element is a CSS containing block.
isCssStackingContext()
returns whether a DOM element (or pseudo-element) creates a new CSS stacking context.
isElementPokingOut()
returns whether a DOM element is causing a horizontal scrollbar due to its poking outside the viewport bounds.
lang()
returns an element’s language.
randomArrayIndex()
a better way to generate a random array index.
reset.css
better default styles.
similarityDS()
measure the similarity of two strings.
slugify()
turn a Latin string into an alphanumeric segment.
stringToUtf16()
convert a JavaScript string to an UTF-16 TypedArray.
wordsByFrequency()
count the number of occurrences of each word.
wordsUnique()
return the set of unique words.

Elsewhere