Categories
React Answers

How to define more than one style name using CSS modules with React?

Spread the love

Sometimes, we want to define more than one style name using CSS modules with React.

In this article, we’ll look at how to define more than one style name using CSS modules with React.

How to define more than one style name using CSS modules with React?

To define more than one style name using CSS modules with React, we can put them class names in one string.

For instance, we write

function Footer(props) {
  return (
    <div className={styles.footer}>
      <div className={`${styles.description} ${styles.yellow}`}>
        <p>this site was created by me</p>
      </div>
    </div>
  );
}

to set the className prop of the inner prop to

`${styles.description} ${styles.yellow}`

to apply multiple classes imported from the CSS module.

Conclusion

To define more than one style name using CSS modules with React, we can put them class names in one string.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *