Better Programming

Advice for programmers.

Follow publication

Member-only story

12 Coding Examples of Ampersand Usages in Styled Components

Jennifer Fu
Better Programming
Published in
11 min readJul 6, 2022

Photo by TJ Arnold on Unsplash

styled-components is a popular library to style React applications. We have introduced what it is and how to use it and provided 7 ways to inherit styles using styled components.

In this article, we are going to talk about ampersand usages. In styled-components, & (ampersand) is used to refer to all instances of the component. Supported by the preprocessor, stylis, & is used to write clean code for nesting. & originates from Sass and Less, which are CSS extensions.

We reused the Create React App working environment in the last article to explore the ampersand usages. The following package has been installed in the environment:

  • styled-components

Here is the list of examples:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Write a response