35 Cool Line Patterns & Stripe Backgrounds (Pattern Textures)

Post pobrano z: 35 Cool Line Patterns & Stripe Backgrounds (Pattern Textures)

Line patterns bring movement and texture to design that can direct the eye and heighten visual interest.

Line Patterns Line Patterns Line Patterns

If you are looking for awesome line patterns for your next project, check out these terrific designs from Envato Elements.

Unlimited Cool Line Patterns & Stripe Backgrounds 

Envato Elements offers thousands of top-quality patterns, backgrounds, mockups, logos, photos, fonts, and much more.

Unlimited Cool Line Patterns & Stripe BackgroundsUnlimited Cool Line Patterns & Stripe BackgroundsUnlimited Cool Line Patterns & Stripe Backgrounds

And for one low monthly fee, you can download as many of these digital assets as you like, as often as you like. Let’s take a look at some of the terrific line patterns and stripe background textures available from Envato Elements

35 Cool Line Patterns & Stripe Backgrounds

Textured Background Stripes (PSD)

Background StripesBackground StripesBackground Stripes

When you need a cool background with stripes for your next project, look no further than this stunning collection. It contains 24 different backgrounds which are easy to customise by adjusting the hue and saturation controls.

Floral Background With Stripes (Vector, EPS)

Background with StripesBackground with StripesBackground with Stripes

Floral Background With Stripes offers exactly what it says in the title: a collection of six backgrounds that combine horizontal stripes and flowers. You can modify the files to suit your needs and resize them without loss of quality.

Line Pattern Texture (Vector, EPS, AI, PNG)

Line Pattern TextureLine Pattern TextureLine Pattern Texture

Line Pattern Texture contains 40 hand-drawn lines created with pens, brushes, and ink that offer an authentic craft feel. The files are offered in seamless vector patterns.

Waves Texture Background Lines (AI, EPS, JPG, PNG)

Texture Background LinesTexture Background LinesTexture Background Lines

When you need a stylish and eye-catching background for a special project, choose Waves Texture Background Lines. The pack contains ten vector files that are fully editable in Photoshop and Illustrator.

Stripe Vector Background (PSD)

Stripe Vector BackgroundStripe Vector BackgroundStripe Vector Background

Looking for texture lines with a touch of grunge? How about Stripe Vector Background? It includes six different backgrounds that are perfect for posters, banners, websites, presentations, etc.

Line Pattern Design (Vector, EPS)

Line Pattern DesignLine Pattern DesignLine Pattern Design

Line Pattern Design is quite a bit more subtle than the other textures we’ve shared so far. This one offers a monochromatic look that relies on light and shadow to create that sense of texture in 3D.

Black and Grey Striped Background (PSD)

Black and Grey Striped BackgroundBlack and Grey Striped BackgroundBlack and Grey Striped Background

Black and Grey Striped Background functions in a similar way to the pattern above. The biggest difference is that it uses different tones of grey to create a sense of texture and contrast.

Watercolour Horizontal Stripe Pattern (Vector, EPS, JPG, PNG)

Horizontal Stripe PatternHorizontal Stripe PatternHorizontal Stripe Pattern

Watercolour is simply irresistible, and when you want to create a dreamy background for your projects, Watercolour Horizontal Stripe Pattern is an excellent choice. The files are all vectors and are very easy to customise.

Abstract Stripes Texture (PSD)

Stripes TextureStripes TextureStripes Texture

Every great project needs a great background, and that’s exactly what Abstract Stripes Texture offers. Use the 12 files included to create backgrounds for your print and web projects. 

Retro Geometric Stripe Pattern (Vector, EPS, AI, PNG)

Geometric Stripe PatternGeometric Stripe PatternGeometric Stripe Pattern

Retro Geometric Stripe Pattern deviates a bit from the theme but is still relevant to it. This collection features colourful and seamless patterns that you can customise using your favourite software.

Sunset Lines Seamless Stripe Pattern (AI, EPS, JPG, PNG)

Seamless Stripe PatternSeamless Stripe PatternSeamless Stripe Pattern

This collection of 40 seamless hand-drawn patterns includes 20 digital papers with gold textured patterns. Use this collection as backdrops to your special projects or apply them in whatever way supports your design.

Abstract Geometric Vector Texture Lines (AI, EPS, JPG, PDF, PNG)

Texture LinesTexture LinesTexture Lines

Feast your eyes on this terrific abstract geometric pattern that presents a kaleidoscope of colours. The collection contains ten different styles that will bring a bit of pizazz to your projects. 

B&W Geometric Stripe Pattern (PNG)

Geometric Stripe PatternGeometric Stripe PatternGeometric Stripe Pattern

B&W Geometric Stripe Pattern is as complex and eye-catching as it gets. Use the PNGs the project contains to create your own unique designs.

Abstract Line Texture Backgrounds (PSD)

Line TextureLine TextureLine Texture

When you need the nuance of stripes rather than an obviously striped effect, choose Abstract Line Texture Backgrounds. The backgrounds are offered in 12 colour combinations that will increase the visual interest in your projects.

Zigs & Zaggers Cool Line Patterns (PNG)

Cool Line PatternsCool Line PatternsCool Line Patterns

This digital art pack of six bold and captivating patterns is just what you need to take your designs to the next level. Use it for fabric, gift paper, flyers, posters, etc.

Black and Grey Striped Background (PSD)

Black and Grey Striped BackgroundBlack and Grey Striped BackgroundBlack and Grey Striped Background

Black and grey—or white—is a winning combination, and this pack offers 15 different ways to please you with its exciting range of black and grey designs.

Colour Stripe Vector Background (PSD)

Stripe Vector BackgroundStripe Vector BackgroundStripe Vector Background

How about Colour Stripe Vector Background for those times when you want to create terrific gift wrap, wallpaper, covers for notebooks, crafting projects, etc. There are 24 design variations in the collection, so you’ll have plenty of variety to keep you happy.

Seamless Stripe Pattern (Vector, AI, EPS, JPG, PNG, PSD)

Seamless Stripe PatternSeamless Stripe PatternSeamless Stripe Pattern

Black and white never looked so good as in this collection of 12 Seamless Stripe Patterns. The files are offered in AI, EPS, JPG, PNG, and PSD, so choose your favourite software and get to work customising your designs.

Abstract Stripe Texture Backgrounds (PSD)

Stripe TextureStripe TextureStripe Texture

