Sorting Tailwind CSS Classes Automatically with Prettier

Поділитися
Вставка
  • Опубліковано 19 вер 2024

КОМЕНТАРІ • 233

  • @MeonisRP
    @MeonisRP 2 роки тому +115

    I just started learning tailwind a week ago. And I can already say it’s one of the best frontend tools I’v seen. It saves so much time and energy!

    • @scravengerx
      @scravengerx 2 роки тому

      Where to learn ?

    • @simonswiss
      @simonswiss 2 роки тому +1

      That's awesome to hear! Glad you're enjoying the journey so far!

    • @gilangeizan2282
      @gilangeizan2282 2 роки тому +2

      @@scravengerx official docs tailwind css, just read bro

    • @somerandomchannel382
      @somerandomchannel382 2 роки тому

      Is prettier-plugin-tailwindcss associated with headwind ? Headwind is a VSCode extensions that existed for many years and been contributed by friendly open-source developers to help with sorting tailwind classes. I hope they get some credit for their hard work!

    • @Ikram-Hussain
      @Ikram-Hussain 2 роки тому

      can you tell me? which font & theme is used on this video?

  • @alexander.kachkaev
    @alexander.kachkaev Рік тому +48

    👋 folks! One of Prettier maintainers here. Note that starting with Prettier v3.0, plugin autoloading is no longer available. After installing `prettier-plugin-tailwindcss`, it is necessary to specify it in the config file (prettier.config.js, .prettierrc.json., etc.).
    {
    "plugins": ["prettier-plugin-tailwindcss"]
    }

    • @Codefide
      @Codefide Рік тому +1

      How do we write it in the .prettierrc.json? I'm having difficulty when saving .scss files nothing gets formatted.

    • @paullagmark
      @paullagmark 10 місяців тому

      Timesaver, thank you!

    • @raian_ruku
      @raian_ruku 9 місяців тому +1

      @@Codefidejust search prettier in search panel, it will show an option to create one

    • @mephdapumkin
      @mephdapumkin 8 місяців тому

      Thank you so much!

    • @bennyzen
      @bennyzen 8 місяців тому

      I was actually scratching my head and wondering why this is no longer working after updating Prettier. Thank you so much!

  • @avetisk
    @avetisk 2 роки тому +29

    At last! No more philosophical existential questioning about class order 🖤🖤🖤

  • @lsagar
    @lsagar 2 роки тому +47

    The debate wasn't about whether or not to use tailwind but about how to order tailwind classes.
    And now the debate is finally resolved

  • @cristhiangarcia8845
    @cristhiangarcia8845 2 роки тому +75

    The developers/community of Tailwind is by far the best 😁

    • @michaels8398
      @michaels8398 2 роки тому +1

      Agreed! They really demonstrate that they listen to their users, recognize any inconveniences and work hard + smart to eliminate them - because of this Tailwind will only get better and better

    • @Ikram-Hussain
      @Ikram-Hussain 2 роки тому

      can you tell me? which font & theme is used on this video?

  • @undefindjs2419
    @undefindjs2419 2 роки тому +5

    This is soo sick, me and my team just had this talk today!!!.. love this!!!

    • @simonswiss
      @simonswiss 2 роки тому +3

      Haha did you have an argument like in my little intro zoom call? 🤣

  • @Skillthrive
    @Skillthrive 2 роки тому +2

    As always, great video. I tried keeping styles organized and now I don't even need to think about it. Perfect!

  • @bergerblancsuisse.
    @bergerblancsuisse. 2 роки тому +2

    Fantastic, we absolutely love prettier and having tailwindcss automatically sorted for us is a no brainer, quite literally we don't use our brain when ordering tailwindcss classes anymore!

  • @Brocollipy
    @Brocollipy 2 роки тому +4

    Soo much good stuff in the tailwind world. Took me a while to make the move from bootstrap but so worthwhile.

  • @Antebios
    @Antebios Рік тому +1

    This is such a time saver. I can't believe I wasted so much time spacing manually.

    • @simonswiss
      @simonswiss Рік тому

      I know right? It's like formatting indentation and semicolon stuff before Prettier 😅

  • @Kwuasimoto
    @Kwuasimoto Рік тому

    Wow.. I've been using tailwindcss for almost 2 years now and this is the first I've seen this plugin, absolute game changer.

  • @ibnuhalimmustofa7813
    @ibnuhalimmustofa7813 2 роки тому +1

    For a long time I follow adam wathan tweet about the best practice writing tailwind classes. Now you make me (us) easier, you're awesome. Love this, thanks

  • @MeonisRP
    @MeonisRP 2 роки тому +3

    Guys you are super cool! I was always arguing with myself how to order those classes :DD

    • @simonswiss
      @simonswiss 2 роки тому

      Haha so it was not just me!

  • @Tryto
    @Tryto 2 роки тому +1

    Thanks Simon giving a brief but powerful introduction for this. Now, I can introduce to the developers of Taiwan.

  • @ThomasBurleson
    @ThomasBurleson 2 роки тому

    This video is wonderful and provides interesting insights:
    Changing the Tailwind directive order in you class="..." does not affect the generated CSS in any way. The specific ordering is enforced during compile/generation. This is an important fact to have when talking about adoption of Tailwind CSS!

  • @moneyfr
    @moneyfr 2 роки тому +5

    instead of hover:bg-red hover:font-xl = hover[bg-red font xl]

  • @lixou
    @lixou 2 роки тому +4

    I have only one problem: My cursor doesn't jumps with it. When i try to figure out the best color, i added ".... bg-red-500" at the end, saved, saw it doesn't look that great for this, then wanna change by simply backspacing 3 times but wait, the background-class isn't at my cursor anymore. Please let the cursor jump with it when using VSCode's Prettier

  • @rfmiotto
    @rfmiotto 2 роки тому +8

    Hi Simon, great work! I have a question: does the Prettier plugin work in case of conditional styling such as in React applications?

  • @chichebem
    @chichebem 2 роки тому

    Amazing!!! I started using tailwindcss 4 months ago and it has been AMAZING 🗣

  • @psyferinc.3573
    @psyferinc.3573 Рік тому +1

    i learn so much from any of your videos. thank you .

  • @riensten
    @riensten 2 роки тому +4

    Is it possible to automatically place a long list of classes onto multiple lines? Just like Prettier does with stuff like long arrays.

  • @devmarkmonster
    @devmarkmonster 2 роки тому +1

    Now if only Blazor was supported by Prettier. Keep up the good work!👌🏻

  • @SilaMC
    @SilaMC 2 роки тому +5

    Feature Request: Play the sound effect in vscode when classes are reorderd.

    • @jonathanreinink1193
      @jonathanreinink1193 2 роки тому +4

      lol I don't think you actually want this 😂

    • @alexandersamokhin
      @alexandersamokhin 2 роки тому

      Gonna drive you nuts 🥴

    • @simonswiss
      @simonswiss 2 роки тому +1

      @@jonathanreinink1193 That would be fun for 1 day and then...

  • @misaka5368
    @misaka5368 2 роки тому

    I learned css from tailwind best ever tools love u

  • @horaciocoronel
    @horaciocoronel 2 роки тому +3

    How does prettier differs from the Headwind plugin when sorting classes?

    •  2 роки тому +1

      Good question

  • @buzzer79
    @buzzer79 2 роки тому +2

    first of all your content is top notch!thx for the vids!

  • @provereno-na-sebe
    @provereno-na-sebe 2 роки тому +1

    Sorry but it doesn't seem to work for me. I'm using tailwind with wordpress and had to install the frontier php plugin but it has issues with the php html options and the tailwind frontier plugin itself doesn't work either :( Back to Headwind

  • @RichReflectionz
    @RichReflectionz Рік тому

    This has been very helpful as I like things structured and easier to follow. Thanks for this extension to help with sorting.

  • @effectic
    @effectic 8 місяців тому

    Thanks. You're the only one who helped me to set it up.

  • @atanaskanchev6103
    @atanaskanchev6103 2 роки тому +2

    Anyone able to make prettier break long class name lines? It seems it’s not supported yet.

  • @dance2die
    @dance2die 2 роки тому

    thank you for the plugin as well as intuitive rules that prettier plugin sorts with

  • @derektata
    @derektata 2 роки тому

    This plugin saves from a lot of headaches, Thank you!!

  • @Ibrahim-fh6kv
    @Ibrahim-fh6kv Рік тому +1

    Is there a way to break the long Tailwind CSS class into multiple lines, in order to make it readable?

  • @yousafsabir7
    @yousafsabir7 2 роки тому +1

    Alhamdulillah....
    This was my last concern about tailwind ....
    It's gone now😙😙

  • @jjrise
    @jjrise Рік тому

    man these videos are pure gold... thank you so much

  • @zummon
    @zummon 2 роки тому

    more easily to see a lot of classes. I somehow used too much brain to think which order helped me to come back and edit easily. Now I'll be able to save more my brain power to do others that more matter

  • @JayPozo
    @JayPozo 2 роки тому

    I’ve been waiting for this, thank you! 🙏🏽👏🏽

  • @DaDa-gr7cy
    @DaDa-gr7cy 2 роки тому

    Wow, these guys definitely know their game

  • @wdwaleed
    @wdwaleed 11 місяців тому

    Hi, this prettier plugin is not working in my project. I'm trying to use it in a Vite React app. Is there a different setup for it? Could someone please solve this problem. Prettier itself is working fine but this plugin for tailwind css is not.

  • @yousafsabir7
    @yousafsabir7 2 роки тому +3

    Tailwind is heaven on earth for CSS developers....
    Who here agrees??

  • @devsbuddy
    @devsbuddy Рік тому

    As i am mostly working with laravel framework which uses blade and prettier is throwing error that it
    can not format the blade files.

  • @kemoboy
    @kemoboy Рік тому +1

    I love tailwind. Tho, I'm facing a problem... I'm switching gears from JS to WordPress for a contract work and I can't, for the sake of sanity make the "Automatic class sorting" work with any .php file. It works with .html but not with .php. Does anyone know a solution to this problem? I'm using VSCode.

  • @gopalloharnew5948
    @gopalloharnew5948 2 роки тому +1

    05:52 This Class Sorting thing is not here to avoid Bugs and Issues but Purely for Organisation and Consistency Reasons !

    • @nivethan_me
      @nivethan_me Рік тому

      of course prettier is a code formatter so a prettier plugin is only going to do it's job

  • @adenreleemmanuel9848
    @adenreleemmanuel9848 7 місяців тому

    Thanks for the video
    please which font do you use in your vs-code editor

  • @gtdmg489
    @gtdmg489 2 роки тому +1

    I can't get this to work on laravel blade. Does anyone know how to install it properly on laravel?

    • @96downlu
      @96downlu 2 роки тому +1

      Prettier currently had no parser for blade. There is a bounty of ~$2500 for the first dev to do it.

  • @david.kizivat
    @david.kizivat 2 роки тому +1

    I'd also like to put related classes into separate lines but prettier ruins that unfortunately…
    e.g.
    class="
    mx-4 my-8
    flex flex-col
    w-full h-24
    border-2 border-gray-300
    "

  • @saklinemostaq7718
    @saklinemostaq7718 3 місяці тому

    Do I need to install it for all my working directory and also create a .prettierrc file? Are there another option to do it once and will apply all my working directory?

  • @swyxTV
    @swyxTV 2 роки тому +1

    lol kudos for finding a way to say “npm install prettier-plugin-tailwindcss” stretched out to 10 minutes

  • @sanjarcode
    @sanjarcode 8 місяців тому

    Couldn't get it to work on vscode mac. Fix is to install Headwind extension, in addition to Tailwind.

  • @ddrweb_
    @ddrweb_ 2 роки тому +1

    This is cool, for a long time I tried doing just this, it was a bit of a pain but the outcome is more readable code. 1 question does it work (or might work in the future) with the @apply directive?For ex i can create a long directive full of classes and it will sort them and break them based on max line specified in prettier? - that will be a beast . Tailwind is the best lib for css you guys killed it. Thanks for your efforts

    • @ddrweb_
      @ddrweb_ 2 роки тому

      ohh so f.. sweet just tested and in works in apply directive as well

    • @nivethan_me
      @nivethan_me Рік тому

      you shouldn't use @apply, in future it will throw a build error

  • @bestchoice7431
    @bestchoice7431 Рік тому

    Your prettier-plugin-tailwindcss does not work with vs code. Can you please give any quick solution for this?

  • @EvgenyBobkin
    @EvgenyBobkin 2 роки тому

    Thank you for this info, however, I had hard time with getting this plugin working with pnpm.

  • @nikhil182
    @nikhil182 Рік тому

    Oh god, did I just see a Shiba at first?😍😍

  • @michaelsaucedo3952
    @michaelsaucedo3952 Рік тому +1

    What about getting rid of extra spaces between class names?
    className=" mx-auto my-auto text-white "

    • @simonswiss
      @simonswiss Рік тому

      YES that would be so handy - this does my head in and I manually fix it all the time 😅

  • @nathandowner6007
    @nathandowner6007 2 роки тому

    Awesome utility for the best css utility !

  • @cyimanafaisal6800
    @cyimanafaisal6800 Рік тому +1

    what if I am using react or nextjs

  • @FONO63
    @FONO63 Рік тому

    This plugin is not working properly on the current version of VS and prettier. Had to switch to Headwind instead.

  • @BohumilJahoda
    @BohumilJahoda 2 роки тому

    Thank you! Is there any way to sort attributes in dynamic classes? To fix something like

  • @emq578
    @emq578 2 роки тому

    Thank you for the tips! Fantastic! Anyway, may I know what font you are using?

  • @skourta
    @skourta 2 роки тому

    Been dying for this!!

  • @WiziwigeAgario
    @WiziwigeAgario 2 роки тому

    Amazing as always

  • @khpeiris
    @khpeiris 2 роки тому

    Would this sort JIT classes as well? Been using a third-party vscode plugin for this, but the biggest headache is it doesn't work with JIT classes in place. (eg. pt-[36px] )

  • @dylanroberts9351
    @dylanroberts9351 2 роки тому +1

    How do you get an emoji to appear on your terminal?

  • @coloringforms
    @coloringforms Рік тому

    Why doesnt this work on my .php files, or on ad wordpress project ? Prettier works fine but it doesnt sort any classes

  • @davidgwyer5169
    @davidgwyer5169 2 роки тому +1

    I'm using Tailwind in a Next.js project and couldn't get this to work. Not sure what I'm doing wrong? Anyone else set this up with a Next.js app?

    • @alexandersamokhin
      @alexandersamokhin 2 роки тому

      Check Imran Tailwind Next.js series

    • @davidgwyer5169
      @davidgwyer5169 2 роки тому

      @@alexandersamokhin I've got Tailwind and Next.js working together, just not the class sorting (yet).

    • @megasanjay
      @megasanjay 2 роки тому

      It should work right off the bat. I set it up in my application for nextjs

    • @alexandersamokhin
      @alexandersamokhin 2 роки тому

      @@davidgwyer5169 What about official Tailwind Prettier extension for VSCode? It sorts classes.

    • @davidgwyer5169
      @davidgwyer5169 2 роки тому

      @@megasanjay 🤷‍♂

  • @JesseCollins
    @JesseCollins 2 роки тому

    I can't get it to work with the Panic Nova Prettier plugin which is a huge disappointment. I love Nova, but the lack of plugin support is really a drag.

  • @jairroy222
    @jairroy222 2 роки тому

    How’s the support for using the classnames npm package and with custom tailwind prefixes?

  • @chrislacey89
    @chrislacey89 2 роки тому +1

    How would you integrate this with eslint?

  • @zain.sadaqat
    @zain.sadaqat Рік тому

    If you're here for learning how to setup prettier for TailwinCSS then jump to 3:40

  • @samuelerbo
    @samuelerbo 2 роки тому

    Great video. Thanks!!

  • @yomajo
    @yomajo 9 місяців тому

    0:45 1. Im using flask + tailwind cli. Should I watch the rest?
    How to wrap those goddamn html lines?

  • @chrisdedavid1860
    @chrisdedavid1860 11 місяців тому

    4:30 That did not work for me. Prettier is adjusting the file, but it's not reorganising the classes, nor the styles.
    My .prettierrc file is empty with only "{}"
    I have removed the .prettierignore file, just to make sure it's not that causing it.

    • @chrisdedavid1860
      @chrisdedavid1860 11 місяців тому

      Okay so I see I was missing this, but it still doesn't reorder the tailwind classes, however this did NOT solve the issue
      .prettierrc
      {
      "plugins": [
      "prettier-plugin-tailwindcss"
      ]
      }

    • @chrisdedavid1860
      @chrisdedavid1860 11 місяців тому

      The only way I could get this to work was to use a different prettier plugin "prettier-plugin-tailwind-css"

  • @mattd5419
    @mattd5419 2 роки тому +1

    does it work for components using @apply?

    • @SirDamatoIII
      @SirDamatoIII 2 роки тому

      Extremely pertinent question. Wish there was some straight answers.

    • @Quenjii
      @Quenjii 2 роки тому

      @@SirDamatoIII Is not a matter of just trying it out?

  • @DEVDerr
    @DEVDerr Рік тому

    Sad that it has peer dependency broken in Node 20 and newest version of prettier :/

  • @thieffen
    @thieffen 2 роки тому

    Thanks a lot for this plugin!

  • @hernanmartinezreumann3279
    @hernanmartinezreumann3279 2 роки тому

    Does this work only for Tailwind V3? I can't make it work in my Laravel project with Tailwind 2

  • @Hristovaa
    @Hristovaa 2 роки тому

    Workaround for blade - Blade formatter has a tailwind class sorting option and I still use prettier for the css files to sort the classes with @apply. Anyone has a better solution?

  • @oussamasethoum2755
    @oussamasethoum2755 Рік тому

    I can't get the extension to format the classes in solidjs

  • @aislanarislou
    @aislanarislou 2 роки тому

    How to make prettier break lines for each group of tailwind classes?

  • @proteus1
    @proteus1 2 роки тому

    Imposible to install this. I just can't get it to work even though I didi a step by step install with Visual Studio.

  • @galangaidil9421
    @galangaidil9421 2 роки тому +1

    Whoaaa, this is awesomeee

  • @bassman2145
    @bassman2145 11 місяців тому

    Does anyone know what font is being used in the code editor?

  • @RovelStars
    @RovelStars 2 роки тому

    More videos please!

  • @zrebec
    @zrebec 2 роки тому +2

    Very nice video. Thanks :) It's working also if I'm using in own class in own .css file where I'm using apply? Like: .card { @apply rounded-lg overflow-hidden bg-slate-100 text-black shadow md:shadow-xl lg:shadow-2xl; }

  • @Adrian-ol1uz
    @Adrian-ol1uz Рік тому

    How to change font for "class", "html", "lang" and other html props?

    • @simonswiss
      @simonswiss Рік тому

      I just use a theme (Night Owl) that happens to have _italic_ settings for attributes 👍

  • @valamandar
    @valamandar 2 роки тому

    Hi. Thanks for the video. By the way, I wanted to know, how to style a mail with tailwindcss. It's possible ?

  • @tigerhex
    @tigerhex 2 роки тому

    someone tell me what font he's using in vscode....?

  • @tomchandler2356
    @tomchandler2356 2 роки тому +1

    Which font are you using?

  • @studiokaralis3622
    @studiokaralis3622 2 роки тому +1

    So, this basically replaces Headwind, right?

    • @jenstornell
      @jenstornell 2 роки тому

      I noticed that custom classes are placed last in Headwind and first in the new plugin. I think I like the new approach more. I might switch.

  • @AzNWizzy
    @AzNWizzy 2 роки тому

    Excellent!

  • @Aaron-qy7vb
    @Aaron-qy7vb 2 роки тому

    Is there any way we can set class and modifiers next to eachother?

  • @chronosceptor
    @chronosceptor Рік тому

    Why didn't I see this video before? thanks

  • @JaeTask
    @JaeTask 2 роки тому

    So good, thanks

  • @rickythegermanshepherd5438
    @rickythegermanshepherd5438 2 роки тому

    Yes, Love it ❤️ Thanks for the plugin. (Time to uninstall headwind lol)

  • @mrunknown_811
    @mrunknown_811 24 дні тому

    thank you

  • @animemangas2877
    @animemangas2877 2 роки тому

    Please make a video on how to prevent class copy on production. Thank you

    • @simonswiss
      @simonswiss 2 роки тому

      What do you mean by class copy? Do you mean avoid having multiple elements with the same group of classes in a project? The answer to that is component abstraction. Create one reusable component, where the classes are maintained only once.

  • @misbahansori
    @misbahansori 2 роки тому +1

    Install it globally and no need to worry about setting up a tailwind project...
    npm install -g prettier prettier-plugin-tailwindcss

  • @lifecyclevlog
    @lifecyclevlog 2 роки тому

    Its not working for blade! Any workaround?

  • @ivantorres2494
    @ivantorres2494 2 роки тому

    could someone tell me if this works with attributify classes?

  • @miyanhassanaraien5607
    @miyanhassanaraien5607 2 роки тому

    Thank You!