Style beautiful web pages without writing any CSS. Using W3.CSS.

Corina Pip on December 08, 2018

Recently i was looking for a way to create some web pages to use in my upcoming technical workshops as demo pages. I did not want to spend too mu... [Read Full]
markdown guide
 

Hi Corina,

Atomic CSS was very "hip" some time ago, and I feel that today, when we build applications using incapsulated components, there isn't really a place for "atomisation". We have common styles and configuration, like fonts etc., but every component lives for itself.

Plus, to be quite frank, the syntax is horrible. Using ten classes to style an element that may appear a couple of times is a terrible redundancy and will hurt the document size, its parsing and further maintenance.

 

"but every component lives for itself"
Please dont' forget that just because many people decide to do "one thing" it doesn't mean it's the ultimate truth. People thought Earth was flat, smoking was good, cocaine was a good medicine etc.
Repeating CSS in every component just because "some folks at Facebook" said it's good for you isn't really a technically convincing argument.
Sure, component based architecture is all fine, but repeating a bunch of CSS properties to every component's scoped CSS will eventually add CSS size, impact performance, and make redesigns harder.
"the syntax is horrible" => subjective opinion.
Redundancy is not repeating classes, because classes ARE MEANT TO BE REPEATED.
Parsing is not impacted. Document size doesn't matter - it's cached anyway.

Please speak with solid arguments and not just personal preference. This type of engineers is what's most annoying in the job.

 

Hello George,

First off, this is a personal comment on a personal blog posting. It's meant to be subjective and I feel that I have justified my reasoning. This is no scientific debate that needs ten references for every sentence :)

I don't say that components are "the ultimate truth", but using such architecture for a long time (way before I started to use React or even Angular JS) has proven very performant. The key here is composition. If you compose your larger components (or, containers) with some smaller ones, you won't repeat your CSS. I don't think this is the place to discuss pros and cons of componetisation, given the fact that the article is about atomic CSS.

Plus, I still believe that using w3-btn w3-border w3-teal w3-margin w3-padding-large w3-left w3-large w3-opacity to style a simple button, an element that will be repeated multiple times, is redundancy. it will impact your document size and, even cached, it will have to be sent to the client.

Last, but not least, I don't believe that every decision needs only "technically convincing arguments". Sure, it's great to have those and take them under consideration. But if we would decide solely based on technicalities, we would all write using C or even low-level languages.

Now, please don't assume that I am against atomic architecture. I am not. If this suits one's needs – this is great.

We're engineers and our decisions should be based on engineering, not on number of blog posts / hype driven development.

Also I would like to point out words used in your original comment:
"atomic CSS was hip some time ago"
"the syntax is horrible"

you know what's horrible?

.header--login__buton { 
   display: block;
   padding: 10px 0;
}

.footer--menu__button {
   display: block;
   padding: 10px 0;
}

compare this with

<header>
  <a href="/whatever" class="block-button padding-s">button</a>
<header>
<footer>
  <a href="/whatever" class="block-button padding-s">button</a>
</footer>

George, this is misunderstanding of BEM principles. Your code should look like this:

.link {
  display: block;
  padding: 10px 0;
}

...

.header__link {
  color: red;
}

---

<header class="header__container">
...
  <li><a href="#" class="link header__link">Hi</a></li>
...
<footer class="footer__container">
...
  <li><a href="#" class="link">Bye</a></li>

Plus, BEM syntax also isn't the prettiest one :)

George, please don't exaggerate. Yes, our decisions should be based on knowledge, metrics, etc., but also on ease of development, entry and complexity levels, adoption etc. Those factors are extremely important. I know people that would even put those higher than sheer performance, simply because, when your code is really good, differences are a lot less significant than, for example, people quitting after three months because of the tech.

Atomic CSS is easier to use than juggling between nested selectors and having to write CSS classes like:
main__header--nav-home.
I think we analyzed enough. This is a technology blog and we should speak like professionals, not like fanboys

 

The dream of the semantic web is over, isn't it?
By which I mean, this is a mix of style and content which means that if you want to re-theme your website you'll have to change all the HTML :(

 

Indeed. I understand why some people choose this approach, but it defeats the purpose of classes. I want to define a class of objects which share attributes because those objects represent the same thing on the page (e.g., headings). Using, e.g., "w3-teal" on those headings is essentially just moving my CSS into my HTML, and making it more cumbersome to change that one color in the future. I'd rather just define my "heading" class with whatever shade of teal I want, then change that one color in one place in the future.