Turquoise and Light Slate Blue are a dreamy colour combination, and that’s just one of the ten different backgrounds presented in Abstract Stripe Texture Backgrounds. Download the pack, choose the one you love the most, and get to work incorporating it into your design.

Line Patterns (PSD)

Line Patterns Line Patterns Line Patterns

With a whopping 39 backgrounds made up of three unique backgrounds and 13 colour variations each, Line Patterns is a great choice for mobile and desktop wallpaper, websites, packaging, and more.

3D Stripes Texture Background (PSD)

Stripes TextureStripes TextureStripes Texture

Who says stripes need to be straight? No one! And that’s why we’ve included this bold collection. Have fun creating your own projects with this unique background. 

Hand Illustrated Stripe Pattern (Vector, EPS, PNG)

Stripe PatternStripe PatternStripe Pattern

This collection offers two variations of the three tileable line patterns of chevrons, waves, and straight lines shown in the photo. The files are offered in both PNG and EPS formats.

Reina Pattern Stripe (PSD, PNG)

Reina Pattern StripeReina Pattern StripeReina Pattern Stripe

Reina Pattern Stripe offers a collection of 18 bold designs that are perfect for collage, crafting, masking, fabric prints, web app backgrounds, etc. 

Floral and Striped Background Pattern (JPG)

Striped Background PatternStriped Background PatternStriped Background Pattern

Need background patterns for scrapbooking? Check out this collection of 12 watercolour patterns. The package includes six seamless striped patterns and six seamless patterns of flowers, leaves, feathers, and hearts.

Metallic Stripes Background (PSD)

Metallic Stripes BackgroundMetallic Stripes BackgroundMetallic Stripes Background

Go metallic when you use this collection of cool metallic pattern stripe backgrounds. The set contains six high-res files that can be used for print and web.

Blue, Red and Grey Line Pattern Texture (JPG)

Line Pattern TextureLine Pattern TextureLine Pattern Texture

Blue, Red and Grey Line Pattern Texture is a bit of a departure from the other stripe vectors shared here so far, and that’s why we’ve included it. A great tech corporate background for relevant projects.

Texture Background Lines (Vector, EPS, JPG)

Texture Background Lines Texture Background Lines Texture Background Lines

Texture Background Lines is just what you need when you want to harness the vibe of the future. There are ten vector and hi-res JPGs included in the collection.

Geometric Stripe Pattern (Vector, AI, EPS, JPG)

Geometric Stripe PatternGeometric Stripe PatternGeometric Stripe Pattern

It doesn’t get more modern and cool than the Geometric Stripe Pattern Collection. It offers six patterns in both black and white in AI, EPS, and JPG format.

Black & Grey Line Pattern Texture (JPG)

Line Pattern TextureLine Pattern TextureLine Pattern Texture

Black & Grey Line Pattern Texture may not be as trendy as some of the other backgrounds shown here, but that’s what makes it so successful. It balances visual interest with subtlety to create a great foil for the main attractions of your work.

Glitch Line Pattern Design (JPG, PNG)

Line Pattern DesignLine Pattern DesignLine Pattern Design

Glitch Line Pattern Design captures the dynamic motion of light rays combined with gradients. The collection offers this one concept in ten different colour schemes. 

Sirena Stripe Texture (JPG)

Sirena Stripe TextureSirena Stripe TextureSirena Stripe Texture

Here’s a line texture with a difference. Sirena Stripe Texture contains ten different designs, all of which are easy to customise to suit your needs.

Colorful Spark Backgrounds (JPG)

Colorful Spark BackgroundsColorful Spark BackgroundsColorful Spark Backgrounds

Create a colourful spark in your own design when you use Colorful Spark Backgrounds for your background. This stunning multicoloured starburst of lines is a great choice for your project.

50 Pattern Backgrounds50 Pattern Backgrounds50 Pattern Backgrounds

Strong and bold, 50 Pattern Backgrounds is a great addition to your toolbox. With 50 designs to choose from, you will never run out of ideas.

Colourful Background Stripes (PSD)

Colorful Background StripesColorful Background StripesColorful Background Stripes

The Colorful Background Stripes PSD looks like a crazy and colourful slide, and that dynamic will transfer to your work when you incorporate it into your projects.

Line Texture (JPG)

Line TextureLine TextureLine Texture

With three unique backgrounds and 13 colour variations, this collection of line textures is a great addition to your projects. The templates can be used in a wide variety of ways, so don’t hesitate to download them and get to work.

Choose Your Favourite Striped Background Pattern 

Now that you know where to find the best striped background patterns when you need them, head to Envato Elements and download your favourite pattern today. 

If you’re interested in learning how to create your own background patterns from scratch, or you want to find more patterned templates, check out these articles from Envato Tuts+:

Tips & Tricks for Cutting Small Letters With Cricut

Post pobrano z: Tips & Tricks for Cutting Small Letters With Cricut

Final product imageFinal product imageFinal product image
What You’ll Be Creating

Being able to cut super small things with your Cricut machine is one of the most fun things to do, and it’s probably a large reason why many people buy these machines. But it can also be so frustrating when you don’t get it right, so I am here to help you to get the best cut and to show you some of the best fonts to use on Cricut for small letters.

There are many different factors to successfully cutting small letters with your Cricut out of vinyl, and so there are also many different things that can go wrong. Some of the factors can include the type of vinyl, the mat you are using, as well as the cut settings you are using. 

Difference between vinylsDifference between vinylsDifference between vinyls
The same vinyl, different approaches – this shows the difference these techniques can make!

Some of these things will make a very small difference in your cutting project, but those small differences could mean the difference between a good result, and a great result. Other factors and changes will make or break your project when cutting small vinyl letters with your Cricut.

What We’ll Cover In This Guide on How to Cut Small Letters on Cricut

  • Do you have a dirty blade?
  • Have you checked to see if you have a blunt blade?
  • Is your mat dirty?
  • The brayer: a game changer!
  • Test your cut settings!
  • What vinyl are you using?
  • Do you know about weeding boxes?
  • 10+ best fonts for small vinyl cutting on your Cricut

Do You Have a Dirty Blade?

This is the first thing that many people check when it comes to cutting small letters with your Cricut. It is also the easiest thing to check and the quickest one to fix. 

When cutting things with your Cricut, whether it’s paper or vinyl, little fibres or adhesive from the vinyl end up sticking to the blade, which can affect how you cut small letters on your Cricut. So one of the first things you want to do is to clean your blade.

Blade housing with blade being pushed outBlade housing with blade being pushed outBlade housing with blade being pushed out
Check how far the blade can extend. This blade also has a lot of debris on it

The best way to clean your blade is to use some rubbing alcohol swabs, so you will need to remove your blade from your machine. Press the top part of the blade housing in, and the blade gets pushed out at the bottom. 

Once the blade has been pushed out at the bottom, you can easily clean it with your alcohol swab, or replace it if your blade is old and blunt. 

Have You Checked to See if You Have a Blunt Blade?

If your blade is blunt, you will see that the blade kind of „skips” over the vinyl and drags it, and no amount of other changes will improve this. This probably means that it is time to get a new blade. Luckily, you don’t have to buy an entirely new blade housing, but rather just buy a replacement blade.

Many people will tell you to pierce a ball of foil to sharpen your blade, but this unfortunately doesn’t work in the way most people think it does. What it does do is clean some of the debris off your blade, but it is not nearly as effective as the method that we mentioned before, which is to clean it with rubbing alcohol. 

Is Your Mat Dirty?

Many people don’t realise that having a mat that isn’t very clean can also affect your cuts, and it can turn the best font for small vinyl cutting into the worst! With regular mat usage, little bits of debris, sand, hair, and dust can build up on the mat over time. With little grains landing on your mat, it does create a bit of a tent over that grain, and that means the blade will move a bit when it hits these grains.

Debris on the matDebris on the matDebris on the mat
You can see in the circles some places where there is dirt under the vinyl

Luckily, you can quite easily see when you have something on your mat that will affect your cuts, as that little tent catches the light quite nicely. So you will just need to lift up the vinyl, remove the little culprit, and you are then good to go!

In addition to debris on your mat, a mat that is quite old and isn’t as sticky anymore will definitely affect your cut. If you have lost quite a bit of stick on your mat, your vinyl will move around while you are trying to cut, which will definitely compromise how the vinyl cuts. Any movement of the vinyl will mean the blade doesn’t cut in the exact place it should, and you will get a wonky cut, which isn’t good for intricate cuts!

Very dirty Cricut cutting matVery dirty Cricut cutting matVery dirty Cricut cutting mat
This mat is verging on too dirty to use for very intricate cuts

The Brayer: A Game Changer!

This is a tool I didn’t know I needed until I had one. It is not only a real game changer for paper crafts, but also has an incredible effect on how to cut small letters on your Cricut. 

Cricut BrayerCricut BrayerCricut Brayer
The Cricut brayer is a real game changer when it comes to crafting with a mat!

What this little tool allows you to do is to ensure that the vinyl you are going to cut is completely stuck down to your mat. It has a soft roller on it, which means that it won’t scratch the vinyl in any way, but by applying even pressure, you are able to more effectively stick your vinyl down onto your cutting mat.

Test Your Cut Settings!

This is the most important part of cutting small vinyl letters with Cricut, and it will mean the difference between impossible weeding and having your vinyl ripping up while cutting. Test cuts are mandatory when it comes to working with the best fonts for small vinyl cutting on your Cricut.

When you are selecting something to cut, you need to choose a material type, and this material type is linked to a pressure setting in Cricut Design Space. A thinner material like crepe paper will need a lower pressure in order to cut through, and a much thicker material like metallic vinyl will need a much higher pressure setting to cut through.

vinyl showing cuts with different pressure settings vinyl showing cuts with different pressure settings vinyl showing cuts with different pressure settings
All three of these words have been cut with different cut settings, the lowest at the bottom. The difference between the cuts is small, but they get darker as the cuts go higher up. 

When your vinyl isn’t cutting through, it means that your pressure setting isn’t high enough, and you will need to increase the pressure to cut through properly. If you find that your vinyl moves around too much while it is being cut, then your pressure is too high.

While your machine is connected, you can view the material settings. If you click on the three lines in the top left-hand corner, you can click on Manage Custom Materials and see the different pressure settings for the different materials.

Manage custom materialsManage custom materialsManage custom materials
Click on the three lines in the top left, and you will find your custom settings

A long list of materials will pop up, and each will have a number to the right of the name—this is the pressure setting. If you use a particular setting and you find that your vinyl is not cutting through, you can either adjust this setting or pick another material type that has a higher pressure setting.

Example of custom material settingsExample of custom material settingsExample of custom material settings
Here are a few examples of vinyl settings and the pressure they use

What Vinyl Are You Using?

Not all vinyls are created equal, so the type of vinyl you use can make a big impact on your project. Each brand and type of vinyl will be slightly different—some are a bit more stretchy than others, some vinyls have a paper backing, and some have a more waxy backing than others. Some of these differences are going to be barely visible to the naked eye, so we may not even think that they are a possible cause of our project not succeeding, but they are.

Because of all of these different factors, you will have different results with the very same cut settings. The Cricut vinyl has been specifically formulated for use with the Cricut machines and tends to produce the best results the most easily. 

Three different vinylsThree different vinylsThree different vinyls
All three of these vinyls are different, and each requires a different approach

Oracal and Grafitack are two examples of widely used brands that tend to be a lot more cost-effective when it comes to working with large volumes of decals, and they can make it a bit more difficult to cut some of the very small letters with your Cricut.

I have found that I have to use different cut settings with the different brands of vinyl I use, and I spend a bit of time when I get a new brand of vinyl to make sure that I have the right cut setting for the best font for cutting small letters on my Cricut.

Do You Know About Weeding Boxes?

When cutting on your Cricut, I find that when it comes time to weeding (removing the excess vinyl), I often struggle when I have quite a few things to cut. Using weeding boxes when cutting small vinyl letters with Cricut really helps!

What this means is putting a box around parts of the text to allow you to weed the text in parts, and not have to remove the entire sheet of excess vinyl around in one go.

10+ Best Fonts for Small Vinyl Cutting on Your Cricut

When looking for the best fonts for cutting small text on your Cricut, there are many different kinds of fonts you can use and approaches you can take. Very often, the very thin and swishy fonts are difficult to cut, but hopefully after following all of these tips and tricks, you will find it as easy to cut very thin fonts.

Script fontsScript fontsScript fonts
Many script fonts are very tricky to cut, but with these tips you will be cutting the finest of fonts available!

But if you’re wondering where to find the best fonts for small text in Cricut, Envato Elements is a great option. This subscription-based marketplace offers you unlimited downloads for a flat monthly fee! Here are some of the best fonts for small text in Cricut:

