Sorting Tailwind CSS Classes Automatically with Prettier

Поделиться
HTML-код
  • Опубликовано: 31 дек 2024

Комментарии • 234

  • @avetisk
    @avetisk 2 года назад +29

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

  • @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 Год назад +51

    👋 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 Год назад

      Timesaver, thank you!

    • @raian_ruku
      @raian_ruku Год назад +1

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

    • @mephdapumkin
      @mephdapumkin Год назад

      Thank you so much!

    • @bennyzen
      @bennyzen 11 месяцев назад

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

  • @lsagar
    @lsagar 2 года назад +48

    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 года назад +76

    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?

  • @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.

  • @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 😅

  • @ibnuhmustofa
    @ibnuhmustofa 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

  • @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? 🤣

  • @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!

  • @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!

  • @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!

  • @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.

  • @buzzer79
    @buzzer79 2 года назад +2

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

  • @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 .

  • @misaka5368
    @misaka5368 2 года назад

    I learned css from tailwind best ever tools love u

  • @Tryto
    @Tryto 2 года назад +1

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

  • @effectic
    @effectic Год назад

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

  • @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!

  • @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

  • @RichReflectionz
    @RichReflectionz Год назад

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

  • @jjrise
    @jjrise 2 года назад

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

  • @devmarkmonster
    @devmarkmonster 2 года назад +1

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

  • @JayPozo
    @JayPozo 2 года назад

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

  • @DaDa-gr7cy
    @DaDa-gr7cy 2 года назад

    Wow, these guys definitely know their game

  • @derektata
    @derektata 2 года назад

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

  • @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?

  • @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

  • @horaciocoronel
    @horaciocoronel 2 года назад +3

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

    •  2 года назад +1

      Good question

  • @moneyfr
    @moneyfr 2 года назад +5

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

  • @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?

  • @skourta
    @skourta 2 года назад

    Been dying for this!!

  • @atanaskanchev6103
    @atanaskanchev6103 2 года назад +2

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

  • @nathandowner6007
    @nathandowner6007 2 года назад

    Awesome utility for the best css utility !

  • @dylanroberts9351
    @dylanroberts9351 2 года назад +1

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

  • @adenreleemmanuel9848
    @adenreleemmanuel9848 10 месяцев назад

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

  • @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

  • @emq578
    @emq578 2 года назад

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

  • @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

  • @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...

  • @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.

  • @wdwaleed
    @wdwaleed Год назад

    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.

  • @saklinemostaq7718
    @saklinemostaq7718 7 месяцев назад

    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?

  • @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
    "

  • @chrislacey89
    @chrislacey89 2 года назад +1

    How would you integrate this with eslint?

  • @BohumilJahoda
    @BohumilJahoda 2 года назад

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

  • @galangaidil9421
    @galangaidil9421 2 года назад +1

    Whoaaa, this is awesomeee

  • @oussamasethoum2755
    @oussamasethoum2755 2 года назад

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

  • @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.

  • @tomchandler2356
    @tomchandler2356 2 года назад +1

    Which font are you using?

  • @nikhil182
    @nikhil182 Год назад

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

  • @chrisdedavid1860
    @chrisdedavid1860 Год назад

    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 Год назад

      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 Год назад

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

  • @cyimanafaisal6800
    @cyimanafaisal6800 Год назад +1

    what if I am using react or nextjs

  • @sanjarcode
    @sanjarcode 11 месяцев назад

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

  • @bassman2145
    @bassman2145 Год назад

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

  • @EvgenyBobkin
    @EvgenyBobkin 2 года назад

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

  • @thieffen
    @thieffen 2 года назад

    Thanks a lot for this plugin!

  • @bestchoice7431
    @bestchoice7431 Год назад

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

  • @yomajo
    @yomajo Год назад

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

  • @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 😅

  • @aislanarislou
    @aislanarislou 2 года назад

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

  • @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.

  • @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?

  • @FONO63
    @FONO63 Год назад

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

  • @Aaron-qy7vb
    @Aaron-qy7vb 2 года назад

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

  • @mrsan385
    @mrsan385 2 года назад

    What's the name of the theme that you are using???

  • @yousafsabir7
    @yousafsabir7 2 года назад +1

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

  • @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

  • @samuelerbo
    @samuelerbo 2 года назад

    Great video. Thanks!!

  • @jairroy222
    @jairroy222 2 года назад

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

  • @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] )

  • @somdobomk
    @somdobomk 2 года назад

    How do you get that extra panel on the right that shows the css at 5:02 ?

    • @sebastianarrieta9678
      @sebastianarrieta9678 2 года назад

      With the Tailwind plugin on vscode

    • @somdobomk
      @somdobomk 2 года назад +1

      ​@@sebastianarrieta9678 Had to check my settings because it wasn't showing for me. Turns out I just had to click the arrow in the menu to show it. 🤦🏼‍♂

    • @simonswiss
      @simonswiss 2 года назад +1

      @@somdobomk Yep there is a little arrow to open the secondary panel. The little cross of the secondary panel will close it when it becomes annoying 😅

    • @sebastianarrieta9678
      @sebastianarrieta9678 2 года назад +1

      @@somdobomk happens to the best of us

  • @UncannyPotato69
    @UncannyPotato69 8 месяцев назад +1

    My prettier doesn't work? Please someone help me

  • @WiziwigeAgario
    @WiziwigeAgario 2 года назад

    Amazing as always

  • @coloringforms
    @coloringforms Год назад

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

  • @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.

  • @DEVDerr
    @DEVDerr Год назад

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

  • @andreibicu5592
    @andreibicu5592 2 года назад

    Can the plugin sort tailwind classes applied in css files ?

  • @tigerhex
    @tigerhex 2 года назад

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

  • @faizalhaziqahmadyani6066
    @faizalhaziqahmadyani6066 Год назад

    hi, how do i set this up on my wordpress project?

  • @zain.sadaqat
    @zain.sadaqat Год назад

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

  • @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 ?

  • @hernanmartinezreumann3279
    @hernanmartinezreumann3279 2 года назад

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

  • @Buffalo_Debile
    @Buffalo_Debile 2 года назад

    How can I make that work with tailwind CDN ?

  • @yousafsabir7
    @yousafsabir7 2 года назад +3

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

  • @xoldyckk176
    @xoldyckk176 2 года назад

    There was a vs code extension called headwind that did automatic class sorting in tailwind css. Is it not recommended to use it now?

    • @trangcongthanh
      @trangcongthanh 2 года назад

      If you're solo dev, use whatever you like. But for consistency across the team, the prettier plugin is better. Because it'll work on CI or git hooks. So your teammate can use whatever IDE/Text Editor they want.

  • @moneyfr
    @moneyfr 2 года назад

    how to do that P+P or *+* all child combinator

  • @rickythegermanshepherd5438
    @rickythegermanshepherd5438 2 года назад

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

  • @ivantorres2494
    @ivantorres2494 2 года назад

    could someone tell me if this works with attributify classes?

  • @Mikkysam52
    @Mikkysam52 2 года назад

    doesn't Headwind vscode extension do that?

  • @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?

  • @neoesm
    @neoesm 2 года назад

    There are no directions on how to configure .prettierrc file to include the tw plugin? A

    • @TailwindLabs
      @TailwindLabs  2 года назад

      Unless you've given your Tailwind config file a custom name/location, you don't need to configure anything for the plugin to start working!

  • @lifecyclevlog
    @lifecyclevlog 2 года назад

    Its not working for blade! Any workaround?

  • @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 👍

  • @stephmunez
    @stephmunez 2 года назад

    Ahhh love this!

  • @swyxTV
    @swyxTV 2 года назад +1

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

  • @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.

  • @ookamiiixd
    @ookamiiixd 2 года назад

    this is really useful

  • @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 🤷‍♂