# js-batch-dom-css

js-batch-dom-css — a Claude rule that keeps the agent from writing styles one property at a time and pushes it toward a class or a single cssText string.

- rule · `type=rule` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline · ★ 1064 repo stars
- Author: jarrodwatts
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/jarrodwatts/claude-code-config/tree/HEAD/skills/vercel-react-best-practices/rules/js-batch-dom-css.md
- Updated: 2026-01-21
- Security check: automated, 2026-11-16 (text) — no signs of malicious code found.
- HTML: https://affpapa.org/en/nevibecode/rules/jarrodwatts-js-batch-dom-css

## What it does

The rule lives in your project and shapes how the agent rewrites code that touches element styles. Four separate writes to `element.style` become one class, or one `style.cssText` assignment. Every lone write makes the browser redo layout; batching keeps it to a single pass.

Four cases are laid out: the slow version, the class version, the `cssText` version, and a React component where a `useEffect` that sets styles one by one is swapped for a `className` toggle. Classes get the nod over inline styles, since the browser caches them and the markup stays readable.

Impact is marked MEDIUM in the rule header, so treat this as cleanup rather than an emergency. It is about the browser DOM and layout recalculation. Bundle size is a different problem.

## Install

### Claude Code (native platform)

**Manually: put the files in place**
- File: `.claude/rules/js-batch-dom-css.md` — The paths frontmatter field limits the files

### Codex

**AGENTS.md**
- Codex reads AGENTS.md: paste the rule text there

### Cursor

**Manually: put the files in place**
- File: `.cursor/rules/js-batch-dom-css.mdc` — Frontmatter: description, globs, alwaysApply

### GitHub Copilot

**Manually: put the files in place**
- File: `.github/instructions/js-batch-dom-css.instructions.md` — The applyTo field sets which files it applies to

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/rules/js-batch-dom-css.md`

### Cline

**Manually: put the files in place**
- File: `.clinerules/js-batch-dom-css.md`

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/jarrodwatts/claude-code-config/tree/HEAD/skills/vercel-react-best-practices/rules/js-batch-dom-css.md

## When to use it
- rewrite a style update so layout is recalculated once
- swap a chain of `element.style` writes for one class
- apply several CSS properties in a single `cssText` string
- drop a style-writing `useEffect` from a React component
- explain in review why a class beats inline styles

## Example prompts
- Rewrite `updateElementStyles` to add the `highlighted-box` class instead of setting four `element.style` properties.
- In the `Box` component, stop writing styles in `useEffect` and toggle `className` instead.
- Check this file against the js-batch-dom-css rule and list where styles change one property at a time.

## Similar
- [inspecting-hermes-desktop-dom](https://affpapa.org/en/nevibecode/skills/inspecting-hermes-desktop-dom.md) — skill · 263 installs
- [expo-dom](https://affpapa.org/en/nevibecode/skills/expo-dom.md) — skill · 25700 installs
- [measuring-dom-nodes](https://affpapa.org/en/nevibecode/rules/measuring-dom-nodes.md) — rule · ★ 849 repo stars
- [js-performance-patterns](https://affpapa.org/en/nevibecode/skills/js-performance-patterns.md) — skill · 716 installs
- [pixijs-scene-dom-container](https://affpapa.org/en/nevibecode/skills/pixijs-scene-dom-container.md) — skill · 6900 installs
- [view-transitions](https://affpapa.org/en/nevibecode/skills/view-transitions.md) — skill · 707 installs

## Other versions with the same name
- [js-batch-dom-css · tech-leads-club](https://affpapa.org/en/nevibecode/rules/js-batch-dom-css.md) — ★ 7191 repo stars

From the same set: [jarrodwatts/claude-code-config](https://affpapa.org/en/nevibecode/by/jarrodwatts/claude-code-config.md) — 20 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
