CSS can do that?
Ananya Neogi

Ananya Neogi @ananyaneogi

About: Frontend dev amongst other things.

Location:
localghost:3000
Joined:
Oct 9, 2018

CSS can do that?

Publish Date: May 17 '19
1912 125

A list of amazing things that CSS can do!

EDIT: Some of these properties won't work in some browsers because of support. We can check for browser support using @supports and add fallback styles accordingly. Please use Chrome to view the examples 🙂

1. box-decoration-break

This CSS property specifies how an element's fragments should be rendered when broken across multiple lines, columns, or pages.


2. attr()

We can retrieve values of the selected element in CSS by using attr(). This method could be really helpful with accessibility purposes.


3. backface-visibility

This CSS property sets whether the back face of an element is visible when turned towards the user. Thinking of a card flip UI?


4. conic-gradient

Gradients are a wonderful thing. You might've used to style backgrounds with linear gradients but do you know we can use pure css to create pie charts with the help of conic-gradient!

To better understand how conic-gradients, reference the MDN docs on it


5. filter

Who needs photoshop filter effects when you have CSS filters. 🙃
Filter functions applies graphical changes to the appearance of an input image. The effects we can achieve are as follows - blur, brightness, contrast, grayscale, hue-rotate, opacity, invert, sepia, saturate, drop-shadow.

drop-shadow filter is pretty amazing. It lets you apply drop shadow to the input image.


6. mix-blend-mode

This CSS property sets how an element's content should blend with the content of the element's background or its parent.


Amazing things can be achieved by mixing blend modes and filters with images and text. Learn more on MDN Docs.


7. first-letter

One of my favourite things in books and magazines are the beautiful drop-caps. We can create drop with first-letter pseudo-element.


8. shape-outside

This CSS property provides a way to customise wrapping adjacent inline content around complex objects rather than simple rectangular boxes.


Open the example in a different tab and try changing the width of the window and notice how the text wraps around the image.


9. writing-mode

This CSS property sets whether the lines of text are laid out horizontally or vertically. We can have these values-

  • horizontal-tb - Content flows horizontally from left to right, vertically from top to bottom.
  • vertical-lr - Content flows horizontally from left to right, vertically from top to bottom.
  • vertical-rl - Content flows horizontally from right to left, vertically from top to bottom.

Checkout this this example to see it in action.


10. Adding gradient to text

This is achieved with the combination of -webkit-background-clip: text and -webkit-text-fill-color: transparent CSS properties.


11. Smooth scroll snap

scroll-snap-type CSS property sets how snap points are applied on the scroll container.

This example shows vertical(y) scroll with value mandatory. MDN docs does a great job on explaining how to use other values such as proximity and horizontal scroll(x).


These are just a few great things CSS can do. Possibilities are endless! 🥳

