Floating Labels with Tailwind CSS

แชร์
ฝัง
  • เผยแพร่เมื่อ 29 ก.ย. 2024
  • In this video, you'll learn how to pull off that cool "floating labels" effect using just Tailwind CSS utility classes. We'll use a bunch of new features added in Tailwind CSS v2.2, including the new placeholder-shown variants and the `peer` sibling selector variant.
    Source code: play.tailwindc...
    Tailwind CSS v2.2: blog.tailwindc...

ความคิดเห็น • 150

  • @rfmiotto
    @rfmiotto 3 ปีที่แล้ว +40

    Again, one more awesome material by Tailwind Labs!
    You are a game changer for web developers. I also learned CSS a lot from you.

  • @himanshusrivastava931
    @himanshusrivastava931 3 ปีที่แล้ว +109

    Whenever a new video comes from this channel, first I 'like' the video then I watch it. 😁

    • @themsaid
      @themsaid 3 ปีที่แล้ว +4

      Simon is GOAT

    • @dotkeyz
      @dotkeyz 3 ปีที่แล้ว +1

      Just did now 😁

    • @MrSonicastra
      @MrSonicastra 3 ปีที่แล้ว +1

      Haha i do the same :)

    • @KunalGulati7
      @KunalGulati7 3 ปีที่แล้ว +1

      Hi Himanshu, would like to connect with you on call for some tailwind theme creation if interested let me know.

    • @iamfaizanarif
      @iamfaizanarif 3 ปีที่แล้ว +1

      Same 2 u

  • @pagarevijayy
    @pagarevijayy 3 ปีที่แล้ว +1

    I thought the end of the video will be like.. now tailwind takes care of all of this in our forms plugin lol. Nice video btw!

    • @aislanarislou
      @aislanarislou 3 ปีที่แล้ว

      There is a form plugin ?

  • @alitonoliveira1700
    @alitonoliveira1700 ปีที่แล้ว

    How to make the label go up as soon as I click on the input? The way you showed it only goes up when I start typing.

  • @mohamedyoussef8835
    @mohamedyoussef8835 ปีที่แล้ว

    Awesome video +++++++++++++++ 🙂

  • @AmxCsifier
    @AmxCsifier 3 ปีที่แล้ว

    Is there a way to regroup the variant classes?

  • @habibullah1090_
    @habibullah1090_ 3 ปีที่แล้ว +1

    bad music

  • @yuriyvasilyev7785
    @yuriyvasilyev7785 ปีที่แล้ว +5

    You should never animate “physical” properties such as “top” in your example. It’s not browser-friendly. Use “transform: translateY” instead.

    • @necrotikS
      @necrotikS 6 หลายเดือนก่อน

      You could at least say why, or send the source of this information...

    • @perfect.stealth
      @perfect.stealth 3 หลายเดือนก่อน

      If I'm not mistaken, translate keeps the physical location meaning you can't click the field as the label would be a layer above the field and there by block the click

  • @igdev6095
    @igdev6095 3 ปีที่แล้ว +19

    You guys can add "select-none" and "pointer-events-none" for best experience!

    • @87whateva
      @87whateva 2 ปีที่แล้ว +1

      Thank you very much. That was the missing piece for a great UX!

  • @talgatsaribayev821
    @talgatsaribayev821 3 ปีที่แล้ว +15

    why not use display: flex and change order? Other than that thanks. It is always amazing.

    • @ashutoshanand4263
      @ashutoshanand4263 3 ปีที่แล้ว

      Had the same thought

    • @rfmiotto
      @rfmiotto 3 ปีที่แล้ว +1

      If you ask about the parent div that wraps the input and label tags having a flex col-reverse attribute, I don't think it would fix the problem. This is because the peer will still be listening to the previous sibling in the DOM (that is, in the HTML structure and not necessarily the component you see in the screen).

  • @hariniran6360
    @hariniran6360 2 ปีที่แล้ว +1

    So I have a silent problem where I can't type if I click directly on the peer-placeholder, please help. If I can anywhere else in the input field and it's fine !

  • @joyontokarmakar5765
    @joyontokarmakar5765 2 ปีที่แล้ว +1

    What is the name of your PREVIEW extension??

  • @mc-ty4br
    @mc-ty4br 3 ปีที่แล้ว +9

    Without those screencasts, I'd only know about the basics of tailwindcss. Thank you!

  • @ApoorvMote
    @ApoorvMote 3 ปีที่แล้ว +8

    I have about 20 forms on my site. This is going to dramatically change everything. Thanks Tailwind.

  • @isaaccloos1084
    @isaaccloos1084 3 ปีที่แล้ว +9

    Yooo, that shot at the end was great 👍🏻

    • @simonswiss
      @simonswiss 3 ปีที่แล้ว

      My son just read that! ✨ Thank you 🙏

  • @flanger001
    @flanger001 ปีที่แล้ว +6

    You entirely changed my mind on this pattern. I hated this when I first saw it because it was always implemented some buggy JS that interfered with password managers. But a pure CSS implementation? Absolute genius. Thank you 💜

  • @beni0208tube
    @beni0208tube 2 ปีที่แล้ว +2

    For the label => "pointer-events-none"

  • @DongQian
    @DongQian 3 ปีที่แล้ว +3

    I hope tailwindcss can write multiple classes to one pseudo-classes. For example hover:[text-red-500, bg-white, ...] instead of repeat `hover:` again and again, it makes the class name list way too long. I think there are libraries that help with this, but I would like to see it as build-in support. Thanks

    • @thomasfindlay2034
      @thomasfindlay2034 3 ปีที่แล้ว

      I asked Adam about it recently, but unfortunately, he said that it's not going to be added.

  • @andreich1980
    @andreich1980 3 ปีที่แล้ว +4

    Great stuff! I did this just the other day. Some more of UX improvements: add this classes to labels `pointer-text pointer-events-none`.

  • @breezycodes
    @breezycodes 2 ปีที่แล้ว +2

    How do you get your classes to stay on different lines?

    • @MOGE_
      @MOGE_ 7 หลายเดือนก่อน

      press enter

  • @AndreNitschke
    @AndreNitschke 2 ปีที่แล้ว +1

    Nice Workflow, but is this with the label after input not a problem for screen-readers?

    • @AndreNitschke
      @AndreNitschke 2 ปีที่แล้ว

      aria-labelledby in input field with id from label - should solve this problem. Nice

  • @belledonne
    @belledonne 2 ปีที่แล้ว

    My head hurts so much trying to combine this with the ugly yellow background of the autofillers... and simple form...
    Anyway, great tutoriel, thanks !

  • @nick97000
    @nick97000 3 ปีที่แล้ว +2

    Lovely video and definitely going to implement this solution. How would you handle autocomplete? When I hover over an autocomplete option, the labels and the filled in values appear on top of each other!

  • @sarbajitacharjee1195
    @sarbajitacharjee1195 2 หลายเดือนก่อน

    When Your Cat step on your keyboard .. The easiest solution is Delete miss typed and see what was written 😎😎

  • @swyxTV
    @swyxTV 3 ปีที่แล้ว +4

    Simon you’re crushing it. Love the demo and the editing and the music!

    • @simonswiss
      @simonswiss 3 ปีที่แล้ว +1

      Thanks! 🙏 Yeah I am slowly getting the hang of it all 🎉

  • @mc-ty4br
    @mc-ty4br 3 ปีที่แล้ว +2

    Without those screencasts, I'd only know about the basics of tailwindcss. Thank you!

  • @ShaharHarshuv
    @ShaharHarshuv 9 หลายเดือนก่อน +1

    Amazing!

  • @Nate-gi7no
    @Nate-gi7no 2 ปีที่แล้ว

    anyone have a problem with not being able to click through the labels to focus the input? am i doing something wrong?

  • @EdzonmxDev
    @EdzonmxDev ปีที่แล้ว

    Hello, Please How are you ?
    Please i can have the name of your VS Code Font...

  • @samueljagestedt6479
    @samueljagestedt6479 4 หลายเดือนก่อน

    seems like a ux problem that the user can't click the placeholder to focus the input.

  • @RyanRampersad
    @RyanRampersad 3 ปีที่แล้ว +3

    This is really great. Thanks for making a video on it. The pattern is popular and while I think it looks funny and actually more confusing, I understand why people like it!

  • @BharatKumarDhaker
    @BharatKumarDhaker 3 ปีที่แล้ว +1

    Cool tips, I was looking this for days, -- One thing left in there I think, -- cursor ---> label in text area cause issue to override the cursor-text -- so the solution is --> label default & peer-focus 'cursor-default' and in peer-placeholder-shown it should be cursor-text

  • @mohakmaheshwari8756
    @mohakmaheshwari8756 2 ปีที่แล้ว

    Peer class is not working anymore plz help.

  • @mbparvezme
    @mbparvezme 2 ปีที่แล้ว +1

    Awesome design by an awesome tool. A suggestion for a little improvement in the terms of UX. Class "cursor-text" for the label would be really good to make a fluent UX feel.

  • @jimmyj.6792
    @jimmyj.6792 3 ปีที่แล้ว +1

    Holy crap this awesome tip 😍 thanks a lot 😀😀 accessibility power 💪

  • @Laratips
    @Laratips 3 ปีที่แล้ว +1

    Mind blowing. Doing this only with css is just amazing.

  • @nicktaylor1613
    @nicktaylor1613 ปีที่แล้ว

    So you basically have to define the same classes to every single input field on the form? This feels VERY repetitive to me..... if you have a form with 5+ fields - you'd need to do the same classes on every single input field...... am I missing something here?

    • @Valyssi
      @Valyssi ปีที่แล้ว

      If you're using tailwind, you're probably also using some sort of component based framework/library like React, Vue Svelte etc, in which case you'd make each field a component, define their classes once within the component, then use those components different places.
      That said I'm not a big fan of using tailwind for complex components. I'd rather create BEM classmates and declare their CSS in a dedicated CSS file

  • @Yaxqb
    @Yaxqb 2 ปีที่แล้ว +6

    This is insane and i would never in my life want to implement this in raw css
    Bravo!!!

  • @PixelRubble
    @PixelRubble 2 ปีที่แล้ว +1

    Fantastic trick for text boxes. Do you have a similar trick for drop downs in order to keep page styling similar?

  • @hcsftw
    @hcsftw 3 ปีที่แล้ว +1

    Hi Simon, instead of absolute you could have used flex on the div and order on the input and label to fix this.

  • @kukasn
    @kukasn ปีที่แล้ว

    What of select input anyone help me with that

  • @io_inc
    @io_inc 4 หลายเดือนก่อน

    I like this, simple and minimalistic

  • @quotesspace1713
    @quotesspace1713 2 ปีที่แล้ว

    add "cursor-text" on the label

  • @mdekramulhassanavi1819
    @mdekramulhassanavi1819 ปีที่แล้ว

    Thank you it's help me a lot.

  • @mamtaagarwal1009
    @mamtaagarwal1009 3 ปีที่แล้ว +1

    Tailwind is just getting better. Let's go

  • @ObviouslyProgrammer
    @ObviouslyProgrammer ปีที่แล้ว

    Thank you this is so nice!

  • @khaledelhoushi8834
    @khaledelhoushi8834 ปีที่แล้ว

    In 4:14c you were typing "class="absolute left-0 -top-3.5(grey image)text-gray-600 text-sm"". Does this code act like CSS or is it the code in the CSS portion or file affecting the webpage?

  • @shafu_xyz
    @shafu_xyz 3 ปีที่แล้ว +1

    JIT has made tailwindcss even better!

  • @Habesha_Today
    @Habesha_Today ปีที่แล้ว

    your vscode font?

  • @ayobamijimoh4953
    @ayobamijimoh4953 2 ปีที่แล้ว

    awesome, thank you

  • @mouradaouinat8721
    @mouradaouinat8721 3 ปีที่แล้ว +1

    Brooop

  • @MOGE_
    @MOGE_ 7 หลายเดือนก่อน

    naaaaaaah I thought i knew tailwind before watching this video. I could literally feel my proverbial tailwind skill bar go up as I watched this.

  • @Sabutofons
    @Sabutofons 3 ปีที่แล้ว

    I am using vscode prettier extension but it doesn't format my tailwind classes to use multiline like it did for Simon. Am I missing any settings?

  • @jamesgrubb
    @jamesgrubb 2 ปีที่แล้ว

    Thanks great information. I had to add a class for when the form is actually filled in ' .label:not(:empty) {
    @apply -top-5;
    }'

  • @kumardeepam
    @kumardeepam ปีที่แล้ว

    this is so sleek

  • @dharyelsantoshonorio5890
    @dharyelsantoshonorio5890 ปีที่แล้ว

    awesome! thanks!

  • @HayuiokNauio
    @HayuiokNauio ปีที่แล้ว

    Bye2 library 😂

  • @SusanthCom
    @SusanthCom 2 ปีที่แล้ว

    Awsome Video

  • @mass-im
    @mass-im ปีที่แล้ว

    Great content as always! Tnx!!!
    Is it possible to move the styles into an @layer @apply directive?

  • @iamsiddd007
    @iamsiddd007 3 ปีที่แล้ว

    When I click label it doesn't work. Is that supposed to happen or did I do something wrong. If anyone knows please let me know.

  • @subhranshudas8862
    @subhranshudas8862 ปีที่แล้ว

    black magic.

  • @mnik0128
    @mnik0128 2 ปีที่แล้ว

    Instead of -top-3.5 u can make parent 'flex flex-col-revese' or use order class for positioning

  • @sharvinpingulkar3844
    @sharvinpingulkar3844 ปีที่แล้ว

    Thank you! You solved my issue and changed my thought process on how to approach this kind of issue. Keep smashing!

  • @sll-q8l
    @sll-q8l ปีที่แล้ว

    Very Good!

  • @mansourahmed3841
    @mansourahmed3841 3 ปีที่แล้ว

    VS Code Auto-Complete Tailwindcas not working

  • @xidnebwoz
    @xidnebwoz ปีที่แล้ว

    Awesome!

  • @vigneshwaranrenganathan7743
    @vigneshwaranrenganathan7743 ปีที่แล้ว

    great work, is it possible to bring same effect using and ?

  • @paulalexander796
    @paulalexander796 2 ปีที่แล้ว

    Gozu :)

  • @MrSonicastra
    @MrSonicastra 3 ปีที่แล้ว

    Cool Simon, i was looking today for that on TH-cam! I'm glad i found it 😁. Lifesaver, thumps up.

  • @telegramvideos1313
    @telegramvideos1313 2 ปีที่แล้ว

    I'm commited to learn new tailwind trick every day, this is the trick for today.. Thanks !

  • @noobparty4282
    @noobparty4282 10 หลายเดือนก่อน

    Hello. What text editor do you use? It looks really cool.

  • @HassanHajX
    @HassanHajX 3 ปีที่แล้ว +1

    How did you do the wavy red lines ? Is it possible to do that with just tailwind ?

  • @ExtraServingsBTS
    @ExtraServingsBTS 3 ปีที่แล้ว

    keep this up and I'll be able to fire all my designers..... muahahahahaha

  • @EkySambora
    @EkySambora 2 ปีที่แล้ว

    Great tutorial

  • @ed1nh0
    @ed1nh0 3 ปีที่แล้ว

    Wondering if there some attr or prop, or even a behavior I could not use a class for it!

  • @AndresMarquezOk
    @AndresMarquezOk 2 ปีที่แล้ว

    The best effect is 7:14 "pru".. Great video! Thanks!!!

  • @Sashankyt
    @Sashankyt 3 ปีที่แล้ว

    I am not getting the peer-placeholder selector in the tailwind docs. It is sometimes hard to know what is available and what not.

  • @NeerajKumar-mm4rl
    @NeerajKumar-mm4rl 3 ปีที่แล้ว

    Simon, which font family you are using in code editor. Subscribed 😀

  • @alfredomontoya4087
    @alfredomontoya4087 2 ปีที่แล้ว

    Excellent work and explanation, thank you very much for everything.

  • @ahmadabuaysheh
    @ahmadabuaysheh 3 ปีที่แล้ว

    is this available in the documentation?? I tried to search for it but couldn't find it.

  • @jeffnikelson5824
    @jeffnikelson5824 2 ปีที่แล้ว

    you're a magician man
    just found out about tailwind and every day I'm more and more convinced
    thank you so much

  • @LRXAORLOV
    @LRXAORLOV 3 ปีที่แล้ว

    This is very cool) how can I improve accessibility for such a solution ?

  • @gamingklex9010
    @gamingklex9010 3 ปีที่แล้ว

    Are you always making these small templates before the video, or where are you getting these?

  • @osman3404
    @osman3404 3 ปีที่แล้ว

    Omg that’s awesome but i wish that was the default of placeholders to Begin with

  • @DanielDrummond2k6
    @DanielDrummond2k6 2 ปีที่แล้ว

    Do you intend to create courses on Tailwind 3.0 or do you already have one?

  • @mitchellchrist5372
    @mitchellchrist5372 3 ปีที่แล้ว

    great approach to floating labels, but i hate how much bloat tailwind adds

  • @lucasj.pereira4912
    @lucasj.pereira4912 3 ปีที่แล้ว

    Does it work in any browser or only recent versions? Asking because some css options does not work in older browsers

  • @deephousefridays1911
    @deephousefridays1911 3 ปีที่แล้ว

    I wish I could add more than one like! Awesome videos!

  • @aislanarislou
    @aislanarislou 3 ปีที่แล้ว

    Now a video teaching how to make a ripple effect into buttons : )

  • @FrederickROS
    @FrederickROS 3 ปีที่แล้ว

    Super good content as usual. I hope your ribs are going to cure soon!

  • @daretobedangerous6552
    @daretobedangerous6552 ปีที่แล้ว

    your tutorials are amazing! cheers mate

  • @modprog
    @modprog 2 ปีที่แล้ว

    you can also use a space in the placeholder IIRC

  • @vinayrwt
    @vinayrwt 3 ปีที่แล้ว +1

    Waiting for it 😂

    • @azam920
      @azam920 3 ปีที่แล้ว

      Yeah waitingable videos 😅👍👍

  • @__su_man
    @__su_man 2 ปีที่แล้ว

    Can anyone tell me, which font is this?

  • @hauladv
    @hauladv 3 ปีที่แล้ว

    where is peer?

    • @jimmyj.6792
      @jimmyj.6792 3 ปีที่แล้ว

      To enable `peer` class, you need to be in : mode: 'jit' into your tailwind.config.js

  • @cristianpallares7565
    @cristianpallares7565 3 ปีที่แล้ว

    Nice! Thanks for the video. Learned something new

  • @GustavAgar
    @GustavAgar 3 ปีที่แล้ว

    excellent 🙌 make more videos please

  • @nyambe
    @nyambe 2 ปีที่แล้ว

    wooo 😘, will be using it

  • @notfadeaway6617
    @notfadeaway6617 ปีที่แล้ว

    i like these small detail tricks

  • @Zoutzuurtjes
    @Zoutzuurtjes 3 ปีที่แล้ว

    What theme are you using?