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.// bad
{
'bermuda-triangle': {
display: 'none',
},
}
// good
{
bermudaTriangle: {
display: 'none',
},
}
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.
// bad
{
bruceBanner: {
color: 'pink',
transition: 'color 10s',
},
bruceBannerTheHulk: {
color: 'green',
},
}
// good
{
bruceBanner: {
color: 'pink',
transition: 'color 10s',
},
bruceBanner_theHulk: {
color: 'green',
},
}
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.
// bad
{
muscles: {
display: 'flex',
},
muscles_sadBears: {
width: '100%',
},
}
// good
{
muscles: {
display: 'flex',
},
muscles_fallback: {
width: '100%',
},
}
Use a separate selector for sets of fallback styles.
Why? Keeping fallback styles contained in a separate object clarifies their purpose, which improves readability.
// bad
{
muscles: {
display: 'flex',
},
left: {
flexGrow: 1,
display: 'inline-block',
},
right: {
display: 'inline-block',
},
}
// good
{
muscles: {
display: 'flex',
},
left: {
flexGrow: 1,
},
left_fallback: {
display: 'inline-block',
},
right_fallback: {
display: 'inline-block',
},
}
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.