Again, I get why some people use libraries like this, but I've noticed a move toward this approach even when it creates more problems than it solves (it doesn't make sense for most enterprise web apps). And the unfortunate reality is that some developers just don't want to spend time understanding CSS to the degree that they do JavaScript.

 

I think tailwindcss is a nice middle-ground - you can use the pure 'utility' approach like :

<div class="shadow bg-primary px-4 py-8">Nav here</div>

But you can also 'compose' classes out of the utilities in your css/sass by doing :

.nav {
  @apply shadow bg-primary px-4 py-8;
}
...
<div class="nav">Nav here</div>

I've found it works quite well - those one-off things can keep their one-off utlities, but as you find common/re-used blocks and components you can style them as one thing.

 

That makes more sense to me because it's still keeping the presentation stuff in the presentation box.

 

Using classes like that isn't technically against the principals of semantic web design. Bulma has a very similar class syntax, but makes a point to not style any HTML elements directly and encourages using things besides <div>s when appropriate. I can't speak for W3.CSS, but there are serious benefits to designing classes in this way.

 

Class attributes aren't semantic content, so nothing wrong with this approach really. The problem with inline styles is that they're too limited: you can't constrain by media queries or other pseudo elements or pseudo classes. Atomic CSS can handle that, and it does so in a way that's much easier to use than fiddling with CSS manually. I recommend checking out the tachyons CSS toolkit.

 

That's true. They also offer something in regards to themes, but i haven't tried it: w3schools.com/w3css/w3css_color_th.... I think it all depends on the purpose of the development and what kind of pages you are creating. This is a quick win in many situations.

 

Why would your content be in your markup files? :O
It should be in the API/DB/CMS.

 

You know there are static websites, right?

And I don't even mean generated static sites. I literally mean sites that don't need an API/DB/CMS because they are pure content and easy to manage in HTML?

Oh, say, for instance most sites hosted on GitHub Pages.

Resume sites. Portfolio sites. Restaurant sites. I can go on and on.

You don't need to over-engineer a 6 page restaurant site that hosts directions, menu, and simple things like that.

Don't overlook those pages -- they're still important and a big chunk of what the web is made of.

I find that unsustainable even for tiny restaurant sites.
For example, you likely have your contact info in the contact page and the footer of every page.
Assuming you at least keep your footers separate, that's still two places to change your phone number, working hours, etc.

And this isn't a root comment, this is a response to the person woeing over having to redo their markup for a restyle.

Well, guess what? CSS Garden doesn't work on real-life markup, only on intentionally superfluous one.

 

The dream of semantic web is far from over; it's on the rise with an evergreen HTML spec and always-up-to-date browsers. More and more "web designers" are finally realizing that if they don't drop their divs and start using semantic standard components, they'll never be able to cover all the devices which will change too rapidly.

Of course, you can always choose to ignore all that and use a ridiculous syntax like w3-padding-large, but then again, nobody can stop you from smashing your head against the screen either, right?

 

I see you are totally missing the point of this article. I stated in the initial part how i came to use it, and what was the purpose for it. I had a specific requirement, and this is a solution to my requirement. Whereas you are free to express your dislike, and i'm sure you have better ways of doing things, please be respectful.

 
 

They don't deserve the hate they once did. It's a much better resource today than, say, 10 years ago.

 

Yeah, that's not really a feeling anymore. Look at the statement at top of W3Fools:

w3fools.com/

 

No, it’s still the most useless tool for developers. If you need an example, search for the css float property, and compare the result with MDN...

 

Yes. It’s one one of the most shitty resource for developers.

 
 

How is this any better than just using inline style attributes?

 

I am boycotting anything W3School.

