DEV Community

joon
joon

Posted on

I front-end and hate CSS. Here's how I deal with it

(Edit) - read the comments afterwards, I now strongly believe that this post is flawed thanks to the awesome community and I now find that there is more value in the comments than the post.

TLDR; use styled-components. If you suggest otherwise, read the post and fight me in the comments ✊

I'm a React front-end web developer with back-end origins(node, express, mongo). So naturally(for me), I dislike CSS. It doesn't feel intuitive(to me) and as someone who loves structuring databases and making queries efficiently, my passion for React hooks was a real pain since I needed to CSS in order to front-end properly.
As a result, I always required a so-called 'publisher'(not sure if such a position exists in other countries, but it exists in South Korea, basically an HTML/CSS specialist). But I was forced out of my 'no-CSS-zone' when I became the sole full-stack developer(part-time) for a startup because I forgot I don't CSS.

By the way, this method probably only works if the designer you work with supplies the design via Zeplin(which I expect to be most designers). If that's not the case, I'm afraid dark days are ahead of you my CSS-hating-comrade - I don't have answers.

So here's the gist - use Styled Components. Unless a large portion of your project's CSS is already set, I don't see an edge case when you shouldn't - and I'm not kidding. I thought about it for 3 days before I started working on my project(I wanted to CSS as less as physically possible) and tried using reactstrap+bootstrap at the beginning. Ditched everything and now I do everything with styled-components.

Here's why.

Why styled-components?

styled-component ex
This is a page I'm working on(yes some naming conventions have not been kept but I'll fix that in the future)

The next screenshot is one without styled-components(and also a project that was terrible in terms of DX(Developer eXperience))
NopeNopeNope

And I literally had to search for a snippet that didn't look terrible(yeah this is the decent one)

Before you ready your pitchforks - I agree with you, it's not the best code.
The point is readability, which influences DX, which ultimately leads to better UX(quoted from Tejas on his spectacular talk at React conf 2019)(because you spend more resources on meaningful coding)

I'm not a visual person and have difficulty picturing visual things in my mind. Yet as the person who wrote the code in the first screenshot, just scanning the names of the components I can literally visualize how it looks like.

Finding the component which I have to edit is so much easier and the code is myriads more straight forward.

The pros of using styled-components are listed on their website, so have a read and try to convince me to use something else in the comments. I'm still in my early stages if you succeed I am definitely willing to switch.

As for the part where I said you need Zeplin - it has all the CSS. Just flex all the components for responsiveness and set min-width. If you hate CSS enough to not have studied flexbox like me, finish this game and you'll be set to begin straight away(it did for me)

And that's how I deal with CSS. 😄
Thanks for reading, hope you get something out of this post.

Latest comments (76)

Collapse
 
gikdev profile image
Mohammad Mahdi Bahrami

But I like CSS! 😆

Collapse
 
louislow profile image
Louis Low

I never write CSS for any UI development. I use Vue.js or Krugurt.js with Yogurt.

I can create beautiful web component in a just few minutes with API callbacks, for example:

<card-post>
  <y class="m-4 p-2 bg-white rounded-lg shadow">
    <y class="{ props.titlesize } font-semibold text-charcoal-100">
      { props.title }
    </y>
    <y class="{ props.descsize } depth-snug truncate">
      { props.description }
    </y>
  </y>
</card-post>

And then mount the web component:

<card-post
  title="..."
  description="..."
  titlesize="text-lg"
  descsize="text-sm">
</card-post>

Absolutely zero CSS.

Collapse
 
fly profile image
joon

Had a quick scroll through the Yogurt link,
I honestly had difficulty in believing that you never had to write CSS,
until I saw the documentation myself.

Very interesting concept / paradigm.

Currently I'm contently using classnames with Sass. And also found out that scss can be quite enjoyable.
Might give yogurt a go though in the future.
Thanks you for the comment Loouis!

Collapse
 
louislow profile image
Louis Low • Edited

My portfolio website is also built with 100% no CSS. All 100% crafted with Yogurt. As for Yogurt, the next version 1.0.9 release is coming soon. Check that out at the Utility Map. Enjoy then.

Collapse
 
sevgit profile image
Sebastián Ventura

I wanted to chime in just to say you're taking feedback like a champ! Glad to see people that are brave enough to share a snippet and then be open minded to what others have to say about it. Cheers!

Collapse
 
fly profile image
joon

Greatly appreciated :)
I really want to show how my css has changed through the help of the community, but totally swamped at work atm.
Thanks for the chime in!

Collapse
 
mtrantalainen profile image
Mikko Rantalainen

In my experience, Zeplin is pretty poor as far as it comes to CSS. Modern UIs should be designed relative to font size the user has selected for his or her browser and as a result, your front end should be sized using raw em and rem everywhere. Zeplin doesn't support that as far as I know.

