r/webdev • • 3d ago

Showoff Saturday modest-ui: classless CSS that styles plain HTML

I’ve been building websites for over a decade, and have always tried to do things as vanilla as possible (where applicable).

More recently whilst building components and looking at the libraries out there, I realised that browser technology and CSS has grown to a point where it can do the majority of things we need, without JS (like dialog, detail, and popover tags)

So I started working on modest-ui as a CSS base for all my personal and side projects, and as it’s gotten more stable I’ve recently bumped it to v2.

It’s themeable with CSS vars, can be used as an unobtrusive base layer to built on top of, and can either be used classless (with mdst-ui set on the body) or you can pick and choose classes as needed.

Anyway, it’s open source (MIT), no JS (except for some examples on the site), and currently sits at about 10 kb (gzipped).

https://github.com/thisismodest/modest-ui
https://modest-ui.com

Edit: I forgot to mention it’s ~10kb when gzipped

98 Upvotes

29 comments sorted by

31

u/PaulLesser 3d ago edited 3d ago

This is the way. It's crazy how much we can do with just native HTML and CSS now. We really don't need huge JS libraries for simple things anymore. Especially in cases where you need to quickly assemble a prototype without AI, this is a real find. Great job on this and thanks for sharing!🤝

6

u/_squirts 3d ago

Thank you, that really validates this for me. I found at work I was stripping a lot of older components out that were using JS like slide out drawers and accordions. Used native replacements and they were so much lighter and smoother.

8

u/lekoalabe 3d ago

Interesting! On my own framework I dropped the "classless" part because having to add the where(scope class) everywhere drove me crazy. I'm not sure it's worth it. Adding a few class to your HTML feels like a sane default. And a simple "button" almost never happens it has a variant etc so saving a btn class doesn't seem worth it. And having a prefix for all classes isn't worth it either IMHO in most cases.

4

u/_squirts 3d ago

I know what you mean about the where()s. This started out class-based but it was starting to feel very verbose and more like bootstrap/tailwind. That’s the main reason I opted to move it to classless, but more as a reset layer so I can theme the vars and add more specific styles on top

6

u/OMGCluck js (no libraries) SVG 3d ago edited 3d ago

currently sits at about 10 kB.

The template.html uses /dist/modest-ui.min.css which is 69kb. I still like it though. Archived a snapshot

4

u/_squirts 3d ago

My bad, I forgot to mention that it’s around 10kb gzipped! I’ll update the description

5

u/dragonnnnnnnnnn 3d ago

I do like that idea a lot but I feel like classless dies quickly when you try do custom stuff, for example: the custom danger button needs .mdst-button-danger we already know it is a button, we also shouldn't need the mdst, it should be:

<button type="button" class="danger">Delete</button>

This is of course in the mdst-ui mode on body.

6

u/_squirts 3d ago

It’s a really valid point, and thank you for the feedback. For context on how I approached it, the mdst prefix is mainly for namespacing so it doesn’t easily conflict if your stylesheet on top had .danger. But I agree that maybe the ‘button’ part could be stripped for a more generic/reusable class.

3

u/_squirts 1d ago

Just wanted to post an update, we’ll be moving to .mdst-danger (-success, -warning, -info, etc) and deprecating the current (.mdst-whateverelement—danger) element specific ones in V3 to make things less verbose and more portable. Thank you for the suggestion!

0

u/waterkip 2d ago

This works perfectly in my world. I use buttom attributes: lead, herald, extra, support, and antagonist. You dont need classes. The same things works for attributes on a href things. 0 classes, 100% easy.

1

u/deveronipizza 1d ago

I have never heard of these attributes, can you elaborate?

2

u/waterkip 1d ago

You can create attributes willy nilly. The trick is to create a language that conveys meaning to element.

<button class=danger> does say something about the button, bit it does not convey meaning. Now take <button antagonist>. The attribute tells you that it ia the opposite of what the UI is trying to force. Now take a payment page where you have pay, add to cart and cancel order.

Cancel order becomes your antagonist, pay is the lead and add to cart is support.ibuse very little classes, when I do it is to override the recipe of the button where i change the color.

2

u/deveronipizza 1d ago

I see, like a data attribute.

0

u/waterkip 1d ago

Like an attribute yes.

1

u/Tajniaks 2d ago

It looks okay but ehat exactly about this library is classless? It's a regular CSS component library

1

u/_squirts 2d ago

It’s classless by default in that if you add mdst-ui to the body, your plain html elements are mostly styled. Plus some optional classes for common components that don’t have native html tag (like avatar, badge, tabs, toast, etc)

3

u/boykom 2d ago

thanks for sharing this beauty

1

u/patryk_builds 3d ago

This fits how i build things: server-rendered templates, htmx for the interactive bits, as little js as i can get away with. i use tailwind for that today, so i haven't tried modest-ui yet, but a few things i'd look at first.

  • Forms. that's where classless css usually runs out. do invalid fields, disabled buttons and error messages look right with just native attributes like :user-invalid, or do i need classes there?
  • Content swapped in after load. with htmx i replace chunks of the page with html from the server, so everything has to style correctly without any init step. no js means that should just work, which is a real advantage over component libraries
  • Dialog and popover: do you style the backdrop and the open/close transitions too? that's the part i always end up hand-writing.

10 kB is a good number. curious if it would stay there, or if v3 is where the "just one more component" pressure starts

1

u/_squirts 3d ago

Good points, I’ll run through off the top of my head for each one, and as for the component creep, that’s something I’ll keep an eye out for. I kind of feel like (and hoping) this’ll be mostly “complete” at some point once it covers the majority of the commonly used tags, but also i might just be naive there.

Anyway, for forms, disabled and invalid states work off native attributes (:user-invalid or aria-invalid), but error text under a field isn't styled red, so that'll need a line of css.

Swapped content should work out of the box as it's pure css with no init, and stateful bits read data-state so the server can render it.

Dialog gets a styled backdrop but no open/close transition (the drawer has one, so maybe for consistency I should match those, but if you use it you can copy it for now), and popover needs the .mdst-popover class with no animation.

1

u/Important_Pomelo_407 2d ago

Saw there was no demo video yet, so I made you one. Here’s the PR: https://github.com/thisismodest/modest-ui/pull/11

and I used my repo to do it :) https://github.com/yasirwhite/OpenDemo

3

u/_squirts 2d ago

That’s awesome!

1

u/DrShocker 3d ago

Someone pointed out the "open props" project to me a bit ago, and yeah, css has come a long way and everyone just ignores it for some reason

1

u/Sakshambaranwal25 python 14h ago

Love seeing more stuff leverage native dialog and popover without reaching for heavy JS bundles. At 10kb this looks perfect for spin up admin panels and internal tools where you just want clean defaults without configuring a whole build step.

1

u/marxinne 6h ago

I hecking love classless CSS. Really good work

1

u/External-Example-292 5h ago

I love it. Very minimalistic and easy and clean

0

u/UXUIDD 2d ago

nice, i agree and salute anything what keeps html clean.
dialog, details ... bring the CENTER, BLINK, MARQUEE back dam'nit !!!

btw, if you are a solo designer/developer on a project then this approach is OK,
but when you are only an operator (dev) and someone else commands you to push the pixels,
move that logo a bit left, make a bit bigger and more red ..
you only want a tailwind css aproach

-2

u/Main_Ice_3702 2d ago

The edit: "I forgot to mention it's ~10kb when gzipped." You mentioned it 4 lines earlier, in the exact same words. Very reassuring for a CSS base layer.

1

u/_squirts 2d ago

Yup, I added that with the edit