Josh W. Comeau Profile picture
Sep 13, 2021 8 tweets 3 min read Read on X
🎉 Brand-new blog post just published, all about creating lush, life-like shadows in CSS.

Check it out here:
joshwcomeau.com/css/designing-…

Or, keep reading for some highlights. 👇 Two white boxes with shadows. One has a grey boxy shadow, th
First, I wanna clarify that this isn't all just about aesthetics. It's important to understand *why* shadows are such a powerful tool.

Shadows give our application depth and realism, and let us focus attention by elevating important elements.
In the past, when I wanted to add a shadow, I'd play with the numbers until I liked the way it looked. As a result, I had a mess of incongruous shadows, breaking the overall illusion of depth 😅

We can avoid this problem by understanding how shadows work.
With all of that precursor knowledge out of the way, we can jump to the ✨ effects ✨

We leverage two tricks to enhance our shadows:
• Layering
• Color-matching
Instead of a single shadow, here's what happens if we use 5!

We can play with the offsets and blur radius to create a diffuse, life-like shadow: Two boxes with shadows. One is boxy and fuzzy, the other is
Most devs will use a transparent black as the shadow color. The problem with this is that it desaturates the shadow, leading to a "washed-out" quality.

If we pick a color based on the backdrop, it looks much more lush and natural: A shadow that slightly blends the background color. Labeled A standard shadow, grey and washed out. Labeled "Too grA vivid, glow-like shadow with the words "too bright&qu
This is one of my most value-packed tutorials ever. Seriously, I think you'll learn a ton of good stuff. We cover a bunch of stuff I haven't mentioned here, like how to incorporate these ideas into a design system, and how to add shadows to irregular shapes like a tooltip: A tooltip with a shadow
Read the full tutorial on my blog:
joshwcomeau.com/css/designing-…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Josh W. Comeau

Josh W. Comeau Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @JoshWComeau

Apr 15
About a year ago, Vercel released Next 13.4, becoming the first React framework to be built on top of React Server Components (RSC). ✨

This is really exciting, but also, a bit concerning for folks who use CSS-in-JS libraries like styled-components.

Let’s talk about it. 🧵
The core idea behind RSC is that we can split our components into two types: Server Components and Client Components.

Server Components run exclusively on the server. They don't even get downloaded by the browser!
There's lots of interesting implications for this new architecture, but from a performance perspective, it means that our totally-static components can be omitted from the JavaScript bundle.

If only 20% of our components use state/effects/etc, only 20% will be downloaded!
Read 8 tweets
Feb 13
✨ I just published a brand-new blog post: “How to Center a Div: The Ultimate Guide to Centering in CSS”.

It's interesting, I started this post because I thought it'd be funny, and could serve as a good intro. But it became *so much more* than that!

joshwcomeau.com/css/center-a-d…
I think that my best blog posts are accessible to beginners while still having some gold nuggets for more experienced devs, and I think I've nailed that here. Even if you have years of CSS experience, I bet you'll learn something new. 😄
For example, we compare CSS Grid and Flexbox, and explore a common-but-rarely-discussed footgun. We also explore a *brand new* centering method, one that is only available in pre-release browsers!
Read 4 tweets
Jan 17
I've been experimenting with the native <dialog> element for modals in React. It's pretty good, but there’s one big problem.

It uses the “top layer”, a native browser feature that guarantees it'll sit above everything else. This *seems* like a great idea…
…but sometimes, I need something else to sit above it!

For example, I'm building a “Create coupon” modal. Some of the inputs have little help circles, which can be hovered to show a tooltip.

Those tooltips wind up sitting behind the modal. Totally invisible. 😬 Screenshot of a "Create new coupon" dialog. It shows two inputs, "Name" and "Code". Both have a little help circle next to the input label.
This happens because the tooltip library I'm using, Tippy.js/react, uses “Portals”.

This requires a bit of unpacking.

The ideal tooltip component should work no matter where you need it. I should be able to render a <Tooltip> anywhere in the DOM, and it should show up.
Read 9 tweets
Aug 21, 2023
Question for y'all!

For folks living in countries with significantly lower purchasing power, I offer regional licenses for my courses. The deal is that you can get the course for 35-75% off, but then the course can only be accessed in that region.
Sometimes, someone will buy the course using the regional license, and then they'll move to a higher-cost-of-living country.

My system provides a bit of a grace period, but ultimately, the person would have to upgrade their license to continue accessing the course.
This system is designed to prevent fraud, but it also just feels fair to me. Regional licenses are based on where you live. If you move to a different country, you should get the same deal as anyone else who lives in that country.
Read 5 tweets
Apr 24, 2023
The `const` keyword in JavaScript is used to create a constant. Many of us learn that a constant is a variable that can't change.

And yet, when applied to an object or array, we *can* make changes to it!

Let's dig into this. 🧵 Code snippet:  const person...
The first thing to understand is that variables are *labels*.

I remember learning that a variable was like a box. We create a container called "person" and then drop an object into it. But this isn't the right way to think about it.
Instead, it's more accurate to say “We create an object, and then point a label at it.”

Labels allow us to retrieve data later. Code snippet:  // Create it...
Read 10 tweets
Apr 23, 2023
I'm on bluesky now! Same handle as here 😄 Screenshot of my profile on...
My initial impressions:
• Seems well-built, everything is snappy and reliable so far.
• I wish it had more personality. Feels *super* generic 😬.
• Mobile-only for now, which is sort of a huge problem for the sorts of things I generally share 😅
Will be interesting to see how it develops! For now, I'll continue to use Twitter as my primary social network.
Read 5 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(