Saturday, May 24, 2025
News PouroverAI
Visit PourOver.AI
No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing
News PouroverAI
No Result
View All Result

Shades of Grey with color-mix()

May 4, 2024
in Front-Tech
Reading Time: 4 mins read
0 0
A A
0
Share on FacebookShare on Twitter


Greys. Who doesn’t love ’em? When it comes to building websites, it can be handy having a few shades of grey at your disposal, no matter your colour palette. We use them for borders and subtle dividers, shadows, and to indicate state changes without overwhelming the user with colour. Some designers feel that a website needs quite a few shades of grey in order to convey subtleties. I once worked on a project that literally had 50 shades of grey. If your native language is American English, you might be a little vexed by my spelling of “grey” here. Sorry, not sorry. Happily, CSS named colours are very inclusive when it comes to greys. All flavours of grey come in US/UK variants — take your pick from these beauties: lightgrey/lightgray grey/gray darkgrey/darkgray (which is lighter than grey/gray!) lightslategrey/lightslategray slategrey/slategray darkslategrey/darkslategray dimgrey/dimgray whitesmoke (technically a grey) silver (also grey) They’re probably not going to cut it for all your UI needs though. What we want is a nice selection of greys that complement our colour palette. We could of course use a colour picker and our favourite design tool (boring). Or we could create a palette of greys with the CSS color-mix() function (yaaaay!). Let’s go with the second option. A primer on color-mix() The color-mix() function enables us to mix percentages of two colors and output the result. To use it, we need to specify three arguments: the colour interpolation method, and the two colours we want to mix. We can specify the proportions of each colour as percentages. If we omit these they’ll be mixed 50/50, or we can specify one of them and the other will be scaled so that they toal 100%. /* 50% red, 50% blue */ color-mix(in srgb, red, blue) /* 60% red, 40% blue */ color-mix(in srgb, red 60%, blue) /* 60% red, 40% blue */ color-mix(in srgb, red, blue 40%) If we want to get into the particulars there’s a bit more to explore, especially when it comes to understanding how different colour interpolation methods operate. I wrote a primer on color-mix() for MDN if you’re interested, and plenty of cleverer people have written extensively about the inner workings of various colour spaces, gamuts and interpolation methods. I recommend Chris Lilley’s talk from CSS Day if you want to get a handle on just how mind-bending colour can be. If ever there was a topic that’s ripe for melting your brain, it’s colour on the web. But assuming you just want to mix a couple of colours, color-mix() itself on the whole it’s pretty intuitive. What even is grey, anyway? Let’s get back to grey (the lesser known Amy Winehouse album). We’re taught as children that grey comes from mixing black and white. That’s true in that it certainly gives us shades of grey, but when it comes to design, our choices of grey tend to be less black and white (LOL). We might want to use warmer or cooler grey tones, which mix in a little bit of colour, and yet we’ll still refer to the results as “grey” in our colour palette or design system. Simple greys with color-mix() We can mix black and white with the color-mix() function to create various shades of grey, from light to dark. Here we’ll mix them in increments of 20%, from 20% black/80% white to 80% black/20% white, storing these as custom properties so that we can use them anywhere in our CSS. (The initial –grey variable, as we saw in the previous example, resolves to 50% black/50% white). :root { –grey: color-mix(in oklch, black, white); –grey-20: color-mix(in oklch, black 20%, white); –grey-40: color-mix(in oklch, black 40%, white); –grey-60: color-mix(in oklch, black 60%, white); –grey-80: color-mix(in oklch, black 80%, white); } We only need to include a percentage for one of our colours (black in this case), the second one will be implied. Of course, if you really do want 50 shades of grey, go ahead and create as many variables as you like. Heck, even stick some calc() in there, I don’t mind. :root { –steps: 50; –increment: calc(100% / var(–steps)); –grey-1: color-mix(in oklch, black var(–increment), white); –grey-2: color-mix(in oklch, black calc(var(–increment) * 2), white); –grey-3: color-mix(in oklch, black calc(var(–increment) * 3), white); /* etc. */ } A side note on colour spaces (I’ll keep it brief, I promise): We’re using oklch here because colours in this space are perceptually uniform. That means that the percentage difference between the colours (well, greys) will be perceived by the viewer as being equal. If we compare the same five shades of grey in the srgb space we can see there’s a difference. See the Pen Shades of grey with color-mix() by Michelle Barker (@michellebarker) on CodePen. Lea Verou has a great article on LCH colours in CSS, including what perceptual uniformity actually means. Grey tones Now let’s create some warmer and cooler grey tones by mixing another colour with our grey variables. Yes, that’s right, we can mix the colours that are output from color-mix(). For our cooler greys, we’ll mix in a little bit of blue. We’re using the CSS named colour blue, which equates to rgb(0 0 255), but feel free to use any blue or blue-ish colour in whatever colour space takes your fancy. We’re going to mix the same amount of colour into each of our grey shades, so let’s create a “mixer” custom property. That way, if we want to tinker with our blue tone we only have one place we need to do it. :root { –blue-mixer: blue 10%; } Then we’ll use color-mix() to mix this into our original set of greys, creating a new set of custom properties: :root { –blue-grey: color-mix(in oklch, var(–grey), var(–blue-mixer)); –blue-grey-20: color-mix(in oklch, var(–grey-20), var(–blue-mixer)); –blue-grey-40: color-mix(in oklch, var(–grey-40), var(–blue-mixer)); –blue-grey-60: color-mix(in oklch, var(–grey-60), var(–blue-mixer)); –blue-grey-80: color-mix(in oklch, var(–grey-80), var(–blue-mixer)); } Perhaps these are too blue for you? You can, of course tone down or dial up the blue by adjusting the percentage value in the –blue-mixer custom property. We can do the same with a red hue to create some warm greys too. Check out the full demo below. Who said grey has to be boring? See the Pen Shades of grey with color-mix() by Michelle Barker (@michellebarker) on CodePen.



