-
Couldn't load subscription status.
- Fork 204
Update CSS Best Practices #408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: gh-pages
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmtrmrv - really great job, I fully support your guidance here, I left quite a few comments - feel free to accept or ignore the suggestions. I would like to see some more concrete examples of using modern (supported) css to achieve cleaner outcomes, perhaps that can be a phase 2 thing.
| When you start a new codebase, pause before writing components and choose a CSS methodology—such as ITCSS, BEM, or a utility-first approach—that fits the project’s size, maintenance horizon, and team expertise. Committing to a structured methodology early establishes clear naming rules, predictable specificity, and sensible file organization. These guardrails ease onboarding, minimize refactors, and save both time and budget over the life of the project. | ||
|
|
||
| Let's be honest, CSS "speed" and performance is not as important as PHP or JavaScript performance. However, this doesn't mean we should ignore it. A sum of small improvements equals better experience for the user. | ||
| If you opt to design a custom architecture, capture every key choice: folder layout, naming conventions, tooling, and any deviations from common patterns. A short explanation of why each decision was made helps future contributors understand the system quickly and avoids guesswork. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmtrmrv Im wondering if we should include something about AI here - certain AI prompts for specific frameworks that can help with context sharing or standardization. Even the use of AI to better understand the CSS implementation - where theres overlap / redundancy or bloated code.
| * If you need more complex animations, use a JavaScript animation framework or requestAnimationFrame. | ||
| * **Reach for media queries last.** Instead of relying heavily on media queries to adjust styles, focus on building layouts and components that adapt naturally to different screen sizes. Media queries should be a fallback for cases where intrinsic solutions won’t work. | ||
| * **Leverage clamp().** Use the clamp() function to create fluid, responsive values for properties like font sizes, spacing, and widths. It allows you to define a minimum, preferred, and maximum value, so elements scale dynamically without needing media queries. | ||
| * **Use intrinsic layouts with CSS Grid.** Grid layouts are inherently responsive and let you define flexible areas that adjust automatically to available space. Pair grids with techniques like minmax() and auto-fit for dynamic behavior without extra breakpoints. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is huge and an often poorly considered point - would love to expand on this further
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed - at least maybe a link to a 3rd party article to start. This would be a great Learning & Knowledge session internally!
| ### Animations (@keyframes) | ||
|
|
||
| * Use clear action-based names (e.g., fade-in, slide-up). | ||
| * Maintain short, intuitive names indicating the animation’s behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmtrmrv if using ITCSS, its worth noting where Animations should be placed within the triangle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really awesome work! I'm sorry that some of this feedback should have been in the GDoc - but sometime swicthing context brings new perspective.
Please reach out to the team if you have any questions, thoughts, or would like some help moving anything forward!
Also, I 100% defer to you on any of my suggestions. Feel free to disregard/ignore as you see fit!
Otherwise - I approve!
| 2. Regular styles (allows overriding extended styles) | ||
| 3. @include (to visually separate mixins and placeholders) and media queries | ||
| 4. Nested selectors | ||
| By thoughtfully implementing and balancing resets, normalization, and custom global styles, you can establish a CSS foundation that fosters maintainability, consistency, and scalability for your project. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that suggestion, but also remember this best practices is to be somewhat agnostic - where we can be more prescriptive within our tooling or internal guides.
|
|
||
| ### Example | ||
|
|
||
| Let’s say you have a Card component. Avoid doing this: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that I see this, I am wondering if we should add an example where we use relative values (i.e. em) to provide relative margin depending on context for vertical rhythm (i.e. headings)? I know you mention the lobotomized owl below, but this is an area I do see folks get hung up on - so a quick and easy example might be helpful. I 100% defer to you though! Simply a suggestion. If you feel this is an anti-pattern - please ignore.
| * If you need more complex animations, use a JavaScript animation framework or requestAnimationFrame. | ||
| * **Reach for media queries last.** Instead of relying heavily on media queries to adjust styles, focus on building layouts and components that adapt naturally to different screen sizes. Media queries should be a fallback for cases where intrinsic solutions won’t work. | ||
| * **Leverage clamp().** Use the clamp() function to create fluid, responsive values for properties like font sizes, spacing, and widths. It allows you to define a minimum, preferred, and maximum value, so elements scale dynamically without needing media queries. | ||
| * **Use intrinsic layouts with CSS Grid.** Grid layouts are inherently responsive and let you define flexible areas that adjust automatically to available space. Pair grids with techniques like minmax() and auto-fit for dynamic behavior without extra breakpoints. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed - at least maybe a link to a 3rd party article to start. This would be a great Learning & Knowledge session internally!
Co-authored-by: Joe Snell <[email protected]>
Co-authored-by: Joe Snell <[email protected]>
Co-authored-by: Joe Snell <[email protected]>
Co-authored-by: Joe Snell <[email protected]>
… choices in documentation
…ing-Best-Practices into feature/css-best-practices
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work!
This is a clear, thoughtful, and highly practical guide.
I like the emphasis on content-first thinking, mobile-first strategy, and accessibility throughout.
The guidance on keeping specificity low, avoiding overuse of shorthands, and managing margins/gaps at the container level is really great!
The stress-testing mindset, sensible use of logical properties, and progressive enhancement with @supports and clamp() make the recommendations both modern and pragmatic.
The structure is easy to follow, examples are actionable, and the tone encourages consistency and collaboration.
Overall, this reads like a playbook teams can adopt with confidence. Great job!
I left some minor comments regarding consistency and some minor checking on grammar/clarity. There are also some suggestions on Accessibility around motion, let me know what you think!
| Style the project as if Desktop doesn’t exist first and then expand or override rules for the desktop. | ||
|
|
||
| Avoid: | ||
| With the capabilities of modern CSS it is usually best to reach for media queries last and use features like auto-rows in CSS Grid or functions like clamp() to create layouts that are mobile and desktop-friendly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I agree, I'm not sure this should live within a Best Practices doc?
Co-authored-by: Antonio Laguna <[email protected]>
Co-authored-by: Antonio Laguna <[email protected]>
Co-authored-by: Antonio Laguna <[email protected]>
Co-authored-by: Antonio Laguna <[email protected]>
…ing-Best-Practices into feature/css-best-practices
Co-authored-by: Joe Snell <[email protected]>
Description of the Change
This PR completely restructures and modernizes the CSS best practices documentation (
_includes/markdown/CSS.mdandcss.md) to provide more comprehensive, actionable, and modern guidance for writing maintainable CSS.Benefits:
Verification steps:
css.mdmatches the new section structureHow to test the Change
Build and serve the Jekyll site locally:
bundle install bundle exec jekyll serveNavigate to the CSS section (
/css/) and verify:Cross-reference with the main index page (
/) to ensure:Validate content accuracy:
Changelog Entry
Credits
Props @dmtrmrv @joesnellpdx @dainelmawer @Antonio-Laguna
Checklist: