It’s incredible to see what we can do with CSS today, especially if you still remember how difficult it once was to figure out stacking contexts or why margins collapsed and why top: float didn’t work. In this post, we’ll look at just that: exciting and fun things we can do with CSS, exploring common problems and use cases we all have to face in our work.
Richer, Life-Like Shadows With CSS
Shadows help convey meaning and add extra value to a UI. Unfortunately, many shadows we see online don’t realize their true potential. Let’s make this change!
Rob O’Leary offers a deep dive into shadows. Rob O’Leary provides a comprehensive look at shadows in his article CSS Tricks. He explains how light influences shadows as well as how to identify a light source. This is the basis for creating shadow effects. After that foundation is established, shadows can be used to create depth and elevate elements. You’ll also learn how to layer shadows and which CSS properties to use depending on the use case. Rob also discusses the accessibility, performance and animation implications of shadows.
Regular vs. irregular shadow. A subtle change creates more depth.
Another fantastic article on the topic comes from Josh W Comeau. Josh W Comeau has a great article on this topic. He describes how ordinary shadows can be transformed into lifelike boxes. This little detail makes any interface feel tactile.
CSS Paper Cut-Out Effect
If you’ve ever tried to make a paper-cut effect as a header, it might be a difficult task. Perhaps you need to set up two separate divs that then would be overlapped on top of each other. It might prove difficult to determine the spacing in relative units.
CSS paper cut-out, using a pseudo-element as well as a data attribute
Stephanie Eckles’ CSS Paper Cut-Out Effect solves the problem for good with CSS custom properties, CSS Grid, CSS transforms and a good ol’-fashioned CSS function attr. Stephanie is using a data-attribute on h1 along with a span inside it. attr picks up the value of the data-attribute, which is then used for the content-property in a :after-pseudo element. CSS Custom Properties allows you to adjust the highlights, shadows, and colors. It is easy to reuse and maintain.
If you’re interested in even more magic from Stephanie and the other amazing people who love CSS take a peek at StyleStage. Here modern CSS is given all it needs.
What is CSS and what should we do with SVG? Ahmad shares his strategies for achieving the cut out effect.
Lastly, check out Ahmad Shadeed’s article on Thinking About The Cut Out Effect. It covers all aspects of when SVG makes more sense and how it can be implemented in real life. You will also find plenty of examples in the article.
The Minimap For The Web
We’ve all seen them: the tiny horizontal bars at the top and bottom of pages. The horizontal bar fills up as the user scrolls down. This allows the user to see how far he has left.
What if we make it a bit more contextual though? It could be that the page contains images, videos or quotations. Wouldn’t it make sense to put them in a different context? Rauno Freiberg also thought so.
A minimap that is more context-sensitive for the internet? Rauno Freiberg offers a suggestion.
Rauno’s minimap for the web (currently works only in Firefox) makes it trivial to create a minimap representation of the entire page, while also allowing readers to pin section of the page and navigate between them. To achieve it, Rauno uses an experimental CSS property element to display a live image from an arbitrary HTML element (which currently only available in Firefox).
Conditional Border Radius In CSS
When designing cards, you might want a border-radius to have a quite sizeable value when there is enough space to display it along with other cards. Yet when there is no space and perhaps no margin either on the card — as it might be the case on smaller screens — you might want to reduce border-radius to 0. What is the best way to do that?
Imagine if the border radius of smaller screens could be reduced while it was larger for larger screens. Ahmad offers a solution.
Ahmad Shadeed has gone into great detail about this issue in his article Conditional Border Radius in CSS. Heydon Pickering, Naman Goel and others suggested that a sufficient number be used to cause one or both states. On smaller screens, if the difference between 100vw and 100% is 0, then the radius will be 0, too; but if the difference is larger, a larger value would be used. The CodePen is also available.
More after jump! Continue reading below |
CSS Grainy Gradients
What if you wanted to add some noise to bring a bit of texture to an image? You could also export the images as WebPs or AVIFs. However, we would prefer to “noise” SVGs to give them some texture. We can turn off and on noise if necessary.
A grainy texture can be added to any gradient. Jimmy Chion demonstrates how it works.
In his CSS-Tricks article about grainy gradients Jimmy Chion describes how to create colorful noises to give texture to gradients using CSS and SVG. Jimmy explained that the trick is to apply the noise to a background using an SVG filter. We layer the noise underneath a gradient and then refine brightness and contrast. Voila! A gradient that slowly fades.
Issue solved! Jimmy also has a Grainy Gradient playground.
Multi-Line Background Gradient
Some things may seem impossible with CSS, but that is until someone discovers a way to make them possible.
Some things might seem impossible to do with CSS. But, until someone finds a hack that makes it possible.
This multi-line background gradient was created using CSS. (Large preview
Yes, as Matthias Ott shows. Matthias Ott shows us how to solve this problem. Although it is somewhat hacky, the pseudo-element is what allows you to get the desired results. This is a great idea that you can play with.
Form Field Focus Without Outlines
Who said that forms had to be dull? Hakim El Hattab has created an example that shows that even simple forms like those asking for your name and email can be fun and provide a chance to spark joy.
Form field focus concepts that go beyond the norm. Large preview
To achieve this, Hakim blends form focus with validation in an elegant animation that is subtle but surprising. It does not have any focus lines on the fields. Instead of a focus dot, it marks the focused field with a dot. The animation kicks in when the focus changes to another field. When that happens, the dot moves to the active field and draws a link between them. The integration of form field validation works seamlessly with the dot expanding to show a checkmark and also showing it. Hakim has also posted a Codepen demo if you want to dig deeper into the code. It’s inspiring!
Transitioning CSS Gradients
If you have ever attempted to change gradients using CSS, then you will probably know that it doesn’t work. The change from one gradient to the next is not gradual, but abrupt. There’s no smooth transition.
CSS Transitioning gradients Keith J. Grant shares his clever solution. (Large preview).
As Keith J. Grant has discovered, we can achieve the transition with a clever workaround though. For this, we use an opacity and pseudo-element transform. We first apply one gradient, position the pseudo-element and fill in the element with the second. We then “transition” between the two gradients, by changing the transparency of the pseudo-element. CodePen has a working example.
Improving Image Performance With image-set
Have you heard of image-set already? You can think of it as a CSS background equivalent to the HTML srcset attribute for img tags. It has been supported by Chromium and Safari for many years, while Firefox only recently added it to their web browsers. Ollie Williams looks at the possibilities and limitations of this technology today.
image-set can be used to serve different background images to different users. Large preview
As Ollie describes, one use case for image-set is to provide multiple resolutions of a background image and leave it to the browser to decide which image is served to a user — a high-res version for users on fancy devices and a lower-res image for those on slow connections or screens with a lower pixel density, for example.
Another very promising use case is still lacking browser support, unfortunately: the idea to use new image formats like AVIF, WebP, or HEIF while adding a fallback for older browsers. If you want to achieve something like that already today and don’t need background-image, the element might be an alternative worth considering, as Ollie suggests. This article will help improve your image performance.
Clip-Path Pop-Out Effect
With clip-path: path supported by major browsers, it’s time to get creative. Mikael Alinalem shows you a wonderful use for this feature. It’s a smooth pop-out effect that is buttery and creamy.
A pop-out effect created with clip-path: path. Large preview
Mikael uses clip-path: path to set a photo of a person apart from its circle-shaped background. The person appears to appear as if they are rising from within the circle. This creates a 3D effect. This is a great page for the “About Us” section.
Whimsical 3D Button
Details matter. It’s not difficult to design a beautiful button. Josh Comeau went all out to create a whimsical, 3D button you will want to click multiple times.
Josh Comeau has a technique that will allow you to press a 3D button over and over. (Large preview).
The idea behind is to create two layers, and then offset the front layer slightly. The front layer is moved down when hovering. Then, we adjust the focus outline with outline-offset, or use :focus:not(:focus-visible) to hide the outline when the button is focused and the user is using a pointer device.
Next, we move the button up a little bit when the user hovers, animate the transformation a bit, adjust Bezier curve to animation, and blurring the shadow to make it look softer. And voila — we have a whimsical 3D button that is accessible, works on mobile and on desktop, and is a pleasure to tap and click on. Josh has the code in full.
CSS Charts
Perhaps you need to design a column chart, or a bar chart, or even a multi-dataset column chart or stacked columns. You don’t know where to start. Perhaps with Charts.css, a CSS data visualization framework that uses CSS utility classes to style HTML elements as charts.
Charts.css, a CSS framework that allows data visualization to be done in modern CSS is available. (large preview)
Created by Lana Gordiievski and Rami Yushuvaev, the framework supports many chart types, has no dependencies, and is very lightweight. The framework also contains detailed documentation about its components, built-in charts types and the source code can be found on GitHub. It is licensed under MIT. Preethi also explains how you can create CSS Charts that have interesting shapes using CSS-Tricks.
The New CSS Reset
What do you use to normalize styles across browsers? Recent developments have allowed for a smaller global CSS reset. These new methods may be able to normalize styles across browsers.
Andy Bell shares his strategy to reduce the CSS reset. (Large preview).
Andy Bell’s Modern CSS Reset has reduced the CSS reset by setting box-sizing rules and removing default margins. It also sets core root defaults and body defaults. Along with it Andy removes all animations, transitions, and smooth scroll for people that prefer not to see them, and has added modern properties like scroll-behavior and text-decoration-skip-ink by default.
The New CSS Reset by Elad Schechter is a bit more aggressive. Elad removes all the default styles which we are getting on specific HTML elements except the display property. These two approaches are well worth considering!
Ah, layout shifts! As Bramus Van Damme explains, one of the slightly more obscure reasons for layout shifts comes due to different types of scrollbars on the web. While overlay scrollbars on iOS/macOS are placed over the content (and aren’t shown by default), other scrollbars are placed in the “scrollbar gutter”, i.e. The space between the inner edge of the border and the outer padding edges.
Bramus Van Damme demonstrates how scrollbar gutters can prevent content shifting. (Large preview).
If the contents of a box become too big, the browser will defaultly show a scrollbar. It will also cause layout shifting in this case. This problem may soon be solved. Meet a shiny new scrollbar-gutter property: by setting it to stable, we can have the browser always showing the scrollbar gutter, even if the box is not overflowing.
And to keep things symmetric, we can use scrollbar-gutter: stable both-edges. This feature isn’t yet available in Chromium, however it will be very soon. Other rendering engines may follow soon.
The Surprising Things That CSS Can Animate
When you think about animating CSS properties which are most likely to come up? Will Boyd approached the question differently and explored the properties not often associated with animation but that can be animated.
Animating overlapping cards with z-index is one of the surprising things that CSS can do. Large preview
Will explores the surprising animatable properties of CSS in his article “The Surprising things that CSS can animate”. He also discusses how animating these properties allows you to do some really cool stuff. z-index, for example, can be used for layered animations, opacity helps you fade out a modal just with CSS. This is a great example of the power and versatility CSS has.
Learning Resources
Learning never stops, right? We have compiled these fun and useful resources. — resources that are perfect to take your CSS skills to the next level. Even if you are a CSS expert, there are challenges that will put your skills to the test. Enjoy!
CSS Vocab And Cheatsheets
You might be there. Just when you are working on a tight deadline, you need to look up something quickly. You can’t go wrong with CSS Tricks Almanac. Also, Ville V. Vanninen has compiled a list of CSS vocabulary.
CSS Vocabulary will help you to find the correct words for CSS. (Large preview).
Learn Flexbox The Fun Way
What do frogs, zombies, and towers have in common? They are your friends in Flexbox. Let’s face it: Flexbox can be very powerful once we understand it. But, getting there can prove difficult. Let’s make learning Flexbox a little more enjoyable.
Flexbox is easy to learn with the help of some friendly frogs. (Large preview).
In the game Flexbox Froggy, you help a little frog and its friends find their lilypads by, you guessed it, writing CSS. The game consists of 24 levels that take you from the very basics of Flexbox positioning to more advanced challenges.
If zombies appeal to you more, Flexbox Zombies might be for you. Each section of the game unravels part of the plot, introduces a new Flexbox concept, and presents so-called “zombie survival challenges” that help you solidify your new skills.
Last, but certainly not least: Flexbox Defense. Inspired by tower defense games, your job is to stop incoming enemies from getting past your defenses — by positioning your towers with CSS, of course. You can play all three of these games right from your browser. Flexboxing is fun!
CSS Grid, CSS Selectors, And Other Competitions
Do you want to improve your CSS skills? You can do that with these three games. In Grid Garden, you’ll become the proud owner of a carrot garden. 28 levels are waiting for you in which you need to take good care of your crop with the help of CSS grid.
CSS Battle allows you to test your CSS skills. (large preview)
CSS Diner: If you think your CSS selection skills are lacking, CSS Diner will help you. Plates, apples, pickles — in each of the 32 challenges, you’ll need to use a different CSS selector to select specific items on a table.
And if you want to compete, check out CSSBattle. In the CSS golfing game, you’ll be using your CSS skills to visually replicate targets with smallest possible code to get to the top of the leaderboard. Each of the challenges is dedicated to a specific topic like visibility, display, transition, or z-index.
Wrapping Up
Have a CSS resource or technique changed how you approached a specific challenge recently? Please share your experience with us in the comments section below. Let us know what you think.