Comments 125 total

  • Hasan TEZCAN
    Hasan TEZCANMay 17, 2019

    It was a seminal article. Thanks 😄

  • Guillaume Martigny
    Guillaume MartignyMay 17, 2019

    The conic-gradient blew my mind !

  • Ajmal Noushad
    Ajmal NoushadMay 18, 2019

    Wow, that's awesome.

  • Paul O
    Paul OMay 18, 2019

    very cool, but i wonder though how well supported these are across browsers. thanks for showing the examples.

    • fluffy
      fluffyMay 18, 2019

      You can use caniuse to see how well-supported things are, and a great thing about CSS is it tends to gracefully degrade anyway.

  • Crystal Schuller
    Crystal SchullerMay 18, 2019

    The filters one had me yelling at my screen. Excellent list - definitely one I'll save.

  • Vijay Jangid
    Vijay JangidMay 18, 2019

    Intresting, some of them I haven't heard. Loved the gredient text color and pie chart.
    Thanks for digging and sharing with us.

  • Nyenye
    NyenyeMay 18, 2019

    This is really helpfull in so many situations! Thanks for sharing!

  • Anand Kumar
    Anand KumarMay 18, 2019

    Very nice.
    Recently i tried mix-blend-mode but due to some strange reason, it did not work on one of my android phone chrome browser. Worked on others. So, the point is to make sure it works for you on supported platforms.

    • Ananya Neogi
      Ananya NeogiMay 18, 2019

      Yes, of course, we should always to check for browser support. But the good thing about CSS is that we can always add fallback styles in cases where our desired css properties are not supported. If a property is not supported CSS won't throw out errors, it will silently cascade to other styles so adding fallback styles works out of the box.

  • Kenold Beauplan
    Kenold BeauplanMay 18, 2019

    Great tips! Thanks for sharing.

  • Vasilis Zoumpourlis
    Vasilis ZoumpourlisMay 18, 2019

    First time I see most of these attributes. And they look great. Thank you!

  • Jakub Sarnowski
    Jakub SarnowskiMay 18, 2019

    Be aware that rendering-heavy properties like filter are not too good for performance when you have a lot of images out there.

    • Ananya Neogi
      Ananya NeogiMay 19, 2019

      Yes, coding is all about trade offs. So it all depends on use cases ☺

    • Adam Crockett 🌀
      Adam Crockett 🌀May 22, 2019

      You have to admire the hidden power though. SVG filters are a science into themselves and can be used with this CSS property.

      Anyway do you know of any benchmarks?

      • Jakub Sarnowski
        Jakub SarnowskiMay 23, 2019

        Don't have any data to show you, just words from experience and checking this stuff on private projects.

        What I've found is that CSS filters performance drops are most visible when you're using them in animations. It can really screw up the UX. And when using it just for initial display - on high-end PC-s you might not even see the difference, but it's certainly noticeable on mobile devices.

    • Ben Evans
      Ben EvansJul 1, 2019

      Agreed, definitely do not use too many advanced CSS attributes like this: codepen.io/ivorjetski/pen/dBYWWZ

      • َ
        َSep 29, 2019

        thanks for the tip!

      • MrSid
        MrSidSep 10, 2020

        That's awesome 😍😍😍

    • Devang Hingu
      Devang HinguFeb 12, 2020

      you're abosolute right.!!

  • Pablo
    PabloMay 18, 2019

    Hey this is an awesome article. Thank you!

    Here's an awesome take on Interstellar theme that goes great as background music while trying out these css tricks

    youtu.be/IuEEEwgdAZs

  • Vishang
    VishangMay 18, 2019

    Good reading. I am just wondering about the browser compatibility.

  • Nick Taylor
    Nick TaylorMay 18, 2019

    Great post Ananya! I wasn't aware of some of these properties, e.g. backface-visibility. Looking forward to your next post. 🔥

  • Anthony Wayne Smith (AJ)
    Anthony Wayne Smith (AJ)May 18, 2019

    Some very cool stuff, I look forward to playing with some of this.

  • Yair Lopez Poveda
    Yair Lopez PovedaMay 18, 2019

    Weird, does box-decoration-break only applies its effect when affected element is resized?

    Interesting post btw

    • Ananya Neogi
      Ananya NeogiMay 19, 2019

      I'm not sure what you mean by when element is resized.
      box-decoration-break gets applied when the text breaks into next line.

      • Ben Sinclair
        Ben SinclairMay 21, 2019

        I can't really tell from the article what that property is supposed to do. The other examples all have different states so you can compare one with another.

  • Cody Shaner
    Cody ShanerMay 18, 2019

    Great post, very practical and fun.

  • Manish Kumar
    Manish KumarMay 18, 2019

    Great read. got to know a lot of new things in CSS. filters are amazing. Thanks for sharing

  • Sam Rose
    Sam RoseMay 18, 2019

    This has blown my mind. Thank you so much for sharing! :)

  • Victor Mbamara 🇳🇬
    Victor Mbamara 🇳🇬May 18, 2019

    Wow, I'm trying out these properties right now

  • sadhac
    sadhacMay 19, 2019

    Nice one. I didnt know CSS was so powerful!

  • rhymes
    rhymesMay 19, 2019

    Wow! Great article, thank you! Some are really really cool!

    ps. conic-gradient doesn't work on Firefox (but I saw the result on Chrome).

    • Ananya Neogi
      Ananya NeogiMay 20, 2019

      Thanks! 🙂
      Yes, I agree browser compatibility is an issue as with so many other features on the web but with CSS we can easily check support with @supports and add fallback styles accordingly. If a property is not supported CSS won't throw out errors, it will silently cascade to other styles so adding fallback styles works out of the box.

      • Mitch Pirtle
        Mitch PirtleMay 30, 2019

        I'm viewing this content through the latest stable build of Firefox, and see a lot of broken image icons. Not sure degradation is working as expected.

        With Google deliberately breaking ad blockers in future Chrome versions, there are likely going to be a lot more Firefox users sooner than later.

  • deji adesoga
    deji adesogaMay 19, 2019

    This is really impressive. Great post Ananya. Looking forward to your next article.

  • Juneau Lim
    Juneau LimMay 19, 2019

    Wow, Many of them I didn't know. Thank you for the amazing post!

  • dshreyas11
    dshreyas11May 19, 2019

    You have done a fantastic job to put it back for community. Thank-you. It's a must save list in mind!

  • Raajkumar Subramaniam
    Raajkumar SubramaniamMay 19, 2019

    Great post Ananya! Really love that the fact that all these could be done without writing any javascript code. Would be really help if you can comment about cross browser compatibility for these CSS tricks. Thanks for sharing

  • Vicki Langer
    Vicki LangerMay 20, 2019

    That's pretty neat. I had no clue you could add filters or text gradients via css.

  • S.R. Aman
    S.R. AmanMay 20, 2019

    Great article. 2nd one is amazing.

  • Luca Uliana
    Luca UlianaMay 20, 2019

    Nice article Ananya. Thanks.
    I say almost every day in my work: with CSS you can do what the f*** you want, about layout & similar. Stop.

  • Fabio Russo
    Fabio RussoMay 20, 2019

    first-letter ... that's so cool.
    I love that kind of stuff, I will use this as soon as possible.

    Thanks a lot for this article!

  • Luiz Fellype Cassago
    Luiz Fellype CassagoMay 20, 2019

    Article really cool!!

  • Hamza Hamidi
    Hamza HamidiMay 20, 2019

    Interesting.

  • Frank W.
    Frank W.May 20, 2019

    Very interesting, I didn't know many of the functions at all. But I will use some of them in the future. Great post

  • Kriti Rai
    Kriti RaiMay 20, 2019

    Mind-blown! :o

  • Adam Crockett 🌀
    Adam Crockett 🌀May 20, 2019

    I'm fairly certain that CSS content and by extension attr() is not read by most screen readers + browser combination, being part of presentation rather than real content. I'd reconsider the recommendation unless I'm wrong then find tell me to pipe down. 😁

    • Sara Marie
      Sara MarieMay 21, 2019

      If what you're doing is purely decorative or there is accompanying text, etc., then no, it's not a, "You can't use it because it's inaccessible." There's certainly use cases for CSS content, for example, that are perfectly fine. It just depends on their use.

      • Adam Crockett 🌀
        Adam Crockett 🌀May 21, 2019

        Not what I'm saying. And I quote "This method could be really helpful with accessibility purposes." This is not true.

        In the codepen example the tooltip will never be explained to blind users, so in affect, sighted users will get the context but not the blind user. So I stand by what I said. CSS content should be used with care.

        Also this is not an I'm right your wrong, I'd love to be wrong because I'd use content more and JavaScript solutions less. Instead this is an ask to remove the quoted text because there is a lot of confusion on how to do accessibility.

    • Ananya Neogi
      Ananya NeogiMay 21, 2019

      From accessibility point of view I meant that when we add such content like tooltip on hover, what we can do is add the content in aria-label which will be read by the screen reader and then make use of the samearia-label through are CSS with attr() for the normal flow. In that way we can have consistent content throughout.
      Probably should've explained better 🙂

      • Adam Crockett 🌀
        Adam Crockett 🌀May 21, 2019

        Hi Anya, thanks for the post, do you mean like this?
        Case 1

        <p>hello a11y text, important info</p>
        

        Case 2

        <p aria-label="hello a11y text"><!--hello a11y text-->important info</p>
        
        p[aria-label]::before {
            content: attr(aria-label);
        }
        

        Case 1 reads "paragraph, hello a11y text, important info"

        Case 2 reads "paragraph, hello a11y text" only but displays the same as case 1.

        If it where me, I would stick to a JavaScript solution with real markup, role and avoid aria-label at all costs, good UX and good content do not need aria-label.

        • CraftyMiner1971
          CraftyMiner1971Aug 11, 2019

          aren't the 'aria-label' tags outdated now?

          • Adam Crockett 🌀
            Adam Crockett 🌀Aug 11, 2019

            No? aria-label attributes still very much a day to day support attribute. They are just not great to use unless you have to, your markup should describe your SR journey without needless overides. Do you have any specification to suggest they are out of date?

  • Levon98
    Levon98May 21, 2019

    3 and #4 are breaking in firefox, most likely engine related.

  • Swashata Ghosh
    Swashata GhoshMay 21, 2019

    This is so cool, thank you very much :)

  • Nenad Kaevik
    Nenad KaevikMay 21, 2019

    That conic-gradient effect is cool but has very limited cross-browser usage... Good post though :)

  • Davyd McColl
    Davyd McCollMay 21, 2019

    Informative article! Thanks!

    I especially like the scroll-snap-type -- always thought I needed javascript for this.

    The conic gradient codepen doesn't seem to be doing anything (Firefox Nightly) -- I just see a white page. What am I missing?

    • Mwenimpako P.
      Mwenimpako P.May 21, 2019

      Use Chrome. I'm on the latest mobile release and it works

      • Davyd McColl
        Davyd McCollMay 21, 2019

        No. "Use some other browser" isn't a solution. Especially when that other browser is Chrome.

        Web standards exist for a reason -- if this only works in Chrome, it's nice to know what to avoid; however, your reply has led me to the answer I was looking for: having a look at MDN, Chrome and variants are the only browsers to support this, meaning it's not ready for web consumption.

  • Subramanya Shenoy
    Subramanya ShenoyMay 21, 2019

    Internet explorer : NOPE NOPE NOPE NOPE!!

  • Tamb
    TambMay 21, 2019

    I had no idea about the scroll snapping. That's friggin amazing!

  • Kumar Abhirup
    Kumar AbhirupMay 21, 2019

    Wow, worth bookmarking this!

    • Ananya Neogi
      Ananya NeogiMay 21, 2019

      These examples are really great! 🙂

      • smakosh
        smakoshMay 21, 2019

        Thank you! just shared your article with my co-workers!

  • rugk
    rugkMay 21, 2019
  • rugk
    rugkMay 21, 2019

    BTW some feedback about this:

    1. "Please use Chrome to view the examples". Seriously? Let's better design for the web (i.e. standards) not for (one particular) browser. There is no reason to make a website "only supported by browser XY", as it sometimes has been done in the past. So don't get used to this, but use feature detection. In this demos, it would have been enough to mark which demos work with which browser. (actually, you mostly just need to mark those few, that don't work.)
    2. In the end you did it once, but if you had linked to MDN for each property, that would increase my curiosity to dive into the CSS property even more… 😄
    • Sara Marie
      Sara MarieMay 21, 2019

      There is no need to be so harsh. You can give critical feedback without coming off this way. Also, the author did give the info in the article that some of these properties are not fully cross-browser yet, but that should not bar authors from talking about them.

      • rugk
        rugkMay 21, 2019

        Sorry, did not mean to be harsh. If this is what you've read it as, I apologize. This just makes me upset a little, because browser diversity is important.

        Yes, it's mentioned, but as I said: Don't get used to it (=creating for one browser).

      • Ananya Neogi
        Ananya NeogiMay 21, 2019

        Thanks Sara! 🙂

    • Ananya Neogi
      Ananya NeogiMay 21, 2019

      We shouldn't limit ourselves as developers and shouldn't be afraid to try out new things. If one browser doesn't support a certain property we can always add a fallback and make use of new capabilities on the browser that does support the property. We don't shy away from adding non-supported javascript on browser by adding polyfills and feature detection methods then why should we shy away from trying new capabilities in CSS.

      And by stating - "Please use Chrome to view the examples", I am not advocating Chrome only websites but the reason was simple enough so that people can actually see the examples.

      • rugk
        rugkMay 21, 2019

        Okay, fine. Understood. And obviously, I agree with your polyfill/fallback part.
        Anyway, I keep my point that sentences like these ("use XY for viewing this!") create a bad incentive/habit. Anyway, it gets off-topic, so let's agree to disagree. :)

  • Tramel Jones
    Tramel JonesMay 21, 2019

    Wow - Amazing!

  • BhanuSingh
    BhanuSinghMay 21, 2019

    A good collection to apply on the next landing pages I develop next.

  • Steffen Pedersen
    Steffen PedersenMay 21, 2019

    I fucking love this post ❤️ Even though I know most of these, I love that you are sharing the power of CSS 😉

  • Roland Taylor
    Roland TaylorMay 21, 2019

    Thanks! Very useful tips here!
    Added to my bookmarks for later.

  • Jecsham
    JecshamMay 21, 2019

    Amazing 👏👏👏

  • Ben Halpern
    Ben HalpernMay 21, 2019

    Amazing post Ananya! It really blew up!!

    Looks like Redditors came to nitpick. Nice job being positive 😄

    • Ananya Neogi
      Ananya NeogiMay 21, 2019

      Thanks Ben! 🙂 It did blow up beyond my expectations. 😅

  • Emma Bostian ✨
    Emma Bostian ✨May 21, 2019

    Awesome post!

  • Sanon Joas
    Sanon JoasMay 22, 2019

    The scroll-snap-type property just saved me from a lot javascript lines of code.
    Thank you for this post!!

  • Kristóf Dombi
    Kristóf DombiMay 22, 2019

    conic-gradient is awesome, I've been looking for it for a few months now. Thanks for the article!

    It's a pity that it's only supported by Chrome yet, but the future is bright! 😌

  • Max Ong Zong Bao
    Max Ong Zong BaoMay 22, 2019

    Awesome :) I really didn't know that CSS has the flipping of picture function

    • Ananya Neogi
      Ananya NeogiMay 22, 2019

      Just to be clear backface-visibility doesn't directly flip. The flipping is achieved by the combination of transform and backface-visibility. 🙂

  • aleBiagini
    aleBiaginiMay 22, 2019

    Like this so much! Thanks!

  • Quốc Bảo
    Quốc BảoMay 22, 2019

    great article! Thanks you very much...

  • YuanHao Chiang
    YuanHao ChiangMay 22, 2019

    Great article Ananya -- I had no idea of half or more of these CSS properties! It's great to see CSS taking over typical things that we had to do in Photoshop like drop shadow on an image and now even filters.

    Thanks for sharing! 🎉

  • l0l0l0l
    l0l0l0lMay 22, 2019

    This is really cool.

  • John Angel
    John AngelMay 22, 2019

    Lovely thanks Ananya!

  • Shernz
    ShernzMay 24, 2019

    Awesome. Thanks for sharing!!!

  • 🎧Cirphrank👣
    🎧Cirphrank👣May 25, 2019

    Don't I just love this lady already, thank you for the new library.

  • naijadeveloper
    naijadeveloperMay 26, 2019

    I didn't know these properties existed, thanks for sharing. 😊🙂

  • Ibrohim Hanafi
    Ibrohim HanafiMay 27, 2019

    Like background-clip, scroll snap..
    Great article

  • Martijn ᗢ
    Martijn ᗢMay 27, 2019

    Some of these things are webkit/blink only, so those are not that great.

  • cjmascareno
    cjmascarenoMay 28, 2019

    backface-visibility, my favorite one!

  • Bernd Wechner
    Bernd WechnerMay 28, 2019

    Some nice things here but like others I'd prefer to read such lists with only stable well supported features not browser specific stuff, that needs fallbacks. Just my preference as I'm interested in building sites that just work and while I'm happy to expect people to gave basically the latest browser in their context, I am not interested in asking them to use a particular browser (that defies the freedom of the web for me).

  • Brad Dougherty
    Brad DoughertyMay 29, 2019

    I had never heard of box-decoration-break, that's really cool!

    FWIW, all of the examples work in Safari. Everything but conic gradient and scroll-snap work in Firefox also. The backface-visibility example will work everywhere if the -webkit-prefixed version is added (for Safari) and the non-prefixed version to .flip-card-inner (for Firefox).

  • dsfsfrec
    dsfsfrecJun 18, 2019

    it's easy

  • Katie Adams
    Katie AdamsJul 3, 2019

    This was great! Learnt loads of interesting CSS techniques that I'm definitely looking into.

  • Mohamed Hussain
    Mohamed HussainJul 13, 2019

    Thanks for the article on what css and HTML can simply do without the Js.....

  • zoebourque
    zoebourqueAug 21, 2019

    Neat!I never know CSS can do filter! Wow! Thank you!

  • Aref Khandan
    Aref KhandanOct 14, 2019

    Wow, actually im going to use "Smooth scroll snap" in my proj right now! thank you

  • Marco Chavez
    Marco ChavezDec 17, 2019

    I just learned about the text gradient the other day! Thanks for sharing, always fun to learn about CSS and it's expansive capabilities.

  • Jang Rush
    Jang RushJan 8, 2020

    Hi, I'd like translate this amazing tutorial to Chinese. Can you give me the permission? The translated text will be published on nextfe.com. Thanks in advance.

    • Ananya Neogi
      Ananya NeogiJan 9, 2020

      Hey! Sure, you can translate it as long as you link back to the original post :)
      Do share the link once it's published.

  • colotuna
    colotunaJan 8, 2020

    very Nice, well job friend

  • sebastiano
    sebastianoJan 24, 2020

    I am learning, thanks! 👏👏👏

  • khalil Chermiti
    khalil ChermitiApr 14, 2020

    awwwww thank you so much for this great post, i just save it so that i can recheck it later <3

  • Louis Low
    Louis LowAug 12, 2020

    Very insightful !

  • Shashwat Verma
    Shashwat VermaApr 9, 2021

    Dope

  • Makar
    MakarJun 27, 2022

    I thought I am good at CSS... before reading this

Add comment