Try to create semantic markup first and use CSS (and maybe JS) to tweak the UI if really needed. Once you understand CSS well (and hopefully don't need to support MSIE or older Safari releases) it seems pretty clear that the V in MVC is CSS in web development.

Yeah, CSS is pretty huge spec. And the compability between older browsers hasn't been that good. But in the end, CSS is the best we have for any environment.

Collapse
 
fly profile image
joon

Modern UIs should be designed relative to font size the user has selected for his or her browser
Definitely, something that I had not accounted for when I began CSSing. Thank you for the advice.

Zeplin doesn't support that as far as I know.
Very true, I've just been using the font-size in pixels generated via Zeplin.

it seems pretty clear that the V in MVC is CSS in web development
Very insightful. I put some thought to the notion and I agree completely.

But in the end, CSS is the best we have for any environment
Sad but true... a great big nemesis that I have been forced to conquer :)

I immensely appreciate your feedback Mikko. It widened my perspective related to CSS and also supplied real-life applicable project design advice. Thank you very much! :)

Collapse
 
fly profile image
joon

Thank you for the feedback Dan!

you are bringing back html/css mess that we have left behind.
I completely agree with you. This is a mess :)

MainDiv2Wrapper is not a component. Article or Comment or Badge etc are components.
Actually I think my concept of naming conventions of component was not up to par. The examples you gave me are of great help and I believe I will be using similar naming conventions when I fix the code.

Thank you for taking the time to point this out. I greatly appreciate it :)

Collapse
 
scottkidder profile image
Scott Kidder • Edited

I feel your pain. I agree with most of the feedback below but I can't believe no one has recommended you take a look at TailwindCSS yet. It has helped me immensely as I've transitioned from backend to frontend. It is a somewhat different approach to CSS but it's a really nice experience once you dive in. It lends well to rapid prototyping but has the flexibility to mesh with any type of design system or style guide.

Collapse
 
bamboriz profile image
Boris B.

The exact same spot in which I find myself. Backend Dev at heart being put into a Full Stack role. We'll find our way though, I just believe in putting in the work.

By the way, hearing alot about Tailwind recently. Is there a React implementation and is it better than Material-ui?

Collapse
 
fly profile image
joon • Edited

I saw your discussion post on Dev regarding Tailwind Techonda :)

I'm glad that this post is helping a fellow developer consider other tech stacks.

The exact same spot in which I find myself. Backend Dev at heart being put into a Full Stack role.
Thank you for pointing this out. It is a great relief that people like me are (probably) not the majority, yet exist out there :)

Collapse
 
seanmclem profile image
Seanmclem

I used to hate css until I took some time to learn it. SCSS helped. Just pouring "hate" on things you don't understand or haven't learned yet -is going to be a problematic standpoint to take on things in life

Collapse
 
fly profile image
joon

Thank you for the feedback Seanmclem!

Just pouring "hate" on things you don't understand or haven't learned yet -is going to be a problematic standpoint
I completely agree. However, I do think I have a legitimate reason for 'hating' CSS, which is pointed out in this comment, TLDR; I find it difficult to notice subtle changes in documents, so I miss a lot of things.

I do try to be optimistic and try my best on most things, it's just that I try to focus on what I'm good at and as a result, I ended up (sort of) ignoring CSS - until I began full-stacking.
Yet I agree that I should take some more time to learn it since I do believe prioritizing on the project's needs should be put before what I find efficient to study.

Collapse
 
seanmclem profile image
Seanmclem • Edited

My suggestion would still be to instead focus even more on css, and anything else that makes you anxious or scared. I was in the same position about a year and a half ago. I could not figure out css and I "hated" it and avoided it. I kept trying and it started to click. Now I'm pretty good at it. Have you tried SCSS? Its nesting feels just like the DOM. If you can figure out the Dom you can get css. You have problems with subtle style changes? Then start with broad ones and refine over time. Everything in programming starts from a similar position. If you can learn anything - you can learn css. Or you can't learn anything. Can you?

Thread Thread
 
fly profile image
joon

If you can learn anything - you can learn css. Or you can't learn anything. Can you?
I completely agree with this statement and I do believe that learning CSS was not the issue, but my approach to life which is to study things that I can learn efficiently/effectively(High output compared to input). CSS was a field that directly contradicted with this/my mindset.

But I will definitely try out SCSS and tailwind(as others have suggested) and try to structure my project in the most optimal sense possible.

You have problems with subtle style changes? Then start with broad ones and refine over time.
Also an approach I hadn't really considered.

Thank you for the suggestion Sean :)

Thread Thread
 
