Instantly share code, notes, and snippets.


CSS is a declarative stylesheet language, this means you describe the result you want to see rather than the steps the browser would need to take to arrive at that result. You can write CSS selectors that target tags matching a certain description in a certain state, and then you declare the values that different styling properties should have at that time.

There are a few aspects of imperative programming living within CSS too. Animations that define sequences of keyframes, media queries, and feature queries are all examples of imperative programming features that are embedded inside the declarative language of CSS.

Custom properties (commonly called “CSS variables”) expand CSS to include the reactive programming paradigm as well. Any time a CSS variable is changed, the new values are updated live in your styles everywhere they have been used. So it's possible for CSS to declare a value that represents a stream of data.

Have you ever felt like CSS was too low-level to provide the abstractions for you to d

View css-unescape.js
new RegExp(
'\\\\', // a backslash
'(?!', // not followed by:
'[0-9a-fA-F]{1,6}', // - 1-6 hex characters,
'|\\n', // - or a newline
'|$', // - or the EOF
View on-screen-bookmarklet.js
javascript:const wrapper = document.createElement('aside'); const style = document.createElement('style'); const toggle = document.createElement('button'); const input = document.createElement('textarea'); const button = document.createElement('button'); const output = document.createElement('pre'); = 'jswrapper'; wrapper.className = 'open'; = 'jstoggle'; button.textContent = 'Evaluate'; style.textContent = ` #jswrapper, #jswrapper * { box-sizing: border-box; } #jswrapper { position: fixed; bottom: 0; right: 0; width: 100%; transform: translateY(0); transition: transform .2s; } { transform: translateY(100%); } #jswrapper #jstoggle { position: absolute; right: 0; top: -2em; height: 2em; width: 2em; } #jstoggle::before { content: '⬇'; } .open #jstoggle::before { content: '⬆'; } #jswrapper textarea, #jswrapper button, #jswrapper pre { display: block; width: 100%; margin: 0; padding: .5em; font-size: 14pt; } #jswrapper pre, #jswrapper textarea { background: white; height: 5em;
View parseCSS.js
function parseCSS(string) {
const iframe = document.createElement('iframe')
const style = iframe.contentDocument.createElement('style')
style.textContent = string
const stylesheet = iframe.contentDocument.styleSheets[0]
return stylesheet
View merry-cssmas-bundle.html
<script type=module>
import deqaf from ''
// [--parent]
// target an element's parent element
import parent from ''
// :has(selector)
// [--has='"selector"']
// like CSS's :has() selector
View index.js
const scraper = require('./scrape.js')
const models = require('./models.js')
const processModels = models => Promise.all( => processLinks(model, model.urls))
result => console.log(JSON.stringify(result))
const processLinks = (model, urls) => Promise.all(
View todoml-after.js
function todoml(string) {
return string
.reduce((html, line) => {
// prepare the line
line = line.trim()
// bold
View debugging.js
// add map, filter, reduce to NodeList
].forEach(method =>
NodeList.prototype[method] = Array.prototype[method]
View adding-event-listeners.js
// Option A
window.addEventListener('touchstart', strike)
window.addEventListener('mousedown', strike)
window.addEventListener('touchmove', slide)
window.addEventListener('mousemove', slide)
window.addEventListener('touchend', release)
window.addEventListener('mouseup', release)
View custom-tag-names.html