Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Surprising things that CSS can animate (2020) (codersblock.com)
295 points by asicsp on Jan 21, 2023 | hide | past | favorite | 47 comments


I always love seeing tricks like this from designers but then I never see anything this cool on the web otherwise. Where do all these great designers work and why don't I ever get to see the products they make?


If you browse Awwward-winning websites, you quickly realise that they are annoying to browse.

Most of the time, I'm just trying to read text and get an answer. Everything that is not text, formatting or typography gets in the way.


You can have exquisite presentation with good choices of text, formatting and typography (including judicious use of colour, spacing and even animation and textures). A luxury printed book full of beautiful details will feel much better than a cheap paperback.

The best techniques can be applied in subtle ways to improve the overall presentation, without resorting to flashy showcases.


I agree with you. I'd love to see good examples of that, because I struggle to create that sort of websites.

For example, how would you redesign the Python docs to feel like a beautifully typeset book does?


Information can be beautiful on its own, if you follow some common patterns about contrast, clustering and hierarchy. These are based on the principles of Gestalt [1] which engineers can learn without having artsy skills by watching books and courses specific for us, e.g. [2].

Do you know about Edward Tufte? His work doesn't revolves specifically about software, but his principles show how to present technical information in the clearest way, and his books [3] are beautiful examples on how to put a technical topic in book form with clean and beautiful layouts.

[1] https://www.interaction-design.org/literature/topics/gestalt...

[2] https://medium.com/bigcommerce-developer-blog/design-for-dev...

[3] https://www.edwardtufte.com/tufte/books_vdqi


A lot of Python docs are in fact pretty well designed to resemble a book without completely breaking the fluidity of the web page. They use serif fonts, apply font weights and colors subtly. In fact I think they strike the right balance between just being a regular webpage and completely succumbing to the constraints of the book as media.

https://flask.palletsprojects.com/en/2.2.x/


This is a beautifully done blog. The author works at Square, according to his info page: https://codersblock.com/about/


https://medium.com/bridge-collection/3d1b0a9b810e Stripe using animations back in 2014.


Because these animations only work in rigidly specified isolated static objects. Because god forbid any animation touches layout.

Well, many of those animations like opacity changes and border animations undoubtedly force the browser to re-layout and repaint the entire screen anyway. So on an actual page you'll se stutters, frame drops and ungodly CPU usage.

The only animations that will (barely) work is the `transform: translate` ones as they usually preserve the layout, and can be composited on the GPU.


> Well, many of those animations like opacity changes [...] undoubtedly force the browser to re-layout and repaint the entire screen anyway.

Depends on the rendering engine. With Blink opacity, filter, and transform will skip past layout and paint after the first render.

Chrome Dev Summit 2018: https://youtu.be/AB9qSUhlxh8?t=754


> With Blink opacity, filter, and transform will skip past layout and paint after the first render.

Thanks! Didn't realize opacity was mostly fixed. In my head it as still very problematic because I know that opacity changes are very frowned upon by device manufacturers (like smart TVs). The reasons are actually mentioned in the video:

