Body Toggle

I appreciate the clarity of this trick that Mikael Ainalem posted over on Reddit: It’s a one-liner that toggles the class on the so you can mock up different states and toggle between them on click.

https://css-tricks.com/body-toggle/

Created 4y | Jul 6, 2021, 10:20:56 PM


Login to add comment

Other posts in this group

Should the CSS light-dark() Function Support More Than Light and Dark Values?

The light-dark() function is currently designed to support just two color schemes. Should it support others? Sunkanmi Fafowora says yes and no.


Sep 2, 2025, 3:10:13 PM | CSS tricks
CSS Elevator: A Pure CSS State Machine With Floor Navigation

In this article, author Chris Sabourin walk through how modern CSS features can build a fully functional, interactive elevator that knows where it is, where it’s headed, and how long it’ll take to

Aug 29, 2025, 1:40:16 PM | CSS tricks
A Radio Button Shopping Cart Trick

Here's an approach for animating products added to a shopping cart that handles an infinite number of items using a variation of the ol' Checkbox Hack.


Aug 27, 2025, 3:20:41 PM | CSS tricks
Getting Creative With Images in Long-Form Content

Images in long-form content can (and often should) do more than illustrate. They help set the pace, influence how readers feel, and add character that words alone can’t always convey.


<p

Aug 25, 2025, 7:20:11 PM | CSS tricks
3D Layered Text: Interactivity and Dynamicism

In this third and final chapter, we’re stepping into interactivity by adding JavaScript, starting with a simple :hover effect, and ending with a fully responsive bulging text that foll

Aug 22, 2025, 2:40:37 PM | CSS tricks
3D Layered Text: Motion and Variations

In this chapter, we will explore ways to animate the effect, add transitions, and play with different variations. We will look at how motion can enhance depth, and how subtle tweaks can create a wh

Aug 20, 2025, 2:10:10 PM | CSS tricks
3D Layered Text: The Basics

A client asked me to create a bulging text effect. With a bit of cleverness and some advanced CSS, I managed to get a result I’m genuinely proud of, which is covered in this three-part series.

Aug 18, 2025, 3:40:13 PM | CSS tricks