Default Colors, Theme Colors, and Custom Colors #29568
Comments
Implementing multiple palettes as described above would go a long way and improve things both for end-users and developers. |
Reading the above I imagine: Gutenberg by default will provide a given set of styles. "Semantic" styles. These are the agreed-upon colors that will always be provided. Themes depend on it, patterns depend on it, blocks depend on it.
A theme can use that variable to style blocks. "Primary goes in this color, foreground goes in that color" A user can set that value to whatever they want. When they do change that value it sticks between themes. If they change any value of the primary, etc set that it's locked in. That's their global palette. If they reset the global styles then that palette goes to whatever the theme expressed or whatever Gutenberg defaults it to if the theme doesn't express anything. Templates and blocks can use those variables and styles in their templating. ".has-primary-color" will always be available what you (and the user) think it is. |
@nosolosw one of the quick steps I imagine here would be to introduce a new |
Thinking on UI: what do you think would be a good first step to match that change? Do we need to create separated palettes in the UI or can we start by having a long list of colors with what we have today (sorted: first core, then theme)?
So, the user can change all palettes (core, theme, user). In terms of theme.json shape/keys, everything can remain the same, we just need to change behavior (don't overwrite palettes). What are your thoughts on themes changing the color value of the color palette? For example, does it make sense that a theme can change the core yellow's value to a different sort of yellow? I'm thinking we don't need this to start, it seems to go against the spirit of this issue. If we wanted to do this, we could offer the option to only change the values but not the slug (so the generated classes still have the same names) or the UI name (so there's an incentive that themes that change the color don't do things like changing a yellow to a purple).
I'm thinking that we may want to cross that bridge when we get to it? Food for thought: depending on our needs, we could do different things such as allow multiple palettes per origin (multiple palettes for core, multiple for themes, etc), allow for having colors that aren't shown in the UI but still generate classes (deprecated colors, so to speak), etc. |
Yes, listing one after the other is fine for now.
Right, this is not planned to be changeable at first through themes. In the future we might unlock the values like you describe.
Agreed :) |
I've prepared a PR that could be a first step for this #31669 |
This is a great idea! I was recently looking for a solution on how to add additional colors to the default colors. I am happy to hear there will be a solution to it. I am wondering, would it be possible to add additional colors via PHP in classic themes? Will we be able to use, for example |
Initial version of this landed, we have a couple follow-up PRs to address some related issues but for now, I'm removing this issue from the must-have board as the UI is not expected in 5.8. |
I love where this is going! I think having colors coming from core is ideal and gives a great baseline API for theme authors to work with. Naming variables is never easy. Leveraging a baseline set of semantic variable names and then adding a layer of aliasing on top for theme authors to override is ideal (to me). |
Splitting theme and core palettes:Yes, absolutely, yes. This will be a good thing for the block directory since we would have standard names from core that are always available. What I'd like to see is the ability for themers to disable the UI part of core colors though while still supporting them as part of the core CSS package. Freelancers/agencies might not want clients choosing something outside of the color scheme. Semantic theme color palette naming:I've been working on a solution for this in the last few weeks. Here's a It is a combination of a Tailwind-like "shade" system based on the feedback from several theme designers on what they need on the average project. There are 4 groups of colors: 1) always-available, 2) neutral, 3) primary, and 4) secondary. The shading system goes from I also think such a shading system could have applications as we consider dark mode down the line. Group 1: Always Available
Group 2: Neutral ColorThese are often text, borders, backgrounds, etc. Usually your "grays".
Group 3: Primary ColorThis would be the primary/brand color used throughout the site. Links, buttons, etc.
Group 4: Secondary ColorOften unneeded, but this is for a secondary or accent color that is separate from the primary.
|
Instead of having all those -100 and -800 variants. I would rather maybe see a mechanism like a stepper, slider UI that can be controlled via API. So, if a purple exists but theme developer only wants to allow for certain steps (e.g. --200, --400, --900) then it would have just those increments on slider. |
Upon second thought, the existing color picker UI would still be more suitable for this, as opposed to |
@justintadlock @kjellr and I discussed this in #themereview the other day. I've come to appreciate @justintadlock approach and naming convention. I think this lays a solid foundation for theme authors to work with. Standardizing on these variable names is critical to setting up a scaffolding for themes to operate, while allowing interoperability when users switch themes. |
I've also gone ahead and put this on the radar for #core-css weekly, as we're currently having ongoing discussions about CSS Custom Property naming conventions. Recently we've been focused on @ryelle experimental work on WP Admin color schemes with Custom Properties. Here is our single source of truth in shared Google Doc: WordPress Core CSS custom property naming |
A couple thoughts after diving into colors lately: I've been playing around with the Automattic theme.json supported themes and across a few other points. BlockBase, Seedlot Blocks, and Blank Canvas all have 1. Should we consider
|
How about a required minimum default palette for themes?Like @richtabor, I've also been doing a deep dive into handling global colors in block-based themes, here are some findings: Global Color handling in Elementor = Sensible Defaults + FlexibilityElementor has done an excellent job as far as handling global colors by offering both sensible defaults and lots of flexibility. In Elementor, you can easily achieve a Tailwind-esque palette as @justintadlock is proposing as well as a more semantic approach like @pbking is referring too. The default palette naming strategy in Elementor is Primary, Secondary, Text, and Accent. The palette labels can be changed but the underlying custom properties remain the same and can't be deleted: --e-global-color-primary, --e-global-color-secondary, --e-global-color-text, --e-global-color-accent Tailwind-esque & Semantic Global Colorl Color handling in GutenbergI've found myself testing both versions of these palettes in block-based themes and ultimately it comes down to the design and what colors I need. In one site build I need multiple shades of a primary color (tailwind-esque variants), in another I need 4 distinctly different but semantically named colors: So far I've landed here as my default for block-based themes, which also echos @richtabor's light & dark palette slugs: Required minimum default palette for themes?With all that being said, how about a required minimum default palette for themes that uses a standard naming convention?
|
I do like the idea of cornerstones of colours you can count on across all themes. Background and foreground make sense to me as meaningful terms. Whatever naming appending numbers seems a slippery slope, so avoiding that seems great to me. What I find problematic actually is the use of primary/secondary and other words that tend to mean less - but that might be because I really want my theme.json right now to read like a recipe, not code. I don’t know if this is going to change for me with time and a personal feeling. Accent also feels strange to me as a term, accent to what? If we settle on some core fixed words, we have to think about translation, their comprehension, meaning and implications. All very doable as this process happens. I really am intrigued by the light/dark append @richtabor suggested, which reminds me of the approaches in various preprocessors. I think that is also needed to get around some block and pattern issues I think anyone who has played with this for even a short while has encountered now. |
Over the years I have found that I have a black&white theme for example, where |
We ended up iterating on Quadrat and going the semantic route as well. I feel like themes need to use semantic colors if they want their users to be able to customize their site's colors in a comprehensive way. Having a "blue" color defined makes little sense when the user goes to the Global Styles panel and changes its value to a red color. Changing a "background" color from blue to red does mean something instead. In the end, it all boils down to how the user is going to customize their site and a theme providing a color is not useful for that, but a color that is common to certain blocks or elements to the site. What those are named it would be interesting to discuss. I think that since the editor is already providing the ability to change the background and text color, those colors should exist as variables too, and be able to be assigned to other places by the theme (and the user). And then if the theme needs to add extra semantic colors (be it secondary, foreground, accent, or whatever you name it) then that could be a theme decision. |
@aristath This does not land for me. I think that monochromatic grays can easily be assigned to I definitely lean towards non-semantic color naming (e.g. seaside-blue) when developing a theme. But, I'm now seeing the more significant consideration of the user who would be interacting with the Global Styles UI in WP Admin. In this case, I think that I agree that a set of semantic color variables should be required within themes (and I also agree with @richtabor note on some sort of light/dark variables are necessary. I think this might be a good required palette:
I think it would be a great polishing feature to put some checks in place in the WP Admin UI for contrast validation (likely similar to what exists in color picker UI for blocks) for I think that Also, I wanted to note that I would love to see the ability for a I'm currently working on my first However, this is a separate issue for implementers to overcome and should not hold up progress on this color discussion. |
I meant literally a black & white theme (for designs a-la every-layout.dev). No grays or shades, no colors of any kind in the palette other than a black and a white, and the theme also disables custom-colors If we are going to require a palette, then the requirements should be limited to colors that are actually required - and that is no more than the background & text colors. Everything else is not strictly speaking required and should be opt-in |
I think a standard set of named variables/options for colors still fits here. If the theme only needs black and white, the json file can have |
I'm on the fence about the need for more standard semantic colors beyond background and text. On one hand, I agree with @aristath that a theme shouldn't have to define more than those two, but on the other hand, I see the value of having those names always mean a thing between theme changes so that when we create patterns or the user changes themes those class names are still there. But "primary" or "accent" may mean different things between two themes while background and text are very specific on their intent and theme switching between themes that care about "primary" colors differently can lead to unexpected results for the end user. |
I agree. If we had to choose between 2, I'd prefer some way to know if a color is dark or light vs where it would be used in the theme. Our premium theme now uses element names, but that doesn't fit everything. Background, background alt (expects a light value), header, body text, heading text, primary button, secondary button. I'm not opposed to a generic/vague naming convention, with focus on dark/light/neutral. A not perfect set of examples: A theme designer can think of The key things to figure out IMHO:
|
Yes, I think it needs to be a balance of WYSIWYG (what you see is what you get) and WYSIWYMNG (what you see is what you might not get). I.e. Whereas, |
I agree strongly with this — If there are any required palette colors for themes, the requirements should be as minimal as possible. Some themes will only need a foreground and background, and will have no use at all for dark, light, etc. I don't think it makes sense to enforce values for those. You don't have to look too far to find a theme that doesn't require a large palette either. If you ignore the dark mode stuff, Twenty Twenty-One primarily relies on just two colors: a foreground and background. It would generally work fine if all the rest were stripped out. If we want to establish suggested naming practices for more colors beyond foreground/background that's fine, but I don't think it makes sense to require more than just those two values. |
One aspect to consider here is patterns. If I insert a pattern that relys on the theme colors, when I customize the theme or switch themes, I would expect the colors to change to the new defaults of the theme. If some themes define a set of 5 colors and others only define 2 then what would happen to these other colors in the pattern? |
We should clarify what we mean by "required" here. A theme should never be required to implement specific color slugs. There are too many use cases outside of our bubble where such subjective "rules" don't make sense. Instead, we should have a standard that is used by core and the pattern directory. This convention should be 100% opt-in. However, if a theme chooses not to, core will automatically output those classes/colors. For example, core already handles That's as far as I would go with "required" colors: background and foreground. Beyond that, we should have a recommended practices document. For the patterns directory, we can always enforce the background/foreground colors too. |
There will absolutely be a ton of themes that do enable a bunch of colors though. I'd guess that a majority will. I think we need a plan for the themes that do enable more than foreground/background. It can still all be opt-in. If any theme defines colors, and switches to another that also defines colors, it shouldn't break. Those themes should have consistent naming/output. If a user has a theme that does define colors, then switches to a theme that doesn't (only has foreground/background), that is a separate concern that needs to be discussed. |
Thank you all for the discussion and thoughts! It's important to establish and clarify that When a theme specifies the background of a site using its palette what it would do is assign one of its colors to a concrete element ( All in all, we cannot be too performative on what colors a theme declares for its palette since it could range anywhere from no colors at all to twenty or more. But we can establish and encourage the use of probably primary and secondary as a desirable convention; beyond which it gets extremely blurry and confusing since a theme's interpretation of what each represents is going to differ in ways that cannot be anticipated nor mapped cleanly. Elements, though, are used across blocks, hence their global nature, and properly understood across themes. Initially, these are a provided set (background, text, titles, captions, etc) but it stands to reason this would eventually be extensible or configurable (this ties a bit with style variations and that separate roadmap, so I won't get too far there). Finally, patterns should be able to use primary and secondary (if we establish them as conventions) or any color from the default palette (non-semantic colors). That's why it's important, even if the UI is not present to pick a default color, that we can still provide the class mappings under the hood so that patterns don't need to go exclusively with inline hex codes alone. Variants and shades of a color would be really nice to prefigure, though there is currently no UI designed for it, so that should be explored as well separately. How can we introduce ranges like -900 -100 without overwhelming people? Should it be calculated or supplied? Should it be part of the palette or the color picker? It'd also be interesting to have the default color palette split between colors and neutrals, as @justintadlock shared, even if gets presented visually as a single palette. Right now we have black, white, and two grays supported (only one selectable!), and it can be limiting. It also stands to reason that core, plugins, or themes would want to eventually provide an entire replacement of the default palette with non-semantic colors (a more vibrant or more muted palette). |
While today, adding default CSS custom props to the body scope isn't such a big deal - as it's adding all of ~28 properties, it's easy to see how this will end up creeping and growing over time as block patterns evolve. Plus, as a general matter of good practice, you want as few props being called globally as possible, and ideally those being called being used consistently across the majority of pages. Patterns by nature are more modular than templates, able to pass between themes much like blocks, and their behavior and dependencies should be isolated similar to how core blocks are when it comes to styling. I've been developing quite a few FSE themes for clients in a production setting lately, in anticipation of the inevitable change-over. When it comes to color conventions, all of these themes we create presets for Aside from those cases, what's useful is grayscale, for example, we override Expanding some shades of gray for a palette could be seen, as well as shades of the brand primary and secondary colors, although this functionality likely could be handled via a plugin. In other words, the most common use cases for color that I've come across is brand-primary, brand-secondary, shades of those colors (which could be achieved with a slider, more or less) and shades of gray - even the most average implementation of gradients used globally are some combination of the brand primary & secondary colors, or shades of. Some themes will, by nature, enable a thousand colors, but that should be a theme creation choice, the default should be the minimum use case possible when talking about enqueueing colors across the entire body element scope. Likewise, patterns will want to showcase color's as a way of attracting people to install them, but these color palettes should be scoped specifically to the block pattern itself - that way someone can override them if they want to dig into them, just like you can override individual block presets. The legwork is already done for enabling block.json for blocks and theme.json for themes - I'd imagine it wouldn't be too tricky to add a pattern.json for patterns - else just defining the variables they use to the php code itself via an associative array (because it has to be done anyway). It's great that the defaults load so you can see them when you're first creating a theme to see how it's all connecting - but this should at least be opt-outable by setting a parameter in the theme.json file. |
Thinking on this further - a possible solution to shades could be to incorporate a function similar to the duotone color filter - effectively a shade filter. In that sense, you'd have your core colors that you chose and then the option to apply shading. In this case you'd have core colors: primary, secondary, black, white (although Theme Shapers makes a good argument for deliberately naming colors vs. just primary/secondary in terms of user confusion - accommodating that convention, but that's a semantic conversation for another time). With a range of 'shade' filters, and using HSL as the primary color tool, you could very easily create shade variables, similar to how you might set a variable for, say, font-sizes (Sm, Med, Lg, Xlg, etc) and apply them to any color selection. Let's take two example 'brand colors', a teal and a red, + the black and white. primary - Making things lighter or darker (shading), requires just manipulating the L value in HSL. To make it lighter, add to the L value, to make it darker, subtract from the L value. So, 3 base 'shade' values, 20%, 40%, 60% would look like the following: Of course, an L value of 0% will always return black, and 100% will always return white. A way around this would be to take advantage of css's calc function, and a sample implementation might look like this: primary color palette - --primary-color-h: 194 --lighter: 15%; primary-color-lighter: You could get into a lot of cool things like making color triads, complementary colors and such by further manipulating H or S values - which could auto generate a palette of colors based on the primary color selected. The initial values or final values could be returned as RGB, HEX, etc if there was a wrapper to convert the value to HSL. Alternatively, you could select your desired 'shade' sets, and a function would simply spit out your primary color recalculated with the different shades for each color you wanted. To keep things clean on the editor side, similar to how gradients has a toggle at the top, you could have a toggle for color / shades. The above implementation uses pure CSS, and certainly a more powerful function could be created on the php / js side of things. A reference article implementing above: https://tsh.io/blog/why-should-you-use-hsl-color-representation-in-css/ There was some company that had a similar implementation to generate color palettes based on an HSL seed color that was pretty cool, but I can't for the life of me remember it. |
What is the problem?
Color handling in Gutenberg comes in two forms: colors picked from a palette and custom colors. Core provides a default color palette which can be overwritten by a theme. Colors assigned to a palette are expressed through classes. The same model applies to gradients. This is issue is not about the technical aspects of when to classes, inline styles, variables, etc, are employed but about the user expectations and theme integration.
At the moment, it’s frustrating as a user that upon switching to a theme that overwrites the default color palette you lose access to the rainbow-color set that comes with core. The core palette aims to provide quick access to distinct hues reliably. A theme palette generally aims to define a restricted set of semantic colors for branding.
The heart of the issue is the conflict that arises since colors are not always used semantically but also for individual expression. A theme might have added a color palette with just two colors — a green and a black — to define its aesthetics. Now, if a user is interacting with a pattern that contains an image with a rural landscape and the green color is picked because it matches the tone of the image, that use is not semantic in the sense the user wouldn’t expect it to change if they switch themes. Gradients are even more pronounced given there’s no sense of “primary”, “secondary”, not even distinct color names and they can be a lot more decorative (the theme Seedlet is a good example, with gradients that work more as background patterns). Assembling a gradient from scratch is also more laborious.
This distinction between semantic colors and local colors has implications for theme switching, global styles, etc. So we need to expand the handling of colors.
Another problem is tying user customization to globally used colors. Right now a custom color can only be replicated by remembering and replicating its color code. There should be an easier way to transfer a local color choice into the shared palette.
Finally we have the situation of patterns, which need to set inline colors right now to ensure they work as expected. This shouldn’t be needed if the pattern wants to use a color from the default color palette.
Proposal
Separate the core palette from the theme palette
A first step is to make the theme color palette something that works in addition to the default palette. That would allow themes to register preferred colors without necessarily overwriting the default palette. Of course, it still needs to be possible to fully disable the default palette since sites that have stricter branding guidelines might prefer to remove it entirely, the same way the custom colors interface can be disabled, but it should not be the default behaviour that a theme palette overwrites the color palette.
Treat theme colors semantically
The other part is treating theme colors as colors that should change upon a theme switch. This is obvious for the global styles context, where headings or link colors set to a theme color should change when switching themes. But it can also be extended to theme colors employed locally.
There is always going to be some uncertainty in determining what the intention is when applying a local color, but by having a more clearly defined “Theme” group we can set a better expectation than what is currently the case — if I apply a theme color rather than a color from the spectrum to a button block, it’s easier to expect it to change upon theme switching.
The approach of having theme colors more clearly presented in the UI, in addition to the default color-spectrum, will allow us to finally tackle a big part of the conundrum outlined in #7553. Theme colors (of the
primary
andsecondary
kind) will be expected to map to the same variables on the next theme whiledark-red
andlight-blue
are consistently provided by core but could still be tweaked within their hue range in a still predictable way (for example, we might update the default color palette with a "vibrant" or "muted" variant of the same color-coded names).Extending the default palette
The default palette should be user customizable (as it is now in Global Styles), so a user can add, edit, or remove from it and sustain it through theme changes. That doesn't change. It's conceivable that the current colors in the default palette would need to be added, updated, or removed in the future. We should work with the assumption that we might add more default palettes in the future and that we should retain the current mappings indefinitely.
Bubble up local changes
Colors picked locally could automatically become part of the custom user palette so that the next time they want to pick the same color it's present there. A user should be able to remove a custom color at any time so that the custom palette doesn’t grow indefinitely if you use many custom colors locally. A tricky implementation detail is how to go from inline disposable color to a class-based one for this reuse, but this also helps address that problem by making it more obvious that adding a color (at least in certain contexts) automatically creates a class mapping for it.
Integration with patterns
By ensuring the default colors are present through their class mappings patterns can reliably work with them even in cases where they might not figure out in the UI for whatever reason. This is important to support a wide range of patterns and limit the need to resort to inline styles for effects.
The text was updated successfully, but these errors were encountered: