Menu

1 / 2
Reading 0:00
15s threshold

22 min read

CSS , Techniques , Web Design

Replacing JavaScript with a modern CSS feature can simplify a piece of code while making the wider application harder to reason about. Gabriel Shoyombo explores what happens when logic is split between CSS and JavaScript, sharing practical guidance to help you keep complexity in check during migration.

Have you ever replaced fifty lines of JavaScript with a few lines of CSS, merged the PR, and felt like you just did the codebase a favor? You replace ResizeObserver with a container query, the diff is mostly red, and everyone approves it before lunch.

This was what it looked like before you made the change:

See the Pen [demo (before PR) [forked]](https://codepen.io/smashingmag/pen/XJMxVJq) by Shoyombo Gabriel Ayomide .

See the Pen demo (before PR) [forked] by Shoyombo Gabriel Ayomide .

Then, a week later, a card on the dashboard has vanished. A heading has grown on tablets for no reason anyone can explain.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.