1. Swashington (OTF & TTF)

SwashingtonSwashingtonSwashington

This font is a great introduction to cutting some fonts with swashes, as those are always the parts that challenge cutting some of the best Cricut fonts for small text.

2. Bellanie (OTF & TTF)

BellanieBellanieBellanie

If you want to learn how to cut small letters on Cricut, this is a great font to learn on. The flourishes will challenge you a little bit, but it still works nicely at a small scale.

3. Determine (OTF & TTF)

DetermineDetermineDetermine

This is one of the best fonts to use on Cricut for small letters as these letters aren’t very thick. So if you aren’t looking for a challenge, this is a fantastic font to use!

4. Brightshine (OTF & TTF)

BrighshineBrighshineBrighshine

This is a particularly challenging yet extremely beautiful font that you can use when you’re looking for the best font for small vinyl cutting on your Cricut. The lines are all very thin, with long, wispy flourishes, and it is a very good font to test your skills!

5. Aisollya (OTF & TTF)

AisollyaAisollyaAisollya

When cutting small vinyl letters with Cricut, this will also be another good font for a beginner to try as it is a little bit challenging, but with not too many flourishes, it won’t be too challenging.

6. Pathout Script (OTF & TTF)

Pathout ScriptPathout ScriptPathout Script

This is another one of the best fonts for small vinyl cutting if you aren’t looking for a challenge. It’s great if you need to have a font work easily, and you aren’t able to tick or correct all of the boxes we covered in this article.

7. Octavia (OTF)

OctaviaOctaviaOctavia

Give this elegant calligraphy font a try for your next Cricut project. Those extravagant flourishes could be a challenge to cut, but you can also simplify things by not using too many of the ligatures and alternates provided.

8. Simplicity (OTF)

SimplicitySimplicitySimplicity

Another great option when looking for the best fonts for cutting small text with your Cricut, this font has simple clean lines and is very thin. So while it doesn’t have too many flourishes, it still provides a nice challenge.

9. Halosense (OTF)

HalosenseHalosenseHalosense

This font is particularly challenging as not only does it have many flourishes, but it also is a slightly textured outline, so it will be challenging to cut in a few different ways. This could be the best font to use on Cricut for small letters!

10. Mallicot (OTF & TTF)

MallicotMallicotMallicot

Looking for the best Cricut font for small text? This type of font is always a fan favourite for cutting small vinyl letters due to the flourishes and thin, clean, classic lines, and it comes with a few extras too!

11. Adorabelle (OTF & TTF)

AdorabelleAdorabelleAdorabelle

With many glyphs and gorgeous flourishes, you could make this font more challenging, but the base of this font is a perfect way of testing out how your machine and cut settings are set up. Definitely, this is one of the best fonts for cutting small letters on Cricut!

12. Harmonie (OTF & TTF)

HarmonieHarmonieHarmonie

This could also qualify as the best font for cutting small letters on Cricut as it has nice thick letters, which makes it an easier font to use when cutting small letters out of vinyl.

Discover More Cricut Tutorials and Resources

If you’re looking for some new skills to learn to apply in Cricut Design Space, below are some amazing articles you can check out to learn some new skills and improve your projects!

Removing jQuery from GOV.UK

Post pobrano z: Removing jQuery from GOV.UK

The GOV.UK team recently published “How and why we removed jQuery from GOV.UK“. This was an insightful look at how an organization can assess its tooling and whether something is still the best tool for the job. This is not a nudge to strip libraries out of your current project right now! Many of us may still be supporting legacy projects and browser requirements that prevent this from being a viable option.

Some of the criticism appears to be that the library size argument is negligible on modern network speeds and caching.

GOV.UK posted an update to address this criticism with metrics – “The impact of removing jQuery on our web performance“.

This article also makes the case for improving maintenance. Instead of upgrading disparate outdated versions of code and having to address security updates in a piecemeal approach, removing the dependency reduces this footprint. This is the dream of having the luxury for addressing technical debt.

Previously, GitHub also documented how they incrementally decoupled jQuery from their front-end code. Improving maintenance and developer experience played a role into their decision.

What caught my eye in particular was the link to the documentation on how to remove jQuery. Understanding how to decouple and perform migration steps are maintenance tasks that will continue to come up for websites and it’s reassuring to have a guide from someone that had to do the same.

Further musing on this subject turned up the old chestnuts “You Might Not Need jQuery” (2014), “(Now More Than Ever) You Might Not Need jQuery” (2017), “Is jQuery still relevant? (1)” (2016), and “Is jQuery still relevant? (2)” (2017).

To Shared LinkPermalink on CSS-Tricks


Removing jQuery from GOV.UK originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

CSS Grid and Custom Shapes, Part 2

Post pobrano z: CSS Grid and Custom Shapes, Part 2

Alright, so the last time we checked in, we were using CSS Grid and combining them with CSS clip-path and mask techniques to create grids with fancy shapes.

Here’s just one of the fantastic grids we made together:

CodePen Embed Fallback

Ready for the second round? We are still working with CSS Grid, clip-path, and mask, but by the end of this article, we’ll end up with different ways to arrange images on the grid, including some rad hover effects that make for an authentic, interactive experience to view pictures.

And guess what? We’re using the same markup that we used last time. Here’s that again:

<div class="gallery">
  <img src="..." alt="...">
  <img src="..." alt="...">
  <img src="..." alt="...">
  <img src="..." alt="...">
  <!-- as many times as we want -->
</div>

Like the previous article, we only need a container with images inside. Nothing more!

Nested Image Grid

Last time, our grids were, well, typical image grids. Other than the neat shapes we masked them with, they were pretty standard symmetrical grids as far as how we positioned the images inside.

Let’s try nesting an image in the center of the grid:

CodePen Embed Fallback

We start by setting a 2✕2 grid for four images:

.gallery {
  --s: 200px; /* controls the image size */
  --g: 10px; /* controls the gap between images */

  display: grid;
  gap: var(--g);
  grid-template-columns: repeat(2, auto);
}
.gallery > img {
  width: var(--s);
  aspect-ratio: 1;
  object-fit: cover;
}

Nothing complex yet. The next step is to cut the corner of our images to create the space for the nested image. I already have a detailed article on how to cut corners using clip-path and mask. You can also use my online generator to get the CSS for masking corners.

What we need here is to cut out the corners at an angle equal to 90deg. We can use the same conic-gradient technique from that article to do that:

.gallery > img {
   mask: conic-gradient(from var(--_a), #0000 90deg, #000 0);
}
.gallery > img:nth-child(1) { --_a: 90deg; }
.gallery > img:nth-child(2) { --_a: 180deg; }
.gallery > img:nth-child(3) { --_a: 0deg; }
.gallery > img:nth-child(4) { --_a:-90deg; }

We could use the clip-path method for cutting corners from that same article, but masking with gradients is more suitable here because we have the same configuration for all the images — all we need is a rotation (defined with the variable --_a) get the effect, so we’re masking from the inside instead of the outside edges.

Two by two grid of images with a white square stacked on top in the center.

Now we can place the nested image inside the masked space. First, let’s make sure we have a fifth image element in the HTML:

<div class="gallery">
  <img src="..." alt="...">
  <img src="..." alt="...">
  <img src="..." alt="...">
  <img src="..." alt="...">
  <img src="..." alt="...">
</div>

We are going to rely on the good ol’ absolute positioning to place it in there:

.gallery > img:nth-child(5) {
  position: absolute;
  inset: calc(50% - .5*var(--s));
  clip-path: inset(calc(var(--g) / 4));
}

The inset property allows us to place the image at the center using a single declaration. We know the size of the image (defined with the variable --s), and we know that the container’s size equals 100%. We do some math, and the distance from each edge should be equal to (100% - var(--s))/2.

Diagram of the widths needed to complete the design.

You might be wondering why we’re using clip-path at all here. We’re using it with the nested image to have a consistent gap. If we were to remove it, you would notice that we don’t have the same gap between all the images. This way, we’re cutting a little bit from the fifth image to get the proper spacing around it.

The complete code again:

.gallery {
  --s: 200px; /* controls the image size */
  --g: 10px;  /* controls the gap between images */
  
  display: grid;
  gap: var(--g);
  grid-template-columns: repeat(2, auto);
  position: relative;
}

.gallery > img {
  width: var(--s);
  aspect-ratio: 1;
  object-fit: cover;
  mask: conic-gradient(from var(--_a), #0000 90deg, #000 0);
}

.gallery > img:nth-child(1) {--_a: 90deg}
.gallery > img:nth-child(2) {--_a:180deg}
.gallery > img:nth-child(3) {--_a:  0deg}
.gallery > img:nth-child(4) {--_a:-90deg}
.gallery > img:nth-child(5) {
  position: absolute;
  inset: calc(50% - .5*var(--s));
  clip-path: inset(calc(var(--g) / 4));
}

Now, many of you might also be wondering: why all the complex stuff when we can place the last image on the top and add a border to it? That would hide the images underneath the nested image without a mask, right?

That’s true, and we will get the following:

CodePen Embed Fallback

No mask, no clip-path. Yes, the code is easy to understand, but there is a little drawback: the border color needs to be the same as the main background to make the illusion perfect. This little drawback is enough for me to make the code more complex in exchange for real transparency independent of the background. I am not saying a border approach is bad or wrong. I would recommend it in most cases where the background is known. But we are here to explore new stuff and, most important, build components that don’t depend on their environment.

Let’s try another shape this time:

CodePen Embed Fallback

This time, we made the nested image a circle instead of a square. That’s an easy task with border-radius But we need to use a circular cut-out for the other images. This time, though, we will rely on a radial-gradient() instead of a conic-gradient() to get that nice rounded look.

.gallery > img {
  mask: 
    radial-gradient(farthest-side at var(--_a),
      #0000 calc(50% + var(--g)/2), #000 calc(51% + var(--g)/2));
}
.gallery > img:nth-child(1) { --_a: calc(100% + var(--g)/2) calc(100% + var(--g)/2); }
.gallery > img:nth-child(2) { --_a: calc(0%   - var(--g)/2) calc(100% + var(--g)/2); }
.gallery > img:nth-child(3) { --_a: calc(100% + var(--g)/2) calc(0%   - var(--g)/2); }
.gallery > img:nth-child(4) { --_a: calc(0%   - var(--g)/2) calc(0%   - var(--g)/2); }

All the images use the same configuration as the previous example, but we update the center point each time.

Diagram showing the center values for each quadrant of the grid.

The above figure illustrates the center point for each circle. Still, in the actual code, you will notice that I am also accounting for the gap to ensure all the points are at the same position (the center of the grid) to get a continuous circle if we combine them.

Now that we have our layout let’s talk about the hover effect. In case you didn’t notice, a cool hover effect increases the size of the nested image and adjusts everything else accordingly. Increasing the size is a relatively easy task, but updating the gradient is more complicated since, by default, gradients cannot be animated. To overcome this, I will use a font-size hack to be able to animate the radial gradient.

If you check the code of the gradient, you can see that I am adding 1em:

mask: 
    radial-gradient(farthest-side at var(--_a),
      #0000 calc(50% + var(--g)/2 + 1em), #000 calc(51% + var(--g)/2 + 1em));

It’s known that em units are relative to the parent element’s font-size, so changing the font-size of the .gallery will also change the computed em value — this is the trick we are using. We are animating the font-size from a value of 0 to a given value and, as a result, the gradient is animated, making the cut-out part larger, following the size of the nested image that is getting bigger.

Here is the code that highlights the parts involved in the hover effect:

.gallery {
  --s: 200px; /* controls the image size */
  --g: 10px; /* controls the gaps between images */

  font-size: 0; /* initially we have 1em = 0 */
  transition: .5s;
}
/* we increase the cut-out by 1em */
.gallery > img {
  mask: 
    radial-gradient(farthest-side at var(--_a),
      #0000 calc(50% + var(--g)/2 + 1em), #000 calc(51% + var(--g)/2 + 1em));
}
/* we increase the size by 2em */
.gallery > img:nth-child(5) {
  width: calc(var(--s) + 2em);
}
/* on hover 1em = S/5 */
.gallery:hover {
  font-size: calc(var(--s) / 5);
}

The font-size trick is helpful if we want to animate gradients or other properties that cannot be animated. Custom properties defined with @property can solve such a problem, but support for it is still lacking at the time of writing.

I discovered the font-size trick from @SelenIT2 while trying to solve a challenge on Twitter.

Another shape? Let’s go!

CodePen Embed Fallback

This time we clipped the nested image into the shape of a rhombus. I’ll let you dissect the code as an exercise to figure out how we got here. You will notice that the structure is the same as in our examples. The only differences are how we’re using the gradient to create the shape. Dig in and learn!

Circular Image Grid

We can combine what we’ve learned here and in previous articles to make an even more exciting image grid. This time, let’s make all the images in our grid circular and, on hover, expand an image to reveal the entire thing as it covers the rest of the photos.

CodePen Embed Fallback

The HTML and CSS structure of the grid is nothing new from before, so let’s skip that part and focus instead on the circular shape and hover effect we want.

We are going to use clip-path and its circle() function to — you guessed it! — cut a circle out of the images.

Showing the two states of an image, the natural state on the left, and the hovered state on the right, including the clip-path values to create them.

That figure illustrates the clip-path used for the first image. The left side shows the image’s initial state, while the right shows the hovered state. You can use this online tool to play and visualize the clip-path values.

For the other images, we can update the center of the circle (70% 70%) to get the following code:

.gallery > img:hover {
  --_c: 50%; /* same as "50% at 50% 50%" */
}
.gallery > img:nth-child(1) {
  clip-path: circle(var(--_c, 55% at 70% 70%));
}
.gallery > img:nth-child(2) {
  clip-path: circle(var(--_c, 55% at 30% 70%));
}
.gallery > img:nth-child(3) {
  clip-path: circle(var(--_c, 55% at 70% 30%));
}
.gallery > img:nth-child(4) {
  clip-path: circle(var(--_c, 55% at 30% 30%));
}

Note how we are defining the clip-path values as a fallback inside var(). This way allows us to more easily update the value on hover by setting the value of the --_c variable. When using circle(), the default position of the center point is 50% 50%, so we get to omit that for more concise code. That’s why you see that we are only setting 50% instead of 50% at 50% 50%.

Then we increase the size of our image on hover to the overall size of the grid so we can cover the other images. We also ensure the z-index has a higher value on the hovered image, so it is the top one in our stacking context.

.gallery {
  --s: 200px; /* controls the image size */
  --g: 8px;   /* controls the gap between images */

  display: grid;
  grid: auto-flow var(--s) / repeat(2, var(--s));
  gap: var(--g);
}

.gallery > img {
  width: 100%; 
  aspect-ratio: 1;
  cursor: pointer;
  z-index: 0;
  transition: .25s, z-index 0s .25s;
}
.gallery > img:hover {
  --_c: 50%; /* change the center point on hover */
  width: calc(200% + var(--g));
  z-index: 1;
  transition: .4s, z-index 0s;
}

.gallery > img:nth-child(1){
  clip-path: circle(var(--_c, 55% at 70% 70%));
  place-self: start;
}
.gallery > img:nth-child(2){
  clip-path: circle(var(--_c, 55% at 30% 70%));
  place-self: start end;
}
.gallery > img:nth-child(3){
  clip-path: circle(var(--_c, 55% at 70% 30%));
  place-self: end start;
}
.gallery > img:nth-child(4){
  clip-path: circle(var(--_c, 55% at 30% 30%));
  place-self: end;
}

What’s going on with the place-self property? Why do we need it and why does each image have a specific value?

Do you remember the issue we had in the previous article when creating the grid of puzzle pieces? We increased the size of the images to create an overflow, but the overflow of some images was incorrect. We fixed them using the place-self property.

Same issue here. We are increasing the size of the images so each one overflows its grid cells. But if we do nothing, all of them will overflow on the right and bottom sides of the grid. What we need is:

  1. the first image to overflow the bottom-right edge (the default behavior),
  2. the second image to overflow the bottom-left edge,
  3. the third image to overflow the top-right edge, and
  4. the fourth image to overflow the top-left edge.

To get that, we need to place each image correctly using the place-self property.

Diagram showing the place-self property values for each quadrant of the grid.

In case you are not familiar with place-self, it’s the shorthand for justify-self and align-self to place the element horizontally and vertically. When it takes one value, both alignments use that same value.

Expanding Image Panels

In a previous article, I created a cool zoom effect that applies to a grid of images where we can control everything: number of rows, number of columns, sizes, scale factor, etc.

A particular case was the classic expanding panels, where we only have one row and a full-width container.

CodePen Embed Fallback

We will take this example and combine it with shapes!

Before we continue, I highly recommend reading my other article to understand how the tricks we’re about to cover work. Check that out, and we’ll continue here to focus on creating the panel shapes.

First, let’s start by simplifying the code and removing some variables

CodePen Embed Fallback

We only need one row and the number of columns should adjust based on the number of images. That means we no longer need variables for the number of rows (--n) and columns (--m ) but we need to use grid-auto-flow: column, allowing the grid to auto-generate columns as we add new images. We will consider a fixed height for our container; by default, it will be full-width.

Let’s clip the images into a slanted shape:

A headshot of a calm red wolf looking downward with vertices overlayed showing the clip-path property points.
clip-path: polygon(S 0%, 100% 0%, (100% - S) 100%, 0% 100%);
CodePen Embed Fallback

Once again, each image is contained in its grid cell, so there’s more space between the images than we’d like:

A six-panel grid of slanted images of various wild animals showing the grid lines and gaps.

We need to increase the width of the images to create an overlap. We replace min-width: 100% with min-width: calc(100% + var(--s)), where --s is a new variable that controls the shape.

CodePen Embed Fallback

Now we need to fix the first and last images, so they sort of bleed off the page without gaps. In other words, we can remove the slant from the left side of the first image and the slant from the right side of the last image. We need a new clip-path specifically for those two images.

We also need to rectify the overflow. By default, all the images will overflow on both sides, but for the first one, we need an overflow on the right side while we need a left overflow for the last image.

.gallery > img:first-child {
  min-width: calc(100% + var(--s)/2);
  place-self: start;
  clip-path: polygon(0 0,100% 0,calc(100% - var(--s)) 100%,0 100%);
}
.gallery > img:last-child {
  min-width: calc(100% + var(--s)/2);
  place-self: end;
  clip-path: polygon(var(--s) 0,100% 0,100% 100%,0 100%);
}

The final result is a nice expanding panel of slanted images!

CodePen Embed Fallback

We can add as many images as you want, and the grid will adjust automatically. Plus, we only need to control one value to control the shape!

We could have made this same layout with flexbox since we are dealing with a single row of elements. Here is my implementation.

Sure, slanted images are cool, but what about a zig-zag pattern? I already teased this one at the end of the last article.

CodePen Embed Fallback

All I’m doing here is replacing clip-path with mask… and guess what? I already have a detailed article on creating that zig-zag shape — not to mention an online generator to get the code. See how all everything comes together?

The trickiest part here is to make sure the zig-zags are perfectly aligned, and for this, we need to add an offset for every :nth-child(odd) image element.

.gallery > img {
  mask: 
    conic-gradient(from -135deg at right, #0000, #000 1deg 89deg, #0000 90deg) 
      100% calc(50% + var(--_p, 0%))/51% calc(2*var(--s)) repeat-y,
    conic-gradient(from   45deg at left,  #0000, #000 1deg 89deg, #0000 90deg) 
      0%   calc(50% + var(--_p, 0%))/51% calc(2*var(--s)) repeat-y;
}
/* we add an offset to the odd elements */
.gallery > img:nth-child(odd) {
  --_p: var(--s);
}
.gallery > img:first-child {
  mask: 
    conic-gradient(from -135deg at right, #0000, #000 1deg 89deg, #0000 90deg) 
      0 calc(50% + var(--_p, 0%))/100% calc(2*var(--s));
}
.gallery > img:last-child {
  mask: 
    conic-gradient(from 45deg at left, #0000, #000 1deg 89deg, #0000 90deg) 
      0 calc(50% + var(--_p, 0%)) /100% calc(2*var(--s));
}

Note the use of the --_p variable, which will fall back to 0% but will be equal to --_s for the odd images.

Here is a demo that illustrates the issue. Hover to see how the offset — defined by --_p — is fixing the alignment.

CodePen Embed Fallback

Also, notice how we use a different mask for the first and last image as we did in the previous example. We only need a zig-zag on the right side of the first image and the left side of the last image.

And why not rounded sides? Let’s do it!

CodePen Embed Fallback

I know that the code may look scary and tough to understand, but all that’s going on is a combination of different tricks we’ve covered in this and other articles I’ve already shared. In this case, I use the same code structure as the zig-zag and the slanted shapes. Compare it with those examples, and you will find no difference! Those are the same tricks in my previous article about the zoom effect. Then, I am using my other writing and my online generator to get the code for the mask that creates those rounded shapes.

If you recall what we did for the zig-zag, we had used the same mask for all the images but then had to add an offset to the odd images to create a perfect overlap. In this case, we need a different mask for the odd-numbered images.

The first mask:

mask: 
  linear-gradient(-90deg,#0000 calc(2*var(--s)),#000 0) var(--s),
  radial-gradient(var(--s),#000 98%,#0000) 50% / calc(2*var(--s)) calc(1.8*var(--s)) space repeat;

The second one:

mask:
  radial-gradient(calc(var(--s) + var(--g)) at calc(var(--s) + var(--g)) 50%,#0000 98% ,#000) 
  calc(50% - var(--s) - var(--g)) / 100% calc(1.8*var(--s))

The only effort I did here is update the second mask to include the gap variable (--g) to create that space between the images.

The final touch is to fix the first and last image. Like all the previous examples, the first image needs a straight left edge while the last one needs a straight right edge.

For the first image, we always know the mask it needs to have, which is the following:

.gallery > img:first-child {
  mask: 
    radial-gradient(calc(var(--s) + var(--g)) at right, #0000 98%, #000) 50% / 100% calc(1.8 * var(--s));
}
A brown bear headshot with a wavy pattern for the right border.

For the last image, it depends on the number of elements, so it matters if that element is :nth-child(odd) or :nth-child(even).

The complete grid of wild animal photos with all of the correct borders and gaps between images.
.gallery > img:last-child:nth-child(even) {
  mask: 
    linear-gradient(to right,#0000 var(--s),#000 0),
    radial-gradient(var(--s),#000 98%,#0000) left / calc(2*var(--s)) calc(1.8*var(--s)) repeat-y
}
A single-row grid of three wild animal photos with wavy borders where the last image is an odd-numbered element.
.gallery > img:last-child:nth-child(odd) {
  mask: 
    radial-gradient(calc(var(--s) + var(--g)) at left,#0000 98%,#000) 50% / 100% calc(1.8*var(--s))
}

That’s all! Three different layouts but the same CSS tricks each time:

  • the code structure to create the zoom effect
  • a mask or clip-path to create the shapes
  • a separate configuration for the odd elements in some cases to make sure we have a perfect overlap
  • a specific configuration for the first and last image to keep the shape on only one side.

And here is a big demo with all of them together. All you need is to add a class to activate the layout you want to see.

CodePen Embed Fallback

And here is the one with the Flexbox implementation

CodePen Embed Fallback

Wrapping up

Oof, we are done! I know there are many CSS tricks and examples between this article and the last one, not to mention all of the other tricks I’ve referenced here from other articles I’ve written. It took me time to put everything together, and you don’t have to understand everything at once. One reading will give you a good overview of all the layouts, but you may need to read the article more than once and focus on each example to grasp all the tricks.

Did you notice that we didn’t touch the HTML at all other than perhaps the number of images in the markup? All the layouts we made share the same HTML code, which is nothing but a list of images.

Before I end, I will leave you with one last example. It’s a “versus” between two anime characters with a cool hover effect.

CodePen Embed Fallback

What about you? Can you create something based on what you have learned? It doesn’t need to be complex — imagine something cool or funny like I did with that anime matchup. It can be a good exercise for you, and we may end with an excellent collection in the comment section.


CSS Grid and Custom Shapes, Part 2 originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

When Do You Use CSS Columns?

Post pobrano z: When Do You Use CSS Columns?

That ain’t rhetorical: I’m really interested in finding great use cases for CSS multi-column layouts.

The answer seems straightforward. Use columns when you want to split any content into columns, right? Here is generally the sort of example you’ll find in articles that show how CSS mutli-column layouts work, including our very own Almanac:

CodePen Embed Fallback

Right on. But is this an actual use case? Mmmmmaybe. If the text is relatively brief, then perhaps it’s a nice touch. That’s how I sold it to myself when redesigning my website a few years ago. It’s not that way today, but this is what it looked like then:

But an entire long-form article split into columns? I love it in newspapers but am hesitant to scroll down a webpage to read one column, only to scroll back up to do it again.

I suppose we can use it to place two elements side-by-side, but flexbox is way more suited for that. Plus, a limitation prevents us from selecting the columns to size them individually. The columns have to be the same width.

One thing columns have going for them is that they are the only CSS layout method that fragments content. (That is, unless we’re counting CSS Regions… what happened to those, anyway?!) So, if you wanna split a paragraph up into columns, it’s already possible without additional wrappers.

When else might you need to split a continuous block of content into columns? I remember needing to do that when I had a big ol’ unordered list of items. I like the way lists can make content easy to scan, but long lists can make one side of the page look super heavy. Let’s say, for example, that we were listing out all the post tags for CSS-Tricks in alphabetical groups. A multi-column layout works beautifully for that:

CodePen Embed Fallback

Go ahead and try resizing the viewport width. Three columns are defined but the number will change based on the amount of available space. Gotta love all that responsive goodness without the media query work!

I was working on a demo for the :left pseudo-class and reached for columns because it’s a great way to fragment things for printing demos. So, I guess there’s another use case. And while making a demo, I realized that a multi-column layout could be used to create a masonry grid of items, like an image gallery:

CodePen Embed Fallback

But what else? Are we limited to short paragraphs, long lists, and free-flowing grids?


When Do You Use CSS Columns? originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

Using CSS Cascade Layers to Manage Custom Styles in a Tailwind Project

Post pobrano z: Using CSS Cascade Layers to Manage Custom Styles in a Tailwind Project

If a utility class only does one thing, chances are you don’t want it to be overridden by any styles coming from elsewhere. One approach is to use !important to be 100% certain the style will be applied, regardless of specificity conflicts.

The Tailwind config file has an !important option that will automatically add !important to every utility class. There’s nothing wrong with using !important this way, but nowadays there are better ways to handle specificity. Using CSS Cascade Layers we can avoid the heavy-handed approach of using !important.

Cascade layers allow us to group styles into “layers”. The precedence of a layer always beats the specificity of a selector. Specificity only matters inside each layer. Establishing a sensible layer order helps avoid styling conflicts and specificity wars. That’s what makes CSS Cascade Layers a great tool for managing custom styles alongside styles from third-party frameworks, like Tailwind.

A Tailwind source .css file usually starts something like this:

@tailwind base;
@tailwind components;
@tailwind utilities;
@tailwind variants;

Let’s take a look at the official Tailwind docs about directives:

Directives are custom Tailwind-specific at-rules you can use in your CSS that offer special functionality for Tailwind CSS projects. Use the @tailwind directive to insert Tailwind’s base, components, utilities and variants styles into your CSS.

In the output CSS file that gets built, Tailwind’s CSS reset — known as Preflight — is included first as part of the base styles. The rest of base consists of CSS variables needed for Tailwind to work. components is a place for you to add your own custom classes. Any utility classes you’ve used in your markup will appear next. Variants are styles for things like hover and focus states and responsive styles, which will appear last in the generated CSS file.

The Tailwind @layer directive

Confusingly, Tailwind has its own @layer syntax. This article is about the CSS standard, but let’s take a quick look at the Tailwind version (which gets compiled away and doesn’t end up in the output CSS). The Tailwind @layer directive is a way to inject your own extra styles into a specified part of the output CSS file.

For example, to append your own styles to the base styles, you would do the following:

@layer base {
  h1 {
    font-size: 30px;
  }
}

The components layer is empty by default — it’s just a place to put your own classes. If you were doing things the Tailwind way, you’d probably use @apply (although the creator of Tailwind recently advised against it), but you can also write classes the regular way:

@layer components {
  .btn-blue {
    background-color: blue;
    color: white;
  }
}

The CSS standard is much more powerful. Let’s get back to that…

Using the CSS standard @layer

Here’s how we can rewrite this to use the CSS standard @layer:

@layer tailwind-base, my-custom-styles, tailwind-utilities;

@layer tailwind-base {
  @tailwind base;
}

@layer tailwind-utilities {
  @tailwind utilities;
  @tailwind variants;
} 

Unlike the Tailwind directive, these don’t get compiled away. They’re understood by the browser. In fact, DevTools in Edge, Chrome, Safari, and Firefox will even show you any layers you’ve defined.

CSS Cascade Layers with Tailwind CSS layers in DevTools.

You can have as many layers as you want — and name them whatever you want — but in this example, all my custom styles are in a single layer (my-custom-styles). The first line establishes the layer order:

@layer tailwind-base, my-custom-styles, tailwind-utilities;

This needs to be provided upfront. Be sure to include this line before any other code that uses @layer. The first layer in the list will be the least powerful, and the last layer in the list will be the most powerful. That means tailwind-base is the least powerful layer and any code in it will be overridden by all the subsequent layers. That also means tailwind-utilities will always trump any other styles — regardless of source order or specificity. (Utilities and variants could go in separate layers, but the maintainers of Tailwind will ensure variants always trump utilities, so long as you include the variants below the utilities directive.)

Anything that isn’t in a layer will override anything that is in a layer (with the one exception being styles that use !important). So, you could also opt to leave utilities and variants outside of any layer:

@layer tailwind-base, tailwind-components, my-custom-styles;

@layer tailwind-base {
  @tailwind base;
}

@layer tailwind-components {
  @tailwind components;
}

@tailwind utilities;
@tailwind variants;

What did this actually buy us? There are plenty of times when advanced CSS selectors come in pretty handy. Let’s create a version of :focus-within that only responds to keyboard focus rather than mouse clicks using the :has selector (which lands in Chrome 105). This will style a parent element when any of its children receive focus. Tailwind 3.1 introduced custom variants — e.g. <div class="[&:has(:focus-visible)]:outline-red-600"> — but sometimes it’s easier to just write CSS:

@layer tailwind-base, my-custom-styles;
@layer tailwind-base {
  @tailwind base;
}

@tailwind utilities;

@layer my-custom-styles {
  .radio-container {
    padding: 4px 24px;
    border: solid 2px rgb(230, 230, 230);
  }
  .radio-container:has(:focus-visible) {
    outline: solid 2px blue;
  }
}

Let’s say in just one instance we want to override the outline-color from blue to something else. Let’s say the element we’re working with has both the Tailwind class .outline-red-600 and our own .radio-container:has(:focus-visible) class:

<div class="outline-red-600 radio-container"> ... </div>

Which outline-color will win?

Ordinarily, the higher specificity of .radio-container:has(:focus-visible) would mean the Tailwind class has no effect — even if it’s lower in the source order. But, unlike the Tailwind @layer directive that relies on source order, the CSS standard @layer overrules specificity.

As a result, we can use complex selectors in our own custom styles but still override them with Tailwind’s utility classes when we need to — without having to resort to heavy-handed !important usage to get what we want.


Using CSS Cascade Layers to Manage Custom Styles in a Tailwind Project originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.