Source link

Tags: colormixcssfront endGreyShadesweb designweb development
Previous Post

What you need to know about the CCPA rules on AI and automated decision-making technology

Next Post

Trump Media stock tumbles as the SEC charges its auditor with ‘massive fraud’

Related Posts

The essential principles of a good homepage
Front-Tech

The essential principles of a good homepage

June 7, 2024
How to measure and improve user retention
Front-Tech

How to measure and improve user retention

June 6, 2024
Push Animation on Grid Items
Front-Tech

Push Animation on Grid Items

June 5, 2024
How to build a Rails API with rate limiting
Front-Tech

How to build a Rails API with rate limiting

June 4, 2024
Introduction to the B.I.A.S. framework
Front-Tech

Introduction to the B.I.A.S. framework

June 3, 2024
Blue Ridge Ruby is exactly what we need
Front-Tech

Blue Ridge Ruby is exactly what we need

June 3, 2024
Next Post
Trump Media stock tumbles as the SEC charges its auditor with ‘massive fraud’

Trump Media stock tumbles as the SEC charges its auditor with 'massive fraud'

Why and When to Use the Generalized Method of Moments | by Luis Felipe de Souza Rodrigues | May, 2024

Why and When to Use the Generalized Method of Moments | by Luis Felipe de Souza Rodrigues | May, 2024

Is Post-Quantum Cryptography The Solution To Cyber Threats?

Is Post-Quantum Cryptography The Solution To Cyber Threats?

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • Trending
  • Comments
  • Latest
Is C.AI Down? Here Is What To Do Now

Is C.AI Down? Here Is What To Do Now

January 10, 2024
23 Plagiarism Facts and Statistics to Analyze Latest Trends

23 Plagiarism Facts and Statistics to Analyze Latest Trends

June 4, 2024
A faster, better way to prevent an AI chatbot from giving toxic responses | MIT News

A faster, better way to prevent an AI chatbot from giving toxic responses | MIT News

April 10, 2024
Porfo: Revolutionizing the Crypto Wallet Landscape

Porfo: Revolutionizing the Crypto Wallet Landscape

October 9, 2023
Implementing User Authentication in React Apps with Appwrite — SitePoint

Implementing User Authentication in React Apps with Appwrite — SitePoint

January 30, 2024
NousResearch Released Nous-Hermes-2-Mixtral-8x7B: An Open-Source LLM with SFT and DPO Versions

NousResearch Released Nous-Hermes-2-Mixtral-8x7B: An Open-Source LLM with SFT and DPO Versions

January 25, 2024
Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

Can You Guess What Percentage Of Their Wealth The Rich Keep In Cash?

June 10, 2024
AI Compared: Which Assistant Is the Best?

AI Compared: Which Assistant Is the Best?

June 10, 2024
How insurance companies can use synthetic data to fight bias

How insurance companies can use synthetic data to fight bias

June 10, 2024
5 SLA metrics you should be monitoring

5 SLA metrics you should be monitoring

June 10, 2024
From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

From Low-Level to High-Level Tasks: Scaling Fine-Tuning with the ANDROIDCONTROL Dataset

June 10, 2024
UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

UGRO Capital: Targeting to hit milestone of Rs 20,000 cr loan book in 8-10 quarters: Shachindra Nath

June 10, 2024
Facebook Twitter LinkedIn Pinterest RSS
News PouroverAI

The latest news and updates about the AI Technology and Latest Tech Updates around the world... PouroverAI keeps you in the loop.

CATEGORIES

  • AI Technology
  • Automation
  • Blockchain
  • Business
  • Cloud & Programming
  • Data Science & ML
  • Digital Marketing
  • Front-Tech
  • Uncategorized

SITEMAP

  • Disclaimer
  • Privacy Policy
  • DMCA
  • Cookie Privacy Policy
  • Terms and Conditions
  • Contact us

Copyright © 2023 PouroverAI News.
PouroverAI News

No Result
View All Result
  • Home
  • AI Tech
  • Business
  • Blockchain
  • Data Science & ML
  • Cloud & Programming
  • Automation
  • Front-Tech
  • Marketing

Copyright © 2023 PouroverAI News.
PouroverAI News

Welcome Back!

Login to your account below

Forgotten Password? Sign Up

Create New Account!

Fill the forms bellow to register

All fields are required. Log In

Retrieve your password

Please enter your username or email address to reset your password.

Log In