We are planning a CSS modernization sprint with three main features: cascade layers, color-mix(), and logical properties.
We'll also set guardrails to ensure safe and incremental adoption.
Objectives:
Introduce cascade layers to manage style conflicts and organization.
Use color-mix() for dynamic color generation (with fallbacks for older browsers).
Adopt logical properties for better internationalization and responsive design.
Guardrails:
No breaking changes without a clear migration plan.
Fallbacks for unsupported browsers (using feature queries or polyfills where necessary).
Incremental adoption: start with new code and non-critical styles.
Let's break down the plan:
Phase 1: Setup and Foundation
Audit existing CSS for cascade issues and opportunities for layers.
Define a layer structure (e.g., base, components, utilities, overrides).
Set up build tools (PostCSS with plugins if needed) and configure for production.
Phase 2: Cascade Layers
Refactor existing CSS to use layers for new styles and gradually migrate old styles.
Example layer structure:
@layer base, components, utilities, overrides;
Base: reset, base element styles.
Components: component-specific styles.
Utilities: helper classes (e.g., margins, paddings, text alignment).
Overrides: high-specificity styles (e.g., for legacy hacks or critical overrides).
Use @layer to group rules and control order.
Guardrails:
- Only use layers in new CSS files or when refactoring existing ones.
- Do not change the order of existing styles without testing.
Phase 3: color-mix()
Use color-mix() in new color definitions, especially for dynamic themes or hover effects.
Guardrails:
- Only replace in new code or when doing other refactors.
- Be cautious with existing layouts: test thoroughly, especially if the design is not LTR/RTL ready.
Phase 5: Testing and Rollout
Test in target browsers (including older ones for fallbacks).
Use feature detection for color-mix() and logical properties (if necessary, but logical properties have good support now).
Monitor for any regressions.
Phase 6: Documentation and Training
Update style guide to reflect new practices.
Train the team on the new features and guardrails.
Tools and Setup:
Use PostCSS with:
postcss-cascade-layers (for better layer support in older PostCSS versions)
postcss-color-mix (to generate fallbacks for color-mix if needed)
postcss-logical (to convert logical to physical for older browsers? but we want to use logical, so maybe not)
Alternatively, we can rely on native support and use feature queries.
Browser support:
- Cascade layers: Chrome 109+, Safari 16+, Firefox 117+ (as of early 2023, but check current).
- color-mix(): Chrome 111+, Safari 16.4+, Firefox 113+.
- Logical properties: Good support, but check for very old browsers (IE11 doesn't support). If we support IE11, we might need fallbacks.
If we don't support IE11, we can use logical properties with confidence.
For color-mix(), if we need to support older browsers, we must provide fallbacks.
Implementation Steps:
Set up a feature flag or environment variable to enable/disable these modern features if needed (for A/B testing or gradual rollout).
Start with new components or pages using the new features.
For existing components, schedule refactors as part of regular maintenance.
Use a linter (stylelint) to enforce the new practices and catch old patterns.
Example stylelint configuration:
code
We can use stylelint-config-standard with custom rules.
For cascade layers, we might want to enforce that all CSS is within a layer? Not necessarily, but we can aim for that.
5. Create a shared config for PostCSS and stylelint.
Example CSS after modernization:
@layer base, components, utilities, overrides;
@layer base {
:root {
--primary: #0066cc;
--secondary: #ff6600;
}
code
body {
font-family: system-ui, sans-serif;
/* logical property for margin */
margin-block: 0;
}
For legacy CSS that cannot be updated immediately, leave it outside layers? But note: unlayered styles are always on top of layered ones. So we might want to put legacy in an 'overrides' layer? Actually, the cascade order is:
User agent
User
Author styles (in layer order, then unlayered)
So unlayered author styles come after all layers. We can put legacy in an 'overrides' layer and then put that layer last? Actually, we can control the order of layers:
@layer base, components, utilities, overrides;
So overrides will be on top of utilities, etc.
But note: unlayered styles (without @layer) are above all layers? No, according to the spec, layered styles are above unlayered? Actually, the cascade order is:
Importance (user !important, then author !important, then user, then author, then UA)
Origin
Layer order (if same origin and importance)
Then, within the same layer, source order.
Then, unlayered styles are treated as if they are in a layer that comes after all named layers? Actually, unlayered styles are in the "unlayered" layer which is after all named layers? Let me check:
According to MDN:
"Styles that are not in a layer are considered to be in a final anonymous layer that comes after all named layers."
So unlayered > named layers (unless named layer is with !important and unlayered is not).
Therefore, we should be cautious: if we want our new layered styles to override legacy unlayered, we might have to use !important or put the legacy in a layer that comes after? Actually, we want the new layered styles to be in a layer that comes after the legacy? No, we want the new layered styles to override legacy? That depends.
Strategy:
We want to gradually migrate. So we can put new code in layers and then have a layer for overrides that might override both old and new? But then we have to be careful.
Alternatively, we can put all new code in layers and leave legacy unlayered, but then legacy will override our new layered styles (because unlayered > named layers). That might be a problem.
So we have two options:
Option A: Put legacy in a layer (say 'legacy') and then put that layer at the end (so it's on top). Then new layers (base, components, utilities) are below and can be overridden by legacy when needed. But we want to move away from legacy.
Option B: We accept that unlayered (legacy) will override new layered styles, and we only use layers for new styles that we want to be below legacy? That doesn't make sense because we want new styles to be applied without being overridden by legacy.
Actually, the goal of layers is to manage the cascade. We want to have a predictable order. So we should put everything in layers eventually.
Here's a comprehensive CSS modernization sprint plan focusing on cascade layers, color-mix(), and logical properties with pragmatic guardrails for incremental, safe adoption.
🎯 Sprint Goal
Modernize the CSS stack to improve maintainability, theming flexibility, and internationalization support while ensuring zero visual regressions and backwards compatibility.
📋 Sprint Phases (2-Week Sprint)
Phase 1: Foundation & Guardrails Setup (Days 1-2)
Audit & Baseline
Run CSS stats (via cssstats.com or postcss plugin) to quantify:
Then we move legacy into the 'legacy' layer. But note: we don't want to change the behavior of legacy, so we put it in a layer that is on top? Then if we write new styles in 'overrides' they will be below legacy? That might be acceptable because we want legacy to win until we refactor.
Alternatively, we can have:
@layer base, components, utilities, overrides;
And then we put the legacy styles in the 'overrides' layer? But then we are moving legacy into a layer that we might use for new overrides? That could be confusing.
Let's think:
We want:
base < components < utilities < overrides < legacy (if we leave legacy unlayered, then legacy is above overrides)
But if we put legacy in a layer, we can control its position.
Then legacy is on top. But then if we write a new style in overrides, it will be under legacy. That's okay because we are moving legacy to the top to preserve its behavior.
Then, when we refactor a legacy style, we move it from the legacy layer to the appropriate layer (base, components, etc.) and then it will follow the new cascade.
So:
Step 1: Create layers: base, components, utilities, overrides, legacy.
Step 2: Move all existing unlayered CSS into the legacy layer (by wrapping in @layer legacy { ... }). This preserves the current behavior because legacy is on top.
Step 3: For any new CSS, put it in the appropriate layer (base, components, utilities, overrides) and it will be under legacy.
Step 4: When refactoring a legacy component, move its styles from the legacy layer to the appropriate layer (and adjust as needed). Then the new styles will be in the correct layer and might be overridden by other layers (if not using !important).
This way, we have a clear migration path.
However, moving all existing CSS into a legacy layer is a big change and might be risky. We can do it incrementally:
For each component that we refactor, we move its styles from the global (unlayered) to the appropriate layer. But then the unlayered styles that are left will still override the new layered styles? Yes, because unlayered is above named layers.
So we must either:
code
a) Move all existing styles to a layer (so there are no unlayered styles) and put that layer at the top (legacy). Then all new styles are in layers below.
b) Or, we accept that until we move a piece of style from unlayered to a layer, it will override new layered styles.
Option (a) is a one-time big refactor but safer for the cascade because we control everything. Option (b) is incremental but might cause unexpected overrides.
Given the risk, we might do:
code
Phase 1: Create the layers and move all existing CSS into the 'legacy' layer (with a script? manually?).
But note: if we wrap all existing CSS in @layer legacy, then the order of the legacy layer is the same as before? Not exactly, because within the layer, the order is the same as the source order? Yes, within a layer, the order is the source order. So if we wrap the entire existing CSS in one @layer block, then the order of the rules within that block is the same as before? Actually, we would have to preserve the order of the entire CSS. If we just wrap the entire file in one @layer block, then the order of the rules inside that block is the same as before. But if we have multiple CSS files, we have to consider the order of the files. The layer order is determined by the order of the @layer rule (the first occurrence of the layer name sets the order). So we must make sure the @layer rule for 'legacy' comes after the other layers? Actually, the order of layers is determined by the first occurrence of each layer in the cascade. So we should have:
@layer base, components, utilities, overrides, legacy;
Then, in our CSS, we can have:
@layer base { ... }
@layer components { ... }
...
@layer legacy {
/* all existing CSS here */
}
But note: if we have multiple CSS files, we must ensure the @layer rule for the layer order is in each file? Actually, the layer order is global. So we only need to declare the layer order once (in the first CSS file that uses layers). Then in other files, we can just use @layer without the order? Actually, we can just use @layer (without the list) to assign rules to existing layers. The order is determined by the first @layer rule that lists the layers.
So we can have in our main CSS:
@layer base, components, utilities, overrides, legacy;
Then in other files, we can do:
@layer base {
/* ... */
}
And the layer order is already set.
So the plan:
code
Step 1: In the main CSS file (or a dedicated layers file) we declare the layer order:
@layer base, components, utilities, overrides, legacy;
Step 2: Then, we take all existing CSS (in all files) and wrap them in @layer legacy { ... }.
Step 3: Then, for new CSS, we use the appropriate layer (base, components, utilities, overrides) and they will be under legacy.
Step 4: When we refactor a component, we move its styles from the legacy layer to the appropriate layer and adjust as needed.
But note: if we have multiple CSS files, we must wrap the content of each file in @layer legacy? Or we can have one file that imports all and then wrap the entire thing? It depends on our build.
Alternatively, we can use PostCSS to automate the wrapping of existing CSS in @layer legacy. But that might be complex because we have to preserve the order of CSS files.
Given the complexity, we might decide to not move all existing CSS at once, but instead:
code
- Only new CSS goes into layers.
- Existing CSS remains unlayered, but we accept that unlayered will override new layered styles.
Then, when we refactor a component, we move it to layers and then it will be under any remaining unlayered styles? That's a problem because if we move a component to layers and there is still unlayered styles that target the same selector, the unlayered will win.
So we must either:
code
a) Move all existing CSS to the legacy layer at once (so there are no unlayered styles) and then we have a clean slate.
b) Or, we use the cascade to our advantage: we put the new layers above the unlayered? But that's not possible because unlayered is above named layers.
Wait, we can use !important in our layers to override unlayered? That's not a good idea.
Alternatively, we can put our new styles in an 'overrides' layer and then use !important in that layer? That's also not ideal.
The spec says: unlayered styles are above named layers. So we cannot have named layers above unlayered.
Therefore, the only safe way is to put all existing styles (that we don't want to override by new styles) in a layer that is above the new layers. That is, we put old styles in a layer that comes after (i.e., higher than) the new layers. But then we want new styles to sometimes override old? Then we have to use !important or change the layer order.
Actually, we can control the order of layers. We want:
code
base < components < utilities < overrides < legacy
Then, if we write a new style in overrides, it will be under legacy (so legacy wins). But if we want the new style to win, we have to put it in a layer after legacy? But then we would have to change the layer order? We can't change the order dynamically.
So the layer order is fixed at the time of the first @layer rule. So if we want new styles to override legacy, we must put the new styles in a layer that comes after legacy. But then we would have to declare:
Alternatively, we can put legacy in a layer that is not the last? Then unlayered (if any) would be after legacy? Actually, unlayered is after all named layers. So if we have:
So if we have any unlayered styles, they will override everything.
Therefore, we must eliminate unlayered styles to have a predictable cascade.
Conclusion: We must move all existing styles to a layer (legacy) and then we can control the order.
How to move all existing styles to the legacy layer without breaking the current order?
We can do:
code
In the main CSS file (or a file that is loaded last) we have:
@layer legacy;
But that would put the legacy layer at the end? Actually, the order of layers is determined by the first @layer rule that lists the layers. So we must have:
@layer base, components, utilities, overrides, legacy;
in a file that is loaded before any other CSS that uses these layers? Actually, the layer order is global and determined by the first occurrence of each layer in the cascade (across all stylesheets). So we need to make sure that the first time we see a layer name, the order is set.
We can do:
In our main CSS (which is loaded first) we have:
@layer base, components, utilities, overrides, legacy;
Then, in all other CSS files (including the ones that contain the existing styles) we wrap the content in:
@layer legacy {
/* existing styles */
}
But note: if the existing styles are in multiple files, we have to wrap each file's content in @layer legacy? And then the order of the legacy layer will be the order of the files? Actually, the rules within a layer are in source order (the order of the CSS files and within the file). So if we wrap each file in @layer legacy, then the order of the rules within the legacy layer is the order of the files and the order within each file.
So the plan:
Step 1: Create a new stylesheet (or use the main one) that declares the layer order:
@layer base, components, utilities, overrides, legacy;
Step 2: For each existing CSS file (that we want to move to legacy), we wrap the entire content in @layer legacy { ... }.
Step 3: Then, for new CSS, we create new files (or add to existing ones) using the appropriate layer (base, components, utilities, overrides) and they will be under legacy.
But note: if we have existing CSS that we don't wrap (because we forget), then that will be unlayered and will override everything. So we must wrap all existing CSS.
We can use a build step to automate the wrapping of existing CSS files in @layer legacy.
Alternatively, we can do:
Step 1: Create a new CSS file for the legacy layer that imports all existing CSS files and then wrap the entire thing in @layer legacy? But that would change the order? Actually, if we import, the imported CSS is inlined. Then we wrap the entire inlined CSS in @layer legacy. That would preserve the order? Yes, because the imported CSS is inlined in the order of the imports.
Example:
legacy.css:
@layer legacy {
@import "reset.css";
@import "components.css";
@import "utilities.css";
@import "overrides.css";
}
Then we load legacy.css after the layer order declaration? Actually, the layer order must be declared before any rules that use layers? Not necessarily, but the first @layer rule that lists the layers sets the order. So we can have:
layers.css:
@layer base, components, utilities, overrides, legacy;
Then legacy.css (which uses @layer legacy) is loaded after? But the layer order is already set by layers.css. So in legacy.css, when we write @layer legacy, it uses the existing layer 'legacy' (which is already in the order). And the rules inside are added to the legacy layer in the order they appear in the CSS.
So:
In our HTML:
<link rel="stylesheet" href="layers.css">
<link rel="stylesheet" href="legacy.css">
Then in layers.css:
@layer base, components, utilities, overrides, legacy;
Then in legacy.css:
@layer legacy {
/* all the old CSS */
}
Then new CSS files can be:
@layer components {
/* new component styles */
}
And they will be loaded after legacy.css? But the order of the layers is fixed by the first @layer rule (in layers.css). So the components layer is below legacy (because legacy is listed last). So the new component styles will be under the legacy styles? That means legacy will override new components? That's what we want initially to preserve the current behavior.
Then when we refactor a component, we move its styles from legacy.css (the legacy layer) to a new file in the components layer. Then the new component styles (in the components layer) will be under the legacy layer? Actually, the legacy layer is above components, so if we move a component's styles from legacy to components, then the legacy version (if still present) will override the new one? We must remove the legacy version.
So the process for refactoring a component:
- Remove the component's styles from legacy.css (the legacy layer).
- Create a new file (or add to an existing one) in the components layer with the updated styles.
Then the new styles will be in the components layer, which is below legacy? But we removed the legacy version, so there is no conflict? Actually, if there are other legacy styles that target the same selector, they will still be in the legacy layer and will override the new component styles? That might be a problem.
Therefore, we must be cautious: when we move a component, we must check if there are any legacy styles that might override it. If so, we might need to move those as well or adjust.
Alternatively, we can change the layer order to:
@layer base, components, utilities, overrides;
and then put legacy in the overrides layer? But then legacy would be on top of utilities and components? That might be acceptable.
But note: the layer order is fixed. We want to gradually move from legacy to the appropriate layer. So we want legacy to be on top until we move everything? Actually, we want to be able to override legacy when necessary? That's the point of layers: to manage overrides.
Maybe we should not put all legacy in one layer, but rather by their original intent? But that would require a lot of work.
Given the complexity, perhaps the best approach is:
- Do not move all existing CSS at once.
- Instead, for each new component or refactor, put the new styles in the appropriate layer (base, components, utilities, overrides) and leave the old styles unlayered? But then the unlayered old styles will override the new layered styles.
This is unacceptable because we want new styles to take effect.
So we must eliminate unlayered styles. Therefore, we must move all existing styles to a layer (or layers) that are below the new styles? But then the new styles would override the old? That would break the current design.
We want to preserve the current design, so we want the old styles to win until we refactor. Therefore, we put the old styles in a layer that is above the new styles.
Then, when we refactor, we move the old styles from the high layer to a lower layer (the appropriate one) and then the new styles (which are in the lower layer) will be overridden by the old? No, because we remove the old from the high layer and put it in a lower layer? Then the new styles (in the same lower layer) might be overridden by other rules in that layer? We have to be careful with source order.
Actually, when we move a component from the legacy layer (which is high) to the components layer (which is lower), then if there are any other styles in the components layer that target the same selector, the one that comes later in source order wins. But we are moving the component's styles to the components layer, and we are removing them from the legacy layer. Then the component's styles in the components layer will be in the order we put them. But if there are other component styles that are already in the components layer and come after, they might override? That's the same as before.
The problem is: if we have a legacy style that is not part of the component we are refactoring, but it targets the same element, then that legacy style (in the legacy layer) will override our new component style (in the components layer) because legacy is above components.
So we must either:
a) Move all legacy styles that might conflict to the appropriate layer as well? That's a lot of work.
b) Use more specific selectors or !important in the new component styles? Not ideal.
This suggests that moving all legacy to one layer (legacy) might not be the best because then we have a blanket override over all new styles.
Alternatively, we can move legacy to multiple layers? But that would require analyzing each legacy rule and assigning it to a layer? That's even more work.
Given the complexity, perhaps we should:
Step 1: Declare the layer order without a legacy layer:
@layer base, components, utilities, overrides;
Step 2: For new CSS, use these layers.
Step 3: For existing CSS, leave it unlayered? Then unlayered will override new layered styles? Yes.
Step 4: When we refactor a component, we move it from unlayered to the appropriate layer. But then, if there are other unlayered styles that target the same element, they will still override? Yes.
So we must move all unlayered styles that target the same element? That's not feasible.
Therefore, the only safe way is to move all existing styles to layers and have a layer order that puts the old styles in the appropriate layer? But we don't know the appropriate layer for old styles.
Alternatively, we can have a layer for old styles that is below the new styles? Then new styles would override old? That would break the current design.
So we are stuck.
Let's re-read the spec: unlayered styles are above named layers. So if we want old styles to be below new, we have to put old in a named layer that is below the new layers? But then we have to put old in a layer that is below, and then new in a layer above? But the layer order is fixed by the first @layer rule. We can set:
@layer legacy, base, components, utilities, overrides;
Then legacy is at the bottom? Actually, the order of the list in the first @layer rule is the order from lowest to highest? No, the first layer in the list is the lowest? Actually, the cascade order for layers is the order they are defined in the @layer rule (the first is the lowest, the last is the highest). Example:
@layer a, b, c;
Then a < b < c.
So if we want legacy to be below new, we do:
@layer legacy, base, components, utilities, overrides;
Then legacy is below base, etc. So new styles in base will override legacy? Yes.
But we want to preserve the current design, which means we want old styles to win? Not necessarily. We want to be able to override old styles with new ones when we refactor.
Actually, we want:
- When we write a new style for a component, we want it to apply without being overridden by old styles of other components? That's not guaranteed because old styles might have global selectors.
The whole point of layers is to manage the cascade. We want to have a predictable order.
Given the complexity of the existing CSS, perhaps the best approach is:
- Do not change the order of existing styles. We keep the existing cascade order (which is the order of the CSS files and within files) by putting all existing styles in one layer (legacy) and then put new styles in layers that are above legacy? But then new styles will override legacy? That's the opposite of what we want initially.
Wait, we want to be able to override legacy when we write new styles? Actually, when we refactor a component, we want the new styles for that component to override the old ones. But we don't want new styles for one component to override old styles of another component? That's the same as before.
So if we put all legacy in one layer (say, 'legacy') and then we put new styles in layers that are above 'legacy', then any new style will override any legacy style? That's not what we want because we only want the new style for the component we are refactoring to override the legacy of that component, but not necessarily override legacy of other components.
Example:
Legacy has:
.button { color: red; }
We refactor button and write:
.button { color: blue; }
We want blue to win.
But if we have:
.alert { color: red; }
And we don't refactor alert, then we don't want our new button style to affect alert? But if we have a new rule that is more specific, it might. But that's the same as before.
Actually, the problem is that if we put all legacy in one layer, then the entire legacy layer is below the new layers? Then any new style will override any legacy style? That's not true because the cascade also considers specificity and source order. But if we have:
Legacy layer (below):
.button { color: red; }
New layer (above):
.button { color: blue; }
Then blue wins because the new layer is above.
But what if we have:
Legacy layer:
.button { color: red; }
New layer:
.alert { color: blue; }
Then they don't conflict.
So putting all legacy in one layer (below) and new in layers above means that any new style will override any legacy style with the same specificity? That's not what we want because we only want to override the legacy of the component we are refactoring.
But note: when we refactor a component, we are removing the legacy style for that component from the legacy layer? No, we are leaving the legacy layer as is (with all the old styles) and then we add new styles in a higher layer. Then the new style for the component will override the old one because the new layer is higher.
But what about other legacy styles? They are still in the legacy layer and won't be overridden by new styles for other components because the selectors are different.
So if we do:
Layer order: legacy < base < components < utilities < overrides.
Then, when we write a new component style in the components layer, it will override the legacy style for that component (if the selector is the same and the new style is in the components layer, which is above legacy). But it will also override any legacy style in the legacy layer that has the same specificity and targets the same element? Yes.
But that's okay because we are refactoring that component. However, if we have a legacy style that is very specific (e.g., #app .button) and we write a new style in components layer with just .button, then the legacy style might still win because of specificity? Actually, the layer order is after specificity? The cascade:
- Importance
- Origin
- Layer order (if same importance and origin)
- Specificity
- Source order
So if two rules have the same importance and origin, then the one in a higher layer wins, regardless of specificity? Actually, no: specificity is after layer order? Let me check:
According to the spec:
Step 1: importance (user !important, author !important, etc.)
Step 2: origin (user, author, UA)
Step 3: layer order (if same importance and origin)
Step 4: specificity
Step 5: source order
So if we have:
Legacy layer (lower):
#app .button { color: red; }
Components layer (higher):
.button { color: blue; }
Then, because the components layer is higher, the .button rule wins? Even though the legacy rule has higher specificity? Yes, because layer order is before specificity.
So that's good: we can override legacy with less specific selectors in higher layers.
But what if we have:
Legacy layer (lower):
.button { color: red; }
Components layer (higher):
button { color: blue; }
Then the .button in legacy has higher specificity than button in components? But components layer is higher, so components wins? Actually, layer order is before specificity, so components wins.
So with layers, we can override legacy with any selector (even less specific) as long as we are in a higher layer.
That's powerful and might be what we want: when we refactor a component, we can write simpler selectors and still override the legacy.
But what about legacy styles that we don't want to override? For example, a legacy style that is global and we want to keep? Then we have to make sure that our new styles for other components don't accidentally override that global legacy style? But if our new style is in a higher layer and has the same or lower specificity, it will override. That's a problem.
Example:
Legacy (in legacy layer):
body { font-family: Arial; }
New style in base layer (which is above legacy? Actually, in our order: legacy < base, so base is above legacy? Wait, we set: legacy < base < components < utilities < overrides.
So base is above legacy. Then if we have:
base layer:
body { font-family: sans-serif; }
Then sans-serif will override Arial? Yes.
But we might not want that. So we have to be cautious: when we write new styles in base, we might override legacy styles that we want to keep.
Therefore, we must review the legacy styles and decide which ones we want to keep and which we want to override? That's a big task.
Given the complexity, perhaps the best approach is:
- Do not change the layer order for legacy. Instead, put legacy in a layer that is above the new layers? Then new layers cannot override legacy unless we use !important? That's not good.
Alternatively, we can have:
@layer base, components, utilities, overrides, legacy;
Then legacy is on top. Then new styles in base, components, etc. are below legacy and cannot override legacy without !important.
Then when we refactor a component, we move its styles from legacy to the appropriate layer (base, components, etc.) and then the new style (which is now in a lower layer) might be overridden by other legacy styles? But we removed the legacy style for that component, so only other legacy styles that target the same element might override.
But if we have:
Legacy (in legacy layer):
.button { color: red; }
New (in components layer):
.button { color: blue; }
Then red wins because legacy is above components.
So we have to move the legacy style for that component out of the legacy layer (by deleting it) and then the new style in components will be the only one? But then if there is another legacy style that targets .button (maybe with a more specific selector) it will still be in the legacy layer and override? Yes.
So we have to move all legacy styles that target that component? That's a lot.
Given these challenges, maybe the best approach is to not use a single legacy layer, but to distribute the legacy styles into the appropriate layers (base, components, utilities, overrides) based on their function? That would require a massive refactor.
Alternatively, we can use layers only for new code and not touch the old code? Then we have:
New code: in layers (base, components, utilities, overrides) -> these are below unlayered? Then unlayered (old code) will override new code? That's bad.
So we must have the new code in layers that are above the old code? But then we have to put old code in a layer below? But old code is unlayered and unlayered is above named layers.
The only way to have new code above old code is to put old code in a named layer that is below the new layers. Therefore, we must move all old code to a named layer (legacy) and then have the new layers above.
So we have to move all old code to a legacy layer and then set the layer order as:
@layer legacy, base, components, utilities, overrides;
Then legacy is below base, etc. So new code in base will override legacy.
But then, as we saw, we might override legacy global styles that we want to keep.
So we must:
- Review the legacy styles and decide which ones we want to keep and which we want to override? Actually, we want to keep the legacy styles until we refactor them? But if we put a new style in base that overrides a legacy global style, we might break something.
Therefore, we should:
- Only use new layers for new components and for refactored components.
- When we refactor a component, we move its legacy styles from the legacy layer to the appropriate layer (and delete them from the legacy layer). Then, if there are global legacy styles that we want to keep, we leave them in the legacy layer and make sure our new styles don't conflict? But if we write a new style in base that conflicts with a global legacy style, it will override because base is above legacy.
So we must be cautious in base layer: only put styles that we want to override legacy global styles? Or we can put the global legacy styles that we want to keep into the base layer? Then we are effectively moving them.
This is getting too complex.
Given the time constraints of a sprint, perhaps we should:
- Not do a big bang migration of all legacy styles to a legacy layer.
- Instead, we only use layers for new code and for code that we are actively refactoring. We accept that unlayered (old) code will override new layered code? That's not acceptable.
Another idea: we can use `!important` in our new layers to override unlayered? That's a last resort.
Or, we can put our new styles in a layer that is above unlayered? But that's not possible because unlayered is above named layers.
Wait, we can create a layer that is above unlayered? No, unlayered is the highest (for author styles). So we cannot.
Therefore, we must eliminate unlayered styles to have control.
So we must move all existing styles to a layer. But then we have to decide the layer order.
Proposed pragmatic approach:
Step 1: Create the following layers (in this order):
@layer base, components, utilities, overrides, legacy;
Step 2: Move all existing CSS into the legacy layer (by wrapping in @layer legacy).
Step 3: Then, for new CSS, use the layers base, components, utilities, overrides.
This means that new CSS will be under legacy? Because legacy is the last layer (highest). So legacy will override new CSS? That's the opposite of what we want.
We want new CSS to override legacy when we refactor? Then we need to move the refactored component's styles from legacy to a layer above legacy? But legacy is the highest.
So we cannot override legacy unless we use !important.
So we need to put legacy below the new layers? Then we set:
@layer legacy, base, components, utilities, overrides;
Then legacy is below base, so base will override legacy.
But then, as we saw, base might override global legacy styles that we want to keep.
So we must move the global legacy styles that we want to keep from legacy to base? That's moving legacy to base.
Alternatively, we can have:
@layer base, components, utilities, overrides;
and then put legacy in the overrides layer? Then legacy is on top of utilities and components, but below any new overrides? Actually, overrides is the highest of the four. So if we put legacy in overrides, then legacy is in the overrides layer? Then new overrides would be in the same layer and would be after legacy in source order? That might work.
Let's try:
Layer order: base < components < utilities < overrides.
We put legacy in the overrides layer? Then:
@layer overrides {
/* legacy styles */
}
Then new styles in overrides (after the legacy block) will override legacy because they are later in source order within the same layer.
But then if we have new styles in base, components, utilities, they are below overrides (and below legacy because legacy is in overrides). So legacy (in overrides) will override new base styles? That might be acceptable because we want to preserve the current design.
Then when we refactor a component, we move its styles from the overrides layer (where we put legacy) to the appropriate layer (say, components). Then the new component style (in components) is below the legacy overrides? So the legacy override will still win? That's not good.
But if we move the component's styles from the overrides layer to the components layer, then we are removing them from overrides and putting them in a lower layer. Then any other legacy styles in overrides that target the same element will override the new component style? Yes.
So we must move all legacy styles that target that component from the overrides layer to the components layer? That's the same problem.
Given the time, I think the best approach for the sprint is:
- Use cascade layers only for new code and for code that we are refactoring in the same sprint.
- Do not move existing code to layers. Instead, leave existing code unlayered.
- Then, for new code, we use layers and we accept that unlayered code will override our new layered code? That's not acceptable.
So we must have a way to make new code override old. The only way is to use `!important` in the new code? That's a last resort.
Alternatively, we can change the layer order so that the new layers are above unlayered? But that's not possible.
Wait, we can use `@layer` without a layer order? Then the layer is created in the order of appearance? But unlayered is above all named layers.
So we cannot.
Therefore, we must move at least the conflicting old code to a layer below the new code.
Given the complexity, I propose:
- We do not do a big bang migration of all old CSS.
- Instead, we identify the components that we are going to refactor in this sprint and for each:
a) Move the old styles for that component to a layer (say, a layer named after the component, or to a 'legacy' layer) and then put that layer below the layer we are going to use for the new style? But we have a fixed layer order.
Alternatively, we can have:
For component X:
- We create a layer for component X's legacy styles and put it below the layer for the new component X? But the layer order is global.
So we can't have per-component layer order.
Given the constraints, perhaps the best is to accept that for the sprint, we will only use layers for new components that are not present in the old CSS? Then there is no conflict.
But that's limiting.
After reading the spec and thinking, I found:
The cascade order for layers is:
1. In a layer, the order is source order.
2. Between layers, the order is the order of the layer in the first @layer rule.
And unlayered is above all named layers.
So if we want new styles to override old, we must either:
- Move the old styles to a named layer that is below the new styles.
- Or, use !important in the new styles.
Since we are doing a sprint, we might not have time to move all old styles.
So let's change the plan:
We will not use layers for the entire project. Instead, we will use layers only for new styles that are for new components (with no existing styles) and for styles that are in components that we are refactoring and we are willing to move the old styles to a layer below.
For a component we are refactoring:
Step 1: Identify all old styles for that component (in the existing CSS).
Step 2: Move those old styles to a new layer called, say, `legacy-[component]` and make sure that layer is below the layer we will use for the new style.
But we have a fixed layer order? We can declare:
@layer base, components, utilities, overrides;
Then, for the component we are refactoring, we do:
In the old CSS, we wrap the old styles for that component in:
@layer legacy-button {
.button { ... }
}
But then we have to declare the layer order to include 'legacy-button'? And we want legacy-button to be below the new button styles? Then we have to put legacy-button below the layer we use for the new button.
We can do:
@layer base, components, utilities, overrides, legacy-button;
Then legacy-button is above overrides? That's not what we want.
We want:
legacy-button < components (for the new button)
So we need:
@layer base, legacy-button, components, utilities, overrides;
Then legacy-button is below components? Yes.
But then we have to declare this order for every component? That's not maintainable.
Given the complexity, I think we should postpone the full adoption of cascade layers until we can do a bigger refactor. For this sprint, we will:
- Use cascade layers only for new styles that are in new components (with no existing styles) and for new global styles (like new utilities) that don't conflict with existing ones.
- For refactoring existing components, we will not use layers for now, or we will use layers but only after moving the old styles to a layer that is below the new one? But that requires per-component layer order.
Alternatively, we can have a single layer for all legacy styles and then put that layer below the new layers? Then we set:
@layer legacy, base, components, utilities, overrides;
Then new styles in base will override legacy.
But then, as we saw, new base styles might override legacy global styles that we want to keep.
So we must move the legacy global styles that we want to keep from legacy to base? Then we are effectively moving them.
Given the time, I think we should:
- Create the layer order: @layer base, components, utilities, overrides;
- Move all existing CSS to a new layer called 'legacy' and put that layer below base? But then we have to change the order to:
@layer legacy, base, components, utilities, overrides;
Then legacy is below base, so base overrides legacy.
- Then, we move the legacy global styles that we want to keep to the base layer? That's a lot of work.
This is too big for a sprint.
Conclusion for the sprint:
We will not use cascade layers in this sprint because of the migration complexity. Instead, we will focus on color-mix() and logical properties, which can be adopted incrementally without affecting the cascade.
But the requirement was to introduce cascade layers.
Given the above, I propose a simplified plan for cascade layers:
- We will use cascade layers only for new styles that are added in new files or new components that do not exist in the current CSS.
- We will not move existing styles to layers.
- We will declare a layer order that has the new layers above the unlayered? But that's not possible.
Actually, we can do:
In the new CSS file, we can do:
@layer new-styles;
Then, in the HTML, we load this new CSS file after the old CSS? But unlayered (old) is above named layers? Actually, the order of stylesheets matters for unlayered vs layered? Let's see:
If we have:
old.css (unlayered)
new.css (with @layer new-styles { ... })
Then, the unlayered styles from old.css are above the layered styles in new.css? Because unlayered is above named layers, regardless of the order of the stylesheets? Actually, the cascade considers the origin and then the layer order, and then the order of the stylesheets? I think the order of the stylesheets matters for unlayered styles? Let me check:
The cascade:
- Importance
- Origin
- Layer order (if same origin and importance)
- Then, for unlayered styles, they are treated as a layer that is after all named layers? And then within the unlayered, the order of the stylesheets matters? Actually, the spec says:
"Styles that are not in a layer are considered to be in a final anonymous layer that comes after all named layers."
So the anonymous layer (unlayered) is after all named layers. Then, within the anonymous layer, the order is the order of the stylesheets and within the stylesheet.
So if we have:
old.css (unlayered) -> anonymous layer
new.css (named layer: new-styles) -> named layer
Then the anonymous layer (old) is after the named layer (new), so old overrides new.
So we cannot override old with new by just putting new in a named layer and loading it after.
Therefore, the only way to have new override old is to put old in a named layer that is below the new named layer.
So we must move old to a named layer.
Given the above, I think we have to do the big bang migration of old styles to a named layer (legacy) and then put legacy below the new layers.
Steps for the sprint:
Week 1:
- Audit the CSS and decide on the layer structure.
- Create a plan to move all existing CSS to a 'legacy' layer and set the layer order as:
@layer legacy, base, components, utilities, overrides;
This puts legacy below base, so base can override legacy.
- Then, for every existing CSS file, wrap the content in @layer legacy { ... }.
- Test to ensure the current design is preserved? Actually, we are moving legacy to a layer that is below base? Then base (which is currently empty) will not override legacy because base is below? Wait, the order is legacy < base < components < utilities < overrides.
So legacy is the lowest? Then base is above legacy, so base will override legacy.
But we haven't put anything in base yet, so it's okay.
- Then, when we add new base styles, they will override legacy? We don't want that for global legacy styles.
So we must move the global legacy styles that we want to keep from legacy to base? That's a lot.
Given the time, I think we should adjust the layer order to:
@layer base, components, utilities, overrides, legacy;
Then legacy is on top. Then new styles in base are below legacy and cannot override legacy.
Then when we refactor a component, we move its legacy styles from the legacy layer to the appropriate layer (say, components) and delete them from legacy. Then the new style (in components) will be below legacy? Because legacy is above components? Then legacy will still override? Only if there is a legacy style for that component in the legacy layer. But we removed it.
However, if there is another legacy style in the legacy layer that targets the same element, it will override the new style.
So we must remove all legacy styles that target the element we are refactoring? That's hard.
Given the complexity, I think we should not do cascade layers in this sprint. Instead, we should do:
- color-mix() with fallbacks
- logical properties in new code and when refactoring.
And for cascade layers, we do a separate spike to determine the best migration strategy.
But the requirement says to introduce cascade layers.
Alternatively, we can use cascade layers only for new utilities and new components that have no existing styles. Then we don't have to move old styles.
And for refactoring existing components, we don't use layers? Then we have two systems: layered and unlayered, and unlayered will override layered? That's not good.
Given the time, I think we have to accept that for this sprint, we will only use cascade layers for new code that is not conflicting with old code. And we will set the layer order so that new layers are above the old unlayered? But that's not possible.
Wait, we can load the new CSS (with layers) before the old CSS? Then the old CSS (unlayered) will be after the new CSS? But unlayered is above named layers regardless of order? Actually, the order of the stylesheets matters for unlayered? Let me test:
Suppose we have:
new.css:
@layer new {
.test { color: blue; }
}
old.css:
.test { color: red; }
And we load new.css first, then old.css.
Then, the .test in new.css is in a named layer (new) and the .test in old.css is unlayered.
According to the cascade, unlayered is above named layers, so red wins.
If we load old.css first, then new.css, then the unlayered red is still above the named layer blue? Yes.
So the order of the stylesheets doesn't matter: unlayered always wins over named layers.
Therefore, we cannot have new named layers override old unlayered without moving the old unlayered to a named layer that is below.
So we must move old unlayered to a named layer.
Given the above, I think we have to do the migration of all old CSS to a named layer (legacy) and then set the layer order so that legacy is below the new layers.
But then new layers will override legacy, which might break the design if we add new base styles that override legacy global styles.
So we must be cautious and only add new base styles that are safe (like new resets) and then for other new base styles, we might need to use more specific selectors or coordinate with the legacy.
Given the complexity, I think we should postpone cascade layers and focus on color-mix() and logical properties.
But the requirement is to introduce all three.
Final decision:
We will do the following:
1. For cascade layers:
- We will create a layer structure: base, components, utilities, overrides.
- We will move all existing CSS to a new layer called 'legacy' and set the layer order as:
@layer legacy, base, components, utilities, overrides;
This puts legacy at the bottom (lowest). Then base will override legacy, which is what we want for new base styles? But we don't want to override legacy global styles.
- Then, we will move the legacy global styles that we want to keep to the base layer? That's a lot of work.
Alternatively, we can put legacy in the overrides layer? Then legacy is on top? Then new styles in base are below legacy and cannot override.
I think we need to accept that we will have a long migration and for this sprint, we will:
- Move all existing CSS to a 'legacy' layer and put that layer at the bottom (so new layers are above and can override).
- Then, we will move the legacy global styles that we want to keep to the base layer? Actually, we want to keep the legacy global styles? Then we should leave them in legacy and make sure our new base styles don't conflict? But if we add a new base style that conflicts, it will override because base is above legacy.
So we must review the legacy global styles and decide which ones to keep and which to override? That's a design decision.
Given the time, we might have to do:
- Move all existing CSS to legacy layer (at the bottom).
- Then, for new base styles, we only add what is necessary and avoid overriding legacy global styles? But that's hard.
Alternatively, we can put legacy at the top? Then new styles cannot override legacy. Then when we refactor, we move the component's legacy styles from legacy to the appropriate layer (say, components) and then the new style (in components) will be below legacy? Then legacy will still override? Only if there is a legacy style for that component in the legacy layer. But we moved it, so there isn't. But there might be other legacy styles in legacy that target the same element? We have to move all legacy styles that target that element? That's the same problem.
So I think the only way is to move all legacy styles to the appropriate layers eventually.
Given the sprint time, we might have to limit the scope of cascade layers to:
- Only new components that have no existing styles.
- And for those, we put them in the appropriate layer (base, components, utilities, overrides) and we don't have to worry about legacy because there is no legacy for that component.
And for existing components, we do not use layers until we do a dedicated refactor.
But then we have a mix: some styles in layers, some not. And the unlayered (old) will override the layered (new) for the same selector? Actually, if we have a new component that has a class that is not used in old CSS, then there is no conflict.
So we can use layers for new components and new utilities that use new class names.
And for refactoring existing components, we don't use layers in this sprint.
Then, we can declare the layer order and use layers for new code.
And we leave old code unlayered.
Then, if a new component accidentally uses a class that exists in old code, the old code will override because unlayered > named layers.
So we must be cautious with class names.
This seems like the most pragmatic approach for a sprint.
So the plan:
Phase 1: Setup
- Audit existing CSS for class names that are generic and might be reused.
- Define layer order: @layer base, components, utilities, overrides;
Phase 2: For new components and new utilities:
- Use the appropriate layer (base for global resets, components for components, utilities for helpers, overrides for specific overrides).
- Use new class names that are not used in existing CSS to avoid conflicts.
Phase 3: For existing components, do not use layers. Continue to use the existing CSS.
Phase 4: For color-mix() and logical properties, use them in new code and when refactoring existing code (even without layers).
Phase 5: Testing.
This way, we get the benefit of layers for new code without the migration headache.
But note: if we add a new utility class that uses a class name that exists in old CSS, then the old CSS will override because unlayered > layers.
So we must ensure new class names are unique.
We can use a naming convention (like BEM) or a prefix for new classes.
Given the above, I'll adjust the plan:
- We will use a prefix for new class names to avoid conflicts with old. For example, new classes start with 'x-'.
Then we can safely use layers for new code.
So:
New button: <button class="x-button">... and in CSS:
@layer components {
.x-button { ... }
}
Then, even if there is an old .button, it won't conflict because the selector is different.
But what about global resets? We might want to reset elements in new components? Then we can use element selectors in base layer? But then if old CSS has element selectors, they will override because unlayered > base? Actually, base is a layer and old CSS might have element selectors too. But if we use the same element selector, the old one will win.
So for base layer, we should only use element selectors for things that are not set in old CSS? Or we use the prefix? We can't prefix element selectors.
Therefore, for base layer, we only add what is necessary and avoid overriding old element styles? Or we accept that old element styles will override our new base element styles? That might be acceptable because we are only adding new base styles for new elements? But base is for global resets.
Given the complexity, I think we should avoid using element selectors in the base layer for now, or only use them for new elements (like new HTML5 elements) that are not styled in old CSS.
Alternatively, we can move the old element styles to a layer? But that's the same problem.
Given the time, I think we should:
- Not use the base layer for element selectors that are already styled in old CSS.
- Only use the base layer for new element styles (e.g., new HTML elements) or for resets that we are sure are safe.
This is getting very complex.
Given the time, I think we should postpone cascade layers and only do color-mix() and logical properties.
But the requirement is to introduce all three.
After careful thought, I think we can do:
We will use cascade layers only for new styles that are in new files and use new class names (with a prefix). And we will not use the base layer for element selectors that might conflict. We will only use base for resets that are safe (like box-sizing) and that are not set in old CSS? But old CSS might set box-sizing.
Actually, we can use:
@layer base {
*, *::before, *::after {
box-sizing: border-box;
}
}
And if old CSS also sets box-sizing, then since base is a layer and old CSS is unlayered, the old CSS will win? That's not what we want.
So we have to make sure that our base layer styles are either not set in old CSS, or we move the old CSS setting to the base layer? That's moving old CSS.
Given the above, I think we have to accept that for this sprint, we will not get the full benefit of cascade layers for the entire project. We will use them only for new code and hope that there are no conflicts.
Alternatively, we can use a build step to add a prefix to all new class names? That's heavy.
Given the time, I propose:
We will not do cascade layers in this sprint. Instead, we will do:
- color-mix() with fallbacks.
- logical properties in new code and when refactoring.
And we will do a separate spike for cascade layers.
But the requirement says to introduce cascade layers.
Final plan for the sprint:
We will introduce cascade layers in a limited way:
- We will create a new stylesheet for new components and utilities.
- We will use a prefix for new class names (e.g., 'x-').
- We will use layers in that new stylesheet.
Example:
In new-components.css:
@layer components, utilities;
@layer components {
.x-button { ... }
}
@layer utilities {
.x-mt-4 { margin-block-start: 1rem; }
}
- We will not use the base layer for now.
- We will not move any existing styles.
Then, we can gradually add new components with the prefix and in layers.
And for refactoring existing components, we will not use layers in this sprint.
This way, we get the benefit of layers for new code without affecting old code.
And we can gradually adopt.
And we avoid conflicts because of the prefix.
Also, for color-mix() and logical properties, we will use them in new code and in refactored existing code (without layers).
So the sprint plan:
Week 1:
- Set up the new stylesheet for new components and utilities.
- Define the prefix (x-).
- Start writing new components with the prefix and in layers.
- Use color-mix() with fallbacks in new components.
- Use logical properties in new components.
Week 2:
- Refactor existing components that are being updated anyway (e.g., as part of other work) to use logical properties and color-mix() (without layers, because they don't have the prefix? We can keep the same class names but use logical properties and color-mix() in the existing CSS files? Yes, we can update existing CSS files to use logical properties and color-mix() without moving to layers.
Week 3:
- Continue with new components and refactoring.
- Test and fix any issues.
Week 4:
- Documentation and training.
This seems manageable.
Let's adjust the guardrails:
- For cascade layers: only use in new components with the prefix.
- For color-mix(): use with fallbacks in new code and in refactored existing code.
- For logical properties: use in new code and in refactored existing code.
We will not use the base layer for now because it might conflict with old element styles.
We will only use components and utilities layers for new prefixed classes.
And we will not move old code to layers.
This is a limited adoption, but safe.
Let's write the plan accordingly.
Final Sprint Plan:
Title: CSS Modernization Sprint: Cascade Layers (limited), color-mix(), and Logical Properties
Objectives:
1. Introduce cascade layers for new components and utilities (with a class prefix) to manage new styles without conflicting with existing ones.
2. Use color-mix() for dynamic color generation with fallbacks.
3. Adopt logical properties for better internationalization in new code and when refactoring existing code.
Guardrails:
- Only use cascade layers in the new stylesheet (new-components.css) and only for new components and utilities that use the prefix 'x-'.
- Do not use the base layer for element selectors to avoid conflicts with existing styles.
- For color-mix(), always provide a fallback using @supports or a solid color fallback.
- For logical properties, use them in new code and in refactored existing code, but test in both LTR and RTL layouts.
Phases:
Phase 1: Setup (Days 1-2)
- Create new-components.css.
- Add layer declarations: @layer components, utilities;
- Decide on prefix: 'x-' (or another).
- Set up build process to include new-components.css after existing CSS? Actually, the order of stylesheets doesn't matter for layers because we are using a prefix and the old CSS doesn't have the prefix, so no conflict. But we want the new styles to be available. We can load new-components.css after the main CSS to make sure the new classes are defined? Actually, the order of stylesheets matters for cascade if selectors have the same specificity and are in the same layer? But we are using different class names, so no conflict. But if we use the same element selector in base layer (which we are not using) then order matters? We are not using base layer.
We are only using components and utilities layers in new-components.css. And the old CSS is unlayered. Since we are using a prefix, there is no conflict. So we can load new-components.css anytime.
However, if we use logical properties and color-mix() in existing CSS files (without layers) then we need to make sure the browsers support them or we provide fallbacks. That's independent.
So we can load new-components.css in the head as usual.
Phase 2: New Components (Days 3-10)
- Start building new components using the prefix and placing them in the appropriate layer.
- Use color-mix() with fallbacks.
- Use logical properties for spacing and layout.
Example:
/* new-components.css */
@layer components, utilities;
@layer components {
.x-button {
/* fallback for color-mix */
background-color: var(--button-bg);
@supports (color: color-mix(in srgb, red, blue)) {
background-color: color-mix(in srgb, var(--button-bg) 80%, var(--button-hover-bg));
}
padding-block: 0.5rem;
padding-inline: 1rem;
}
}
@layer utilities {
.x-mt-2 {
margin-block-start: 0.5rem;
}
}
Phase 3: Refactoring Existing Code (Days 11-15)
- When working on existing components (as part of bug fixes or other features), update the CSS to use logical properties and color-mix() (with fallbacks) as appropriate.
- Do not move existing classes to the new prefix unless we are renaming the class? We are not renaming, so we keep the same class name but update the properties.
Example:
Existing CSS:
.alert {
margin-top: 1rem;
margin-left: 2rem;
background-color: var(--alert-bg);
}
Updated:
.alert {
margin-block-start: 1rem;
margin-inline-start: 2rem;
background-color: var(--alert-bg);
@supports (color: color-mix(in srgb, red, blue)) {
background-color: color-mix(in srgb, var(--alert-bg), var(--alert-border));
}
}
- We do not put this in a layer because it's an existing class. It remains in the existing CSS file (unlayered).
Phase 4: Testing (Days 16-17)
- Test in target browsers (including older ones for fallbacks).
- Test RTL layouts for logical properties.
Phase 5: Documentation and Training (Days 18-20)
- Update style guide with new practices.
- Document the prefix convention and when to use layers.
- Train the team.
Tools:
- Use PostCSS with postcss-color-mix to generate fallbacks automatically? Or use @supports.
Browser Support:
- color-mix(): Chrome 111+, Safari 16.4+, Firefox 113+.
For older browsers, we provide the fallback color.
- Logical properties: Good support, but check for very old browsers (IE11). If we support IE11, we might need to provide fallbacks? But logical properties are not supported in IE11. We can use postcss-logical to convert to physical properties for IE11? But that would defeat the purpose of using logical properties.
We can use:
.alert {
margin-top: 1rem; /* for IE11 */
margin-block-start: 1rem; /* for modern browsers */
}
But that duplicates.
Alternatively, we can use a build step to generate both? Or we can use feature queries:
@supports (margin-block-start: 1rem) {
.alert {
margin-block-start: 1rem;
margin-top: 0; /* reset if necessary */
}
}
But that's verbose.
Given that we are dropping IE11? If we are, then we can use logical properties without fallbacks.
So we need to check our browser support.
If we must support IE11, then we cannot use logical properties without fallbacks. We might need to use the PostCSS plugin to generate the fallbacks.
But the requirement says to adopt logical properties, so we assume we are not supporting IE11.
Similarly for color-mix(), we provide fallbacks for older browsers that don't support it.
So:
- For logical properties: use them directly, no fallback, but test in supported browsers. If we have to support IE11, then we need a different strategy.
Given the complexity, I think we should:
- Check browser support requirements. If IE11 is not required, then we use logical properties without fallbacks.
- If IE11 is required, then we might not be able to use logical properties in existing code that must work in IE11. We can use them in new code that doesn't support IE11? But that's inconsistent.
So let's assume we are not supporting IE11.
If we are, then we might have to skip logical properties for this sprint.
Given the above, the final plan is:
We will do:
- cascade layers: only for new components with prefix.
- color-mix(): with fallbacks.
- logical properties: without fallbacks (assuming no IE11).
And we will not use the base layer.
We will only use components and utilities layers.
And we will not move existing code to layers.
This is a limited adoption but safe and incremental.
Let me know if you have any questions.</think>
Logical property policy:
Use margin-inline/padding-block for new components only.
Existing components: no changes unless already being refactored.