seanmclem profile image
Seanmclem

Trying a css framework before you understand css might make things more difficult. Maybe not. Everybody is different. SCSS isn't a framework, just a slightly improved way of writing it.

Collapse
 
eemebarbe profile image
Jeremy Barbe 🧢

This fails to include the hordes of styled components that you have to include in your component's file that radically lower readability, especially with hooks.

Collapse
 
fly profile image
joon

Thank you for the feedback Jeremy :)

that radically lower readability, especially with hooks.
I had noticed that my styles were beginning to get out of hand, yet I think I chose to ignore the fact.
Good catch! It is definitely something I should not have ignored.

Collapse
 
okkdev profile image
Jen Stehlik

Oh boy, I don't like the look of this. You should try Tailwind CSS.

Collapse
 
fly profile image
joon

Thank you for the feedback Jen!

You should try Tailwind CSS.
Will definitely do so, I saw a few comments recommending Tailwind as well

Collapse
 
snookems profile image
Snookems

I prefer the second one too.

Collapse
 
fly profile image
joon

Thank you for the feedback Snookems!

Now that I see the fault in my first styled-component attempt, I prefer it too :)

Collapse
 
kheaganeckley profile image
kheaganeckley • Edited

There are allot of new css-in-js libraries each with there own syntacts, that for instance make certain things, like animations, structuring react apos and theming (especially for light-dark mode) easier.Without knowing css really well you won't be able to pick up the new better ones. Great css-in-js souloutions that I at least know: emotionjs, theme-ui (from the creators of gatsbyjs - my fav), glamorous, and of course styled components.

Collapse
 
fly profile image
joon

Thank you for the feedback kheaganeckley!

emotionjs, theme-ui (from the creators of gatsbyjs - my fav), glamorous, and of course styled components.
I will definitely look into these and consider whether they can be a better substitute for styled-components. Kudos for chipping in :)

Collapse
 
kbrackson profile image
Kayla

How long have you been 'front ending'? CSS is your biggest friend is you want scalable, semantic code. This example actually made me think the inverse of what you were trying to argue, but thank you for helping me out it into words - this code might be great for a single freelance developer in limited cases, but so semantically messy and bloated that any team member would just label this as spaghetti and wouldn't even bother refactoring it.

I would suggest investing in reading up on pug / scss (mixins + variables in your build) with your react (or vanilla, or vue, or whatever.js) - have it output your SCSS or LESS into CSS for you (use prettier at runtime if you need to, with most compilers), then you can dig in later.

Also worth checking out: BEM, prettier, and other CSS naming / cleaning tools.

Collapse
 
fly profile image
joon

Thank you for the feedback Kayla!

so semantically messy and bloated
I couldn't agree more :)

SCSS or LESS into CSS for you
I never considered using SCSS and LESS because although I heard that they are great, it just felt like more CSS. But I kind of get the impression that styled-components do pretty much the same thing, is there any particular reason why you recomment SCSS or LESS?

BEM, prettier, and other CSS naming / cleaning tools.
Never heard of BEM before, will definitely try it out if it helps writing CSS.
Thanks a lot!

Collapse
 
frontendtony profile image
Anthony Oyathelemhi

Whew! Where do I begin!?

I've read a lot of comments on this, both positive and negative. The problem here is NOT your inability to write CSS (you still write CSS with Styled Components), it's that you want to see the structure (and styling) of the page once you look at the file.

But like everyone has pointed out, you're going about this in a wrong way. I'll like to suggest a much better way to deal with your CSS hate, Utility-first CSS. Checkout tailwind css

The benefit of this is that, you immediately get a sense of the style of your page without opening the CSS file. You can use this with SC (I'm doing exactly this right now).

It'll take you just a few hours to get used to this I promise.

Collapse
 
fly profile image
joon • Edited

you want to see the structure (and styling) of the page once you look at the file
Wow, I never realized it myself, but I think that this was the (real) reason why I structured my styled-components so un-semantically. Nice catch!

Checkout tailwind css
I have seen several posts regarding tailwind CSS but never imagined I'd be needing it.... alas maybe the time is ripe...

you immediately get a sense of the style of your page without opening the CSS file. You can use this with SC
OK, if it does exactly what you say here, I'm instantly hooked. I will definitely try it out. Thanks so much for the recommendation.

Wow, I did not expect another novel, constructive and directly-helpful comment that didn't just widen my perspective regarding the matter - but actual advice that I'm considering using.
Thank you beyond words, I greatly appreciate the recommendation.

Collapse
 
frontendtony profile image
Anthony Oyathelemhi

You're welcome Joon. Glad I could help

Some comments may only be visible to logged-in visitors. Sign in to view all comments. Some comments have been hidden by the post's author - find out more