Design system contract for AI tools extending or modifying Marginalia.
Typographic callout library. 15 components, CSS custom properties, zero dependencies. Extracted from Inside the Math and Scrutinizer.
- All CSS classes use
mg-prefix. No exceptions. - JS attaches to
window.Marginalia.
- CSS custom properties (
--mg-*) are the theming API. Never hardcode colors. - Light theme via
[data-mg-theme="light"]or@media (prefers-color-scheme: light). - New color tokens go in the
:rootblock alongside existing ones.
- Every component must be fully functional with CSS only. JS enhances (animations, copy buttons).
marginalia.jsis optional. If it's not loaded, everything still works.
- 3D transforms (pull quotes) removed at
max-width: 720px. - All components must be readable on 320px viewports.
- Add new semantic variants via
data-typeattributes, not new class names.- Good:
<div class="mg-callout" data-type="danger"> - Bad:
<div class="mg-callout-danger">
- Good:
- Left border (3px) is the universal callout indicator.
- Rounded right corners (
border-radius: 0 var(--mg-radius) var(--mg-radius) 0) on bordered elements. - Font stack inherits from host page. Library only sets
font-familyon monospace elements via--mg-font-mono. - The 3D perspective pull quote is the signature component. Preserve:
perspective(600px) rotateY(14deg) scale(0.92)andshape-outsidepolygon. - Perspective text alignment rule: text aligns toward the border accent. If the element has
border-left, usetext-align: left; ifborder-right, usetext-align: right. The border is the visual anchor. Applies to pull quotes, margin notes, and any future perspective components.
- No build step. Ship raw CSS and JS.
- No dependencies.
- JS uses
'use strict'and works in all browsers supporting<details>andnavigator.clipboard. - Keep
marginalia.cssunder 700 lines andmarginalia.jsunder 200 lines.
- Add CSS in
marginalia.cssunder a labeled section comment. - If JS enhancement needed, add in
marginalia.jsand call frominit(). - Add demo in
index.htmlunder a new<section class="demo-section">. - Update README component count and usage examples.
marginalia.css Core styles + custom properties
marginalia.js Optional: collapse animation, code copy, gallery lightbox
marginalia-md.js Optional: markdown subset → Marginalia HTML converter
llm.md LLM system prompt cheat sheet (markdown patterns reference)
index.html Live demo (GitHub Pages)
screenshots/ README visuals
pandoc/ Lua filter + HTML template + Constitution example
Things tried and abandoned, so they don't get reinvented.
.mg-center-wrap— dual-float centered callout. Removed 2026-04. Tried to float a callout in the center of body text with text wrapping on both sides (magazine spread), using::beforefloat left +.mg-center-rfloat right + matchedshape-outsidecutouts +position: absolutecallout. Required a--mg-center-hper instance to sync heights, fell apart when the callout didn't match float height, needed a totally different mobile fallback, and stacked fragile CSS features (shape-outside + absolute + transform) with undefined interactions. If someone needs this again: use CSS multi-column withcolumn-span: all, or accept a full-bleed horizontal break (flatmg-pull), or just usemg-marginfor sidenotes. Lesson: layout tricks that need per-instance hand-tuning don't belong in a zero-config library.