DEV Community

Discussion on: If you could start over from scratch, how would CSS work?

Collapse
 
tomhodgins profile image
Tommy Hodgins

To be honest, I've tried to do this for years - if we could throw away everything about CSS and come up with something similar, I'd still end up with something pretty close to CSS. It may look ugly, but it's fit-for-purpose.

You can check out some of the other styling language ideas from a time before CSS

When you compare some of the other ideas out there there are good feature ideas, but the syntax CSS has (which itself is based on X resources for unix programs) is simple, expressive, and flexible.

What I'm excited about now is that even if we want to invent a totally new styling language, we can use valid CSS + valid JavaScript to do it! CSS has "custom properties" (aka CSS variables) that allow us to define custom properties and set values for those properties anywhere in CSS, HTML, or via JavaScript. This is incredibly powerful.

There are also ways you can write CSS rules with custom selectors that get powered by JavaScript functions, as well as custom at-rules that get powered by JavaScript functions as well - so at every level (value, property, selector, stylesheet) you can customize valid CSS and extend it with small amounts of JavaScript logic to help it apply styles in situations, and to elements CSS alone can't quite reach.

The future of styling beyond CSS still looks like writing CSS, it's just designing and using a more declarative, higher-level styling language expressed in valid CSS syntax that is also powered by JavaScript functionality in addition to what CSS can do by itself.

twitter.com/innovati/status/108197...