Skip to content

Conversation

@dmtrmrv
Copy link

@dmtrmrv dmtrmrv commented Aug 21, 2025

Description of the Change

This PR completely restructures and modernizes the CSS best practices documentation (_includes/markdown/CSS.md and css.md) to provide more comprehensive, actionable, and modern guidance for writing maintainable CSS.

Benefits:

  • More actionable guidance for developers at all levels
  • Better alignment with modern CSS development practices
  • Improved maintainability and scalability guidance
  • Enhanced accessibility considerations throughout
  • Clear migration path for adopting new CSS features

Verification steps:

  1. Review the updated table of contents in css.md matches the new section structure
  2. Verify all internal anchor links work correctly
  3. Check that code examples are syntactically correct and follow established formatting
  4. Ensure the mobile-first and accessibility principles are consistently applied throughout

How to test the Change

  1. Build and serve the Jekyll site locally:

    bundle install
    bundle exec jekyll serve
  2. Navigate to the CSS section (/css/) and verify:

    • All navigation links in the sidebar work correctly
    • Internal anchor links jump to the correct sections
    • Code examples are properly formatted and highlighted
    • Content flows logically from general principles to specific implementation details
  3. Cross-reference with the main index page (/) to ensure:

    • CSS section links are updated and functional
    • The updated navigation structure is reflected in the homepage listing
  4. Validate content accuracy:

    • Review code examples for correctness
    • Ensure all external links are functional
    • Verify that the guidance aligns with current CSS best practices

Changelog Entry

Changed - Completely restructured and modernized CSS best practices documentation with updated methodologies, modern CSS features guidance, and enhanced practical examples

Credits

Props @dmtrmrv @joesnellpdx @dainelmawer @Antonio-Laguna

Checklist:

Copy link
Contributor

@dainemawer dainemawer left a 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.
Copy link
Contributor

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.
Copy link
Contributor

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

Copy link
Collaborator

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.
Copy link
Contributor

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.

Copy link
Collaborator

@joesnellpdx joesnellpdx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmtrmrv

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.
Copy link
Collaborator

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:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmtrmrv

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.
Copy link
Collaborator

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!

Copy link
Member

@Antonio-Laguna Antonio-Laguna left a 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.
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants