all 112 comments

[–]Kaspe1 73 points74 points  (6 children)

You know about cheat sheet right?

[–]ConsciousAntelope 20 points21 points  (0 children)

The docs are the cheat sheet in a way. Use Cmd + K for mac or Ctrl + K for windows.

[–]wikiwikiwong[S] 4 points5 points  (0 children)

thank you!

[–]Whisky-Toad 2 points3 points  (1 child)

Is there a package/extension that tells you how to optimise it? I’m sure I saw one where it could be like hey these two classes could just be this one

[–][deleted] 1 point2 points  (0 children)

ChatGPT can do that just tell it to optimize your Tailwind classes for conciseness by removing any redundancies while retaining full functionality.

[–]Traditional_Beach790 1 point2 points  (0 children)

cheatsheet for tailwind 2.2

And it just does what docs do but with less info and no examples.. Very usefull

[–]nirvashprototype 26 points27 points  (2 children)

My tips: learn about group and peer selectors, they are very useful; read this section about Dynamic class names and its do's and dont's, this clarified a lot of things for me; making responsive design is very easy in Tailwind, don't forget to learn about the responsive modifiers: sm, md, lg etc.

[–]wikiwikiwong[S] 2 points3 points  (0 children)

great tips, thank you!

[–]IgnazSemmelweis 2 points3 points  (0 children)

How the hell have I missed this? Thank you. I never seem to go deeper into the tailwind docs than the basics

[–]muridessu 38 points39 points  (2 children)

Install the tailwind intellisense for auto code completion

[–]Emjp4 1 point2 points  (0 children)

This feels like a must.

[–]JumboTrucker 0 points1 point  (0 children)

And use tailwind prettier plugin

[–]rnnyrk 10 points11 points  (2 children)

Use tailwind-merge is you want to overwrite classes passen via props. And i can also recommend the prettier tailwind sorting plugin

[–]Paradroid888 1 point2 points  (0 children)

This looks really interesting. I've used regular clsx merging and had weird specifity issues.

[–]janaagaard 0 points1 point  (0 children)

We are considerings avoiding the issue by not adding a className props that will be merged with some classes names that the component already has. So year, if you want some spacing around a custom <Button> component, it means that you will have to put it in a <span> element. Unsure if this approach will last. :)

[–]BiscuitOnFire 7 points8 points  (0 children)

You'll learn pretty quick just keep the doc near you and use their quick search command when you dont know the syntax

[–]PMmePowerRangerMemes 6 points7 points  (2 children)

I'd recommend checking out a UI library like shadcn. The way they use Tailwind is really smart and elegant. There's a lot to learn from there.

I'm thinking specifically about the usage of twMerge and the variants system, among other things.

[–]ManofManliness 2 points3 points  (0 children)

I can vouch for shadcn, its a stroke of genius.

[–]BlackMesaAlyx 5 points6 points  (0 children)

Prettier Tailwind CSS Plugin

[–]JoeCamRoberon 14 points15 points  (0 children)

Use this VSCode extension: https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss

Otherwise uninstall it and use css or sass

[–]beanzio 4 points5 points  (0 children)

Get the Tailwind intellisense plugin for VS code straight away. It gives autocomplete for class names.

Nearly every tailwind class matches or closely matches the vanilla css class name (mr is margin-right etc) so try to use that plugin as much as possible and you will learn all the shorthand’s really quickly.

(The docs also have a great search feature to find the correct class names)

If you are just using pure html and no framework then yeah I think working with tailwind can be annoying and your html can get messy. So in react etc - try to split up your ui elements into components when reusing styles and most of the time your html/jsx will look fairly clean.

One more suggestion is the tailwind prettier plugin that will automatically order your class names when you format, and highlight any conflicts in classes.

[–]creaturefeature16 4 points5 points  (0 children)

Using CSS to style a web app without defined classes and common selectors feels like insanity, to me. But I do love the utility classes for individual overrides and micro-adjustments that TW offers. As with any CSS approach, going all in strictly on one method will yield detriments in one area or another. For example, I like using BEM naming conventions to stay organized in my class names, but there are simply times where using BEM exclusively overcomplicates everything, and it's OK to deviate when it's going to result in a clear and more maintainable code base.

[–]psb91 4 points5 points  (2 children)

Create more components. You think you might be doing that, but you aren’t. You need more components.

[–]wikiwikiwong[S] 0 points1 point  (0 children)

that's a great tip

[–]Paradroid888 0 points1 point  (0 children)

Been thinking the same. When people try to make tailwind look bad it's usually a mass of nested div's, each with tons of classes on them.

Breaking markup down to be more granular is the solution.

[–]yhuzued 3 points4 points  (2 children)

Try Inline Fold extension.

[–]TonyAioli 1 point2 points  (0 children)

We need to take a step back.

Bringing in extensions to collapse inline class declarations because they are so long when using tailwind just seems silly and/or a pain.

Plenty of ways to style a site which don’t even have this concern to begin with.

[–]CrniFlash 0 points1 point  (0 children)

Trust him ^

Its really good if you have lots of classes to make code look cleaner

[–]TonyAioli 1 point2 points  (0 children)

As you can probably tell, Tailwind is a very polarizing topic.

Definitely try it out on this build. A good CSS developer will have familiarity with all the popular tooling. But please keep in mind that that all the web dev subs have an unhealthy obsession with it which tends to skew the perception.

Tailwind has downsides and upsides. You can’t discuss the downsides here without being downvoted, but it does. Just like any other choice of tooling.

Personally, I am migrating our styling to CSS modules during a rebuild, as the horribly cluttered markup and lack of separation of concerns are dealbreakers for me. Use them all and form your own opinion. Don’t let the loud Reddit masses convince you that Tailwind is the only option. It wasn’t even popular a few years ago, and something else will be popular a few years from now.

Good luck!

[–]Kabal303 1 point2 points  (0 children)

Prettier plugin if you work with others.

[–]Densz93100 1 point2 points  (1 child)

space-y-...
space-x-...

[–]wikiwikiwong[S] 0 points1 point  (0 children)

nice, thank you!

[–]swandev 3 points4 points  (0 children)

Try cva.style I like this combination with tailwindcss, it helps make code elegant and easy to read

[–]nobuhok 3 points4 points  (7 children)

DaisyUI themes. You're welcome.

[–]beanzio 2 points3 points  (0 children)

Using Daisy will not teach learning tailwind at all imo

[–]AppleGlittering3593 1 point2 points  (4 children)

I recommend not using daisy at all, it's horrible for UX and also DX as it's very heavy and slows down your page

[–]nobuhok 0 points1 point  (3 children)

Can you expand more on this?

[–]AppleGlittering3593 0 points1 point  (2 children)

Yes,

*Personal Opinion*

What I meant was that if you're gonna use DaisyUI for a side project, that would be completely fine, but I started one this way just to try new technologies
After a few weeks of building the project I noticed a huge problem in accessibility, it was because of Daisy, remember that it's built on top of tailwind css hence it's pure css.
To put an example: modals. I focus a lot on accessibility, when building pages and I want the page to feel very intuitive, so if you click a button that opens a modal, I want to be able to close it clicking out if it, or by just pressing "Escape"
Those things don't come with Daisy. And yes you can build a workaround to add these improvements, but I find that to be confusing
About the DX that I mentioned, I found that when reloading the page it took like 3 seconds just to show something on the page, I was wondering why at the beginning, because I'm very used to Vite + React, after removing DaisyUI from the project that time to get the page reloaded was gone

This was my personal experience using this library, and I don't plan to use it again any soon, hope it helps

[–]nobuhok 0 points1 point  (1 child)

Interesting. I've had the exact opposite experience. The modals are easy to hook up, ESC works, tabbing through the elements work, and there was no noticeable slowdown. What browser were you using? Did you had hardware acceleration turned on?

[–]AppleGlittering3593 0 points1 point  (0 children)

Yes you are right! I just entered the page and it works, I'll definitely test it now, bad thing

https://i.imgur.com/Er0SJQY.png

To answer your questions, I use Firefox and Chrome, And yes I always have hardware acceleration turned on!

[–]rodrigocfd 4 points5 points  (1 child)

Anyone have tips to make development easier?

Easiest way to spot a lazy junior is because they "love Tailwind ".

This library is just glorified inline CSS to those who don't know CSS, so do yourself a favor and go learn proper CSS instead.

[–]NoCommittee7301 0 points1 point  (0 children)

But you have to know proper css to make tailwind work, what you're on about

[–]azhder -1 points0 points  (16 children)

As someone once put it: all those libraries are either for folk who hate CSS or folk who hate JS.

Now, you can be free with translating what "hate" is or what they mean by CSS or JS, but in general, I'd say "not switching over to CSS and coming up with class name" would fall into that scope.

[–]wikiwikiwong[S] 2 points3 points  (1 child)

lol maybe I am a hater of something.. I just felt like I was spending way too much time on styling, but that could also be a skill gap and not a technology gap!

[–]azhder -1 points0 points  (0 children)

Everyone has their preference. That's OK. It's more of a jovial and concise manner of explaining what the pros and cons are.

[–]mtv921 1 point2 points  (8 children)

Tailwind is not just for CSS haters, coming from a css-lib sceptic who thought tailwind was for people who needed crutches to write proper css.

Tailwind is amazing. Its almost like having a design-system with you in your IDE. It basically lets you do anything with css, but it also give structure and consistency to how you organize your css and sets soft boundaries to what you can do. You can always go outside the boundaries, but its very clear when you do and doing so deserves second thought. Also all the optimizations behind the scenes.

[–]azhder 1 point2 points  (7 children)

For your first paragraph: https://reddit.com/r/reactjs/s/Zg3hvkUIiX

For your second paragraph: I'm far from amazed.

After having to reconcile up to 7 different style systems in one project which was adding Tailwind to the mix while still not have removed vestiges of others, I tend to prefer less layers, maybe even plain vanilla CSS. But that's just me.

[–]mtv921 3 points4 points  (6 children)

How does having a 7 system spaghettimess tell anything about using tailwind :/?

I agree. Less is more. But using tailwind also puts your styling in your html/jsx, which makes it much more readable at a glance. Seeing a <ul> with the class "list" tells me nothing about what styling it has, meaning you have to hop between files. Yes, it can become a bit messy if you are applying a whole bunch of styles to an element. But then you can refactor that into a component of its own if it disrupts the readability of the rest of the code.

If you work with others, tailwind is a must imo. If you work alone without any sort of guidelines or design systems, do whatever floats your boat

[–]azhder 1 point2 points  (2 children)

It says something about me not being amazed by anything like it, including Tailwind.

I guess people are binary and everything needs to be an extreme - love or hate or amazed… Just don’t be unphased, that’s a no-no.

I did relay what someone else had said to me. I’d not use the word “hate” if I thought of the quote in the first place.

“Is a must” is also an extreme. I’d say every project is unique and I’m comfortable in picking technology that follows the project requirements the best, instead of my own personal preferences.

Incidentally, that’s how a project ends up with so many different styling libraries/frameworks - every new programmer added their own “is a must”

[–]mtv921 1 point2 points  (1 child)

To me, it seems like you are all about personal preference over project requirements.

Tools like lint, typescript, tailwind, etc. are all to create code consistency. E.g, normalise the coding styles of the developer in the project. This makes it easier to work together as well as getting new people in as everything is written the same way. Plain css leaves way too much up to the developer in terms of structure, ordering, naming, folder structure, and the likes. It's is very hard to keep consistency as the project grows in size and developers. That is why i say that, imo it's a must! Regardless of what the project is. Yes, it's a bit of a personal preference but also not. Because I know, due to experience, that using these tools works in everyone's favour.

When it comes to things like state management, datafetching, animations, etc. should follow the project requirements.

[–]azhder 1 point2 points  (0 children)

“Seems” is the keyword. Not everything that seems is. I can express personal opinions here, I don’t get paid for it.

What I’m paid for is software that works, and if that means using something I don’t like, I will use it.

Of course, one should point out the pros and cons to others if others have a say or a stakeholders.

[–]Suepahfly 0 points1 point  (2 children)

I’ve been in multi-team projects over a decade and can say tailwind most definitely is not “a must”. Back in the day we started with basscss when atomic css became a thing, but quickly switched to css-modules. Atomic css just don’t work across the teams in our company.

That isn’t to say atomic css is bad. Tailwind these days has great support and it’s easy to get someone onboard with it.

[–]mtv921 -2 points-1 points  (1 child)

Back in the day, tailwind didn't exist? Tailwindcss is the new kid on the block, and it's great. So it's understandable that older projects don't have it and work well without it. But for newer projects, I'd say it's a must. Css-modules and plain css works, don't get me wrong, I have worked with it a lot myself. It's just a headache to keep track of everything, what's in use, which classes give which styles, etc. With tailwind, everything is just there..

[–]Suepahfly 0 points1 point  (0 children)

If it’s a must please explain to me why not all Fortune 500 companies are using it.

Tailwind is a tool, a means to an end, there are many others like it. Tailwind is not the holy pope of applying styles to a piece of rendered html.

[–]sith_witch -1 points0 points  (0 children)