- they "don't trigger layout and can often bypass paint" (so paint isn't always bypassed)

- "compositing is not free. If you are on resource constrained devices, you really need to watch your composited layer count"

The vast majority of devices in the world out there are resource constrained: cheap smartphones are ubiquitous. But then there's also things like smart TVs etc. Hence my reaction to opacity changes :)


What do you think of The Pudding (https://pudding.cool/)? They make beautiful “visual essays”. Unlike some fanciful animated sites, I feel like The Pudding’s design and animation complement the text to make the result ‘greater than the sum of its parts.


Half of these don't work on safari even in a isolated demo. Compatability is probably a big reason


Yeah, I too had fun with CSS and curvy circular text animation.

https://egbert.net/blog/index.html

(Sorry, web access is only HTTP/1.1-3, TLSv1.3 and ChaCha-only, no Chrome access possible)


Why the weird cypher requirements? Blocking like 65% of users seems like a very weird choice.


Weird because that's the strongest setting used with the fewest (zero) vulnerabilities there.


But it's not supported by Chrome? Why not use a cyphersuite that is supported and also has zero vulnerabilities: TLS_AES_128_GCM_SHA256


I would be repeating myself.


It's weird being able to highlight animated text like this


It's very cool that on Android the text selecting tabs will even rotate around too with the text


Nice website (not just the cool animated motto).


Interesting how so many of these didn't work in Safari in 2020, but all of them do now. Good progress for interoperability, I guess.


They didn’t work for me on Safari mobile.


They do for me, on iOS 16.2. Are you using any content blocker that might interfere?


> You could use a bit of JavaScript with setTimeout to get rid of the modal at the right time

This always felt hacky to me, "animating" visibility instead is a great idea. Thanks for sharing!


There's also a way to do it on exactly the right frame: https://developer.mozilla.org/en-US/docs/Web/API/Element/tra...


That's been a thing for almost a decade now. I don't do much CSS anymore but I think not enough people have been using it


Thanks for mentioning this, I never knew you could do this, that would make my hacky CSS+JS animations a lot less hacky :D.



I watched all of those animations on Safari. The constant reminder that you wouldn't see anything on Safari had me doubt my sanity.


It's because the post is from 2020


The only thing that didn't appear to work for me was the code selection. It would only allow selecting the whole code block, and not toggle to allow selecting only a portion. Other than that the animations appeared fine to me as well.


Those CSS animations would be a success in the web of the old days. Reminds me of the whole rounded borders thing: all those hacks and loops to make it work in all browsers (transparent images in the corners, lol), and then finally when there's wide browser support, rounded borders were already out of fashion


That's usually the point of fashion

Meta-fashionistas add a deliberate Stilbruch (style-break)


None of the examples in the article work with js disabled.

I'll say more generally, that as much as I love all the cool things CSS is capable of these days, I think it's gotten to the point where now I want a CSS blocker the same way I block ads and JS by default, ideally something that lets me enable only a sane subset of CSS while blocking everything else.

I keep meaning to write one for firefox, but I really don't have the time, and I'm honestly hoping somebody comes along and beats me to it.


This reminds me of the time I removed tyres from my car’s wheels. I want the predictability of my horse drawn cart back. A wheel breaks, I just take a hammer and some nails to it. Galvanised rubber and metallurgy is something I don’t understand so it must be bad.


> This reminds me of the time I removed tyres from my car’s wheels. I want the predictability of my horse drawn cart back. A wheel breaks, I just take a hammer and some nails to it. Galvanised rubber and metallurgy is something I don’t understand so it must be bad.

I understand CSS and I've done a fair bit of webdesign myself. CSS has evolved to the point where it can be used abusively. Hell, some consider it turing complete (https://github.com/brandondong/css-turing-machine).

CSS can be used for ads, fingerprinting, and exploits. There are perfectly valid reasons for wanting a little less functionality while still allowing for some basic styling.

I mean, it's cool that there are computer games written in pure CSS and other neat tricks, but sometimes you just want a browser to behave itself even in hostile spaces. If that makes my heavily locked down browser a "horse drawn cart" I'm happy to trot forward.


> None of the examples in the article work with js disabled.

Some because of Codepen.io embeds? The ghost and pricing tables should work on their own.


Codepen is certainly part of it. Lots of boxes with nothing inside but centered text saying things like "See the Pen Spooky Boo! by Will Boyd (@lonekorean) on CodePen."

Nothing on that page animates for me, although I'm sure that's my fault. CSS should work, but I've got a whole lot more than just JS disabled in this browser too. For what it's worth I tried to search the page for the words "ghost" "table" and "price" and couldn't find any mention.


Not sure what sort of person downvoted you. I, too, have an issue with a page about CSS tricks requiring JS.

I may write JS for a living but I do browse the internet without it

Edit: someone downvoted you again as I was writing this, heh. Is this even a healthy thing to do on a Saturday morning


Probably because: "i did something unspecified and now it doesn't work" is kind of an annoying comment. More to the point, nobody promised that the page doesn't use javascript, just that the techniques presented do not need js in principle.


It's just weird to me how often people who have their own websites and are perfectly capable of self-hosting demos of things that don't require javascript make the decision to instead use a website to showcase them that requires JS to work or be visible at all.

I fully understand my configuration is unusual. I don't think it's unusual to expect that a certain number of people who don't use JS would be interested in a site that offers cool CSS tricks that don't require it, so it's strange to see those same people being unnecessarily excluded. To the writer's credit they have some source available in their article at least.


"Doctor, it hurts when I do this"

...


The most amazing imo is the `d` attribute of an svg <path> element


Fun fact about SVGs: you can drop-shadow an SVG and it will work fine. See https://poggers.website


Not the only surprising thing about CSS.


The path to shit started with the `<blink>` GI.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: