Naming

  • Use camelCase for object keys (i.e. “selectors”).

    Why? We access these keys as properties on the styles object in the component, so it is most convenient to use camelCase.

    1. // bad
    2. {
    3. 'bermuda-triangle': {
    4. display: 'none',
    5. },
    6. }
    7. // good
    8. {
    9. bermudaTriangle: {
    10. display: 'none',
    11. },
    12. }
  • Use an underscore for modifiers to other styles.

    Why? Similar to BEM, this naming convention makes it clear that the styles are intended to modify the element preceded by the underscore. Underscores do not need to be quoted, so they are preferred over other characters, such as dashes.

    1. // bad
    2. {
    3. bruceBanner: {
    4. color: 'pink',
    5. transition: 'color 10s',
    6. },
    7. bruceBannerTheHulk: {
    8. color: 'green',
    9. },
    10. }
    11. // good
    12. {
    13. bruceBanner: {
    14. color: 'pink',
    15. transition: 'color 10s',
    16. },
    17. bruceBanner_theHulk: {
    18. color: 'green',
    19. },
    20. }
  • Use selectorName_fallback for sets of fallback styles.

    Why? Similar to modifiers, keeping the naming consistent helps reveal the relationship of these styles to the styles that override them in more adequate browsers.

    1. // bad
    2. {
    3. muscles: {
    4. display: 'flex',
    5. },
    6. muscles_sadBears: {
    7. width: '100%',
    8. },
    9. }
    10. // good
    11. {
    12. muscles: {
    13. display: 'flex',
    14. },
    15. muscles_fallback: {
    16. width: '100%',
    17. },
    18. }
  • Use a separate selector for sets of fallback styles.

    Why? Keeping fallback styles contained in a separate object clarifies their purpose, which improves readability.

    1. // bad
    2. {
    3. muscles: {
    4. display: 'flex',
    5. },
    6. left: {
    7. flexGrow: 1,
    8. display: 'inline-block',
    9. },
    10. right: {
    11. display: 'inline-block',
    12. },
    13. }
    14. // good
    15. {
    16. muscles: {
    17. display: 'flex',
    18. },
    19. left: {
    20. flexGrow: 1,
    21. },
    22. left_fallback: {
    23. display: 'inline-block',
    24. },
    25. right_fallback: {
    26. display: 'inline-block',
    27. },
    28. }
  • Use device-agnostic names (e.g. “small”, “medium”, and “large”) to name media query breakpoints.

    Why? Commonly used names like “phone”, “tablet”, and “desktop” do not match the characteristics of the devices in the real world. Using these names sets the wrong expectations.

    1. // bad
    2. const breakpoints = {
    3. mobile: '@media (max-width: 639px)',
    4. tablet: '@media (max-width: 1047px)',
    5. desktop: '@media (min-width: 1048px)',
    6. };
    7. // good
    8. const breakpoints = {
    9. small: '@media (max-width: 639px)',
    10. medium: '@media (max-width: 1047px)',
    11. large: '@media (min-width: 1048px)',
    12. };