FAQ

Why did you do this?

It started as an attempt to relearn modern CSS for myself so I can teach others. As I did this I realized that most of the things I learned have been completely replaced with flexbox and grids, and if I just use those then CSS becomes much easier to understand. Specificity works as expected. When I change a component with class or id it actually changes. The layout flows correctly and is easier to create. Nearly everything works better and is easier to understand.

This website became a demonstration to others that layout doesn't need div.class structure, subverting ul/li tags, and other CSS hacks. You can use simple truly semantic HTML and simple CSS to accomplish 90% of what you're doing today with more reliable results faster.

Why is this site in black and white?

I used an entirely monochrome simplified design because I'm not a designer, and I want people to focus on the visual structure of each demo, not whether my use of Cornflower Blue was appropriate for a button.

I'm also an experienced oil painter and a fundamental teaching in realist art is that color does not matter for visual comprehension. What matters most is the "drawing", or monochrome aspects of visual experience. If you can't make something work in monochrome then no amount of color will help. Make it visually understandable in monochrome and any color scheme you choose should work (barring a few rules about color perception's relationship to monochrome values).

What's wrong with classes?

There's nothing wrong with classes in CSS. How they're used in recent CSS frameworks subverts the normal specificity rules making CSS unnecessarily difficult. The original specificity rules put the base design of a component at the tag level, then a class can be used to modify and extend the design, and an id can make this even more specific. In today's use of div.class heavy markup you lose this ability to alter the design as needed where its used, and instead you have to resort to !important and specificity hacking to change how something looks, or add more div with more class.

The other problem with div.class is it's more difficult to debug problems with the layout. There's the obvious problem of debugging failures in layout through a forest of divs, but you're also relying on specificity that can come from anywhere in the cascade. It's much more difficult to find exactly what bit of CSS is overriding your local decisions. If you've ever had to open the inspector in your browser to troll through CSS locations looking for the culprit then that's why. If the base design decisions are at the tag level, then your local class and id specifics will work as expected. You can also replace many uses of class as design modifiers with scoped CSS variables and reduce the use of div.class even further.

Finally, using div.class heavy layout systems pollutes your markup with structure that's difficult to analyze and maintain. When you focus on using truly semantic named tags and follow specificity as intended then your HTML is lighter and easier to understand because it isn't full of div.grid.col-1.col-mx-auto class rules that really have nothing to do with the actual meaning of that particular visual element. With flexbox and CSS grids you don't need any layout divs, and can keep the HTML clean and semantic. This also ends up being more flexible with less or the same effort as using a pre-made grid system full of divs.

Should we ban div.class?

Hell no. The current problem of too much class based CSS is because of trends in recent years calling for everyone to irrationally ban some practice. Remember when everyone decided tables were evil? So then we banned tables and grids completely? Then nobody could do a layout without crazy tricks and JavaScript? Nobody wants a repeat of the anti-tables "semantic markup" war, so please don't ban div.class.

All this website does is demonstrate that you don't need so much div.class. You can scrap a lot of what you're using now to do layout and go with clean HTML with flatter structure, then judiciously use div.class as needed. Treat div.class like salt. Right now you're pouring a whole box of it on your HTML when a little bit makes it taste better.

Do these demos work on phones?

I haven't done the work needed to adapt this to phones yet. That may come in a later release. Try it anyway as you may be surprised how well the layouts still work on smaller screens.

Can I suggest a challenge?

Yes please. If you find an example of a layout that you think is impossible with flexbox and CSS grids then tell me on Twitter at @lzsthw and I'll attempt a replica. My only requirement is that you also have to tell me what trick the challenge is using. This is an exercise in replicating layouts, not reverse engineering devious hidden CSS tricks. Also keep in mind that I am not invested in "winning" and only curious about the limits of flexbox and CSS grids. If you find something I can't do, that means I found a useful limit to avoid. It doesn't mean that we throw out all of flexbox and CSS grids so you can go back to the float-clear-div-class 1990s.

How did you make this site?

It's actually all hand coded HTML, CSS, and JavaScript, with the only technology being Svelte to make things easier. You could do all of this without Svelte and it wouldn't be much harder. Svelte is why if you do "view source" it's a mostly empty HTML page that just loads some JavaScript, and if you inspect the results it's full of svelte- classes. If you want to see the real HTML then each demo has the source given.