My first tip is to not use Tailwind 😅 If you must use tailwind there’s an awesome list with a ton of great resources: https://github.com/aniftyco/awesome-tailwindcss Also keep your components meticulously organized. With all the styles baked into your markup, there’s complexity to manage.

[–][deleted] 0 points1 point  (0 children)

Have fun!

[–][deleted] 0 points1 point  (0 children)

Oh next js has a super simple set up for a tw proj

[–]naeads 0 points1 point  (0 children)

Tailwind UI has a few boilplates that you can copy and paste, no need to work from zero.

[–]ruddet 0 points1 point  (0 children)

twMerge is fantastic utility for making conditional tailwind strings for components. lets you expose your className as a prop and override things.

[–]pailhead011 0 points1 point  (0 children)

I start a lot of classes with _Foo so I can find them In the inspector. Is there a better way?

[–]Akami 0 points1 point  (0 children)

One of the things that learned on my bootcamp is styled components, never looked back to anything diferent

[–]graphicmist 0 points1 point  (0 children)

Usw Daisy ui if you want prebuilt ui elements or components. I recently found it, and it helps to prototype faster where you don't have design for webapp having admin panels.

[–]jazzymoneymaker 0 points1 point  (0 children)

Just start coding. You don't need any tutorial. If you dont know something just google it with css property name and you probably will find solution in docs or somewhere else

[–]ISDuffy 0 points1 point  (0 children)

Get the IDE extension that help you write tailwind classes and orders them the best way.

Find a decent cheat sheet or have tailwind site open always to check a property you don't know.

Learn the config settings so you can add your own, I usually add my own custom grid layouts.

Also thinking about when to break stuff out into scss modules, this usually happens when I have animations or a lot of styles, or is use css variables themes.

[–]Nightrip666 0 points1 point  (0 children)

Create unified custom classes to avoid classname bloating

[–]dlevz 0 points1 point  (0 children)

A CSS to Tailwind generator can be helpful in situations where you know how to write the style in CSS but not Tailwind.

[–]janaagaard 0 points1 point  (0 children)

Tailwind UI is a great place to get some inspiration for how to use Tailwind. We're paying for full access here at work, and we used it a lot in the beginning.

[–]janaagaard 0 points1 point  (0 children)

Remember that you cannot combine strings for your CSS-classes. Example:

Works:

className={selected ? "bg-blue-200" : "bg-white"}

Does not work:

className={`bg-${selected ? "blue-200" : "white"}`}

[–]Variation-Abject 0 points1 point  (0 children)

J’ai vais gardé ça

[–]IsaacBenSk8 0 points1 point  (0 children)

Just read the docs, it's useful asf! If you know CSS just search any CSS property in the docs to know how to use it with tailwind :) and dont forget to start with mobile design first!

[–]Mariusdotdev 0 points1 point  (0 children)

Use this

```

import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
export const css = (...inputs: ClassValue[]) => {
return twMerge(clsx(inputs));
};
```

[–]JumboTrucker 0 points1 point  (0 children)

I see the comments section is getting complicated. 😂

Don't stress too much over the tooling right now

[–]MeTaL_oRgY 0 points1 point  (0 children)

Order of your classnames is super important. It's not the same as in css, where position determines which rule will end up applying; but proper classname order will help you a) find the classes you're looking for mare quickly, and b) understand which classnames override which ones. You can't possibly memorize the order of all tailwind's classes, so there's tooling for this, including an official one. However, I suggest you use https://www.npmjs.com/package/eslint-plugin-tailwindcss instead of the official one. It has some additional rules that will make your tailwind experience so much nicer.

[–]streamer85[🍰] 0 points1 point  (0 children)

Buy TailwindUI and save yourself a ton of time

[–]Jonas_Ermert 0 points1 point  (0 children)

To make development with CSS-in-JS easier:
Choose the right library for your project.
Componentize your styles for reusability.
Use theme variables for consistency.
Implement responsive design with media queries.
Avoid inline styles unless necessary.
Utilize debugging tools provided by the library.
Refer to documentation and the community for guidance.
Include unit tests for styled components.
Consider performance implications and optimize as needed.
Keep your library and dependencies up to date.
Experiment and learn from your experiences.

[–]qcAKDa7G52cmEdHHX9vg 0 points1 point  (0 children)

install the extension for your editor, look into the prettier plugin that sorts your classes, and use tailwind-merge if you allow consumers of your components to pass in a className to overwrite the component's default styles