Skip to main content

Sass: Referencing Parent Selectors

You can select the parent selector by using the & character. It tells where the parent selector should be inserted.


Example of parent selectors in a SCSS file:

<title>Referencing Parent Selectors</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" href="">
<script src=""></script>
<script src=""></script>

<div class="container">
<h1>Example using Parent Selector</h1>
<a href=""> </a>

and the style.scss file:

a {
font-size: 20px;
&:hover { background-color: yellow; }

Then you tell Sass to watch the file and update the CSS when the file changes:

sass --watch my\path\style.scss:style.css

The generated style.css files is as shown below:

a {
font-size: 20px;

a:hover {
background-color: yellow;

Table of Contents