The issue I have with W3School is how unfair they are with overloading the W3 symbol (it's reserved by w3.org, where Sir. Tim Berners-Lee and colleagues writes Specifications for the web).

So, w3css is like what Microsoft does with "SQL", when they. SQL has a Specification, not written by Microsoft. Here, W3School isn't contributing to standards. And aren't fair-play with the W3 name.

w3fools.com/

 

Hi Corina,
for quick and decent design i've also found w3.css a very lightweight, easy to learn & implement solution.
Now busy with Vue.js i am using bulma.io which has a similar simplicity/elegance out-of-the-box.

 

Might not matter much to you since you're using a CSS framework, but I wanna mention how awesome Vue Loader's "scoped" attribute is -- it removes the challenges of globally scoped CSS without requiring you to utilize actual web components with something like Polymer. We have unscoped global styles for things like dropdowns, forms, etc. in our root component, and we just scope/customize other components as necessary. We used to practice BEM but just don't need to anymore.

 

So this is just another CSS Framework, of which there are plenty. In the past I couldn't trust W3 schools because there were a lot of errors in their examples / documentation but they've really improved over the years.

That said, I don't know how new W3.css is but I'd stick with Bootstrap or Bulma over this as they are more tried and true / popularity in this case means trust.

 

Shouldn't a professional be able to use the right tool for the right job? Why is everyone judging this hammer for not being able to drive a screw? I'm definitely not going to over-tool a landing page and contact form with a huge CSS framework.

 

As someone who just wrote a quick project that produced a simple HTML page with no styling (I'm a backend guy, so CSS has always been a struggle for me), this is a nice intro that comes at a timely moment for me. Thanks for sharing!

 

So instead of learning some CSS, which is an accepted standard, you're going to learn this, which is a random array of string leveraging the class attribute which is not supposed to be used for styles at all?

w3-btn w3-border w3-teal w3-margin w3-padding-large w3-left w3-large w3-opacity
 

While I agree with you that W3 css isn’t necessarily a great choice, the popularity of atomic css is on the rise, and with good reason. Also, styles on classes is 100% how CSS is intended.

 

No. From the WHATWG HTML spec, § 3.2.6 (emphasis mine):

There are no additional restrictions on the tokens authors can use in the class attribute, but authors are encouraged to use values that describe the nature of the content, rather than values that describe the desired presentation of the content.

It doesn't any sense for HTML, which is all about document semantics, to announce that an element is of type "padding-small". Use a class name to categorize an element such as "important-item", "feed-item", etc.

The article claims that you're not writing any CSS. Why in the world would you do class="padding-small" when you can do style="padding: var(--small)", which precisely describes what you want, and is a standardizes way of doing things?

Everyone goes bananas over inline styles, repeating a mantra they've read somewhere about how "it's bad practice", "anti-pattern", and then they splash a class="margin-top-medium". Totally not inlining styles. Nope, not at all.

I encourage you to give this article a read and share your thoughts. I understand the ideology behind separation of concerns, but look at react and vue. Maybe it’s time we challenge this idea as well.

mrmrs.io/writing/2016/03/24/scalab...

I never said anything about separation of concerns, not did I say that you shouldn't inline styles or that it's a bad thing to do.

There's nothing wrong with inlining styles.

But there's everything wrong with pretending you're not inlining styles when you add a class named padding-small which adds the style { padding: var(--small) }.

This article perfectly describes why it is very different from inline styles.

frontstuff.io/in-defense-of-utilit...

Please, while I know you disagree with others, be civil and open to new ideas and other viewpoints. It makes this community a better place for everybody!

Wow, that article has literally no left margin.
I wonder what the author meant by that.
Probably that the curtains were blue.

Luckily it's an easy markup change that can be done in seconds, without fear of breaking another page that reuses the same semantic class names!

Yup, luckily he has no idea that changing styles means changing styles, and not changing markup. Ignorance is a bliss indeed!

It really makes me sad to see so much negativity and superiority complex in a place that's made to encourage deep thought, differing opinions, and progress for developers.

 

Atomic CSS isn't a new thing. He's been around for several years and was born before all the new methodologies, and it's a bit obsolete in 2018 since CSS evolved and let us writing more maintainable CSS.

I tell you a thing.. each article about "How to do a THING" you will find an article telling "Don't do this THING"

I can't send you many links about semantic css, against functional CSS (ACSS). Maybe you are interested reading this for a different point of view.

maintainablecss.com/
ecss.io
robdodson.me/css-semantics/

If your way works for you, and my way works for me, why argue that either is right or wrong?

I disagree that css has made atomic obsolete. I think it has allowed atomic to progress actually. Tailwind is a great example.

There is no one way to do everything. I prefer atomic, you prefer semantic. Each are perfectly acceptable when implemented correctly.

For me personally, I very much enjoy being able to quickly understand how my markup will look just by glancing at my class definitions.

Naming classes based on content seems odd to me, as I feel that the new HTML5 semantic elements do that already.

To each their own. Good luck in your future projects!

I never said what is wrong or not. I wrote acss years ago and i just suggested you to see this thing from a different point of view...

Touché. I read your comment in a negative tone, which is definitely on me. Thanks for your insight and point of view. I will definitely give these a read.

Please feel free to drop me a pm or tweet about your conclusions

 

"leveraging the class attribute which is not supposed to be used for styles at all?"
Classes are not meant for styles?
Srsly?

 

Yes, "srsly". Go ahead and click the link if you want to see the source.

which link are you referring to? Listen, this:

So instead of learning some CSS, which is an accepted standard, you're going to learn this.

Is not a technically convincing argument - and it won't work to any future colleague.

Facebook is doing it. (check screenshot) Do they not know how to write CSS?
I think someone needs several years of hands on professional experience in big projects. Working and having a product owner/manager/boss who wants you to deliver is not the same as writing a thesis about semantic web for uni.
I learned CSS on a very good level and then decided to follow this pattern because I saw its' power and productivity. This technique has a big following of very VERY senior developers.

thepracticaldev.s3.amazonaws.com/i...

 

Tailwind CSS (tailwindcss.com) is a great alternative to this with many configuration and integration options, third-party plugins, and an established community.

 

Wow! That looks really neat. Hopefully, this will clear up the clutter and motivate everyone to get on common ground. 🤗

 

I developed production-size websites and SPAs using functional CSS ( custom-made framework after years of writing CSS, following the logic of tachyons.io/ , and still adhering to principles of cssguidelin.es/ ) and the speed of dev/productivity but also Visual Consistency I was able to achieve with this system was unheard of. (before even Component based architecture was a thing)
The principles behind it?
-> Don't fight with CSS rules - write less of them
-> Semantic Classes are overrated and offer no real-world technical or business advantages (check Facebook's source code)
-> using functional/atomic CSS you can compose "visual components" (even when not using React or Vue) which are repeatable - maintainable - easily redesignable
-> seeing a design you can quickly abstract all the visually repeatable elements, code your base classes, use SASS variables, and have a first draft of your website literally in no time.
Sorry to generalise, but there was a mass influx of ex-backend devs when React et co became a cool thing, and many of them don't really know their shit when it comes to CSS. They just use CSS scoped CSS, repeat everything and think they're doing a cool job serving megabytes of code.

 

Welcome to the “Learning libraries instead of technologies” era.

 

Would it not be better just to use Bootstrap rather than use the W3C? Is there any extra feature that it has that Bootstrap does not?

 
 

Probably better off with a more mature toolkit that's been around awhile: tachyons.io

 

Are you serious now?
Thats for learning css as a standard.
Not for developing!

Try Bootstrap! Or other CSS frameworks

 

Hmm... Interested in how this framework compares with Bulma

 
 

Don't make that blanket statement. It solved a problem for the author, and Corina is a developer, so your statement is false.

 

This is brilliant ! I love w3schools and it's amazing they built their own CSS framework !!

 

You do this for either a living or a serious hobby and basic CSS is too much?

I feel these frameworks are a jump to far too often.

 

The funny thing with these "you don't have to learn CSS" frameworks is how you still use CSS keywords and general logic all over the place -- change class to style and you're basically getting a valid CSS string, with some minor punctuation changes.

class="w3-padding-large"
stye="padding: var(--large)"

Much improve, such differ.

 
[deleted]
 

We’re removing these comments because they are in violation of the Code of Conduct. If you have questions, please email yo@dev.to.

 

This comment doesn't meet the dev.to community guidelines. Please reconsider the way you express yourself around here.

 
[deleted]

Sure there is.

Your comment is not welcoming. It is not respectful. It does not show empathy for your fellow Dev.to users.

So, it does not meet guidelines.

dev.to/code-of-conduct

As a thought exercise I encourage you to rethink what you posted and how you can be constructive while giving the same feedback. What words could you change?

 
Sloan, the sloth mascot Comment marked as low quality/non-constructive by the community View code of conduct

Looks totally awful and unusable in real projects. At max one can use it for some simple landing page. For a little advanced styles and markup it would be a hell editing CSS that way. Moreover, it's violating all rules and approaches that we stated to make web beautiful. No semantic HTML, no BEM classes, just inline CSS basically. Why would you even choose it instead inline CSS if it's basically same thing?

This approach has absolutely 0 use case.

code of conduct - report abuse