Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1><span>Custom PostCSS Combinators Built Using <code>:has()</code></span><a href="https://twitter.com/branmcconnell" target="_blank">by @branmcconnell <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M24 4.557c-.883.392-1.832.656-2.828.775 1.017-.609 1.798-1.574 2.165-2.724-.951.564-2.005.974-3.127 1.195-.897-.957-2.178-1.555-3.594-1.555-3.179 0-5.515 2.966-4.797 6.045-4.091-.205-7.719-2.165-10.148-5.144-1.29 2.213-.669 5.108 1.523 6.574-.806-.026-1.566-.247-2.229-.616-.054 2.281 1.581 4.415 3.949 4.89-.693.188-1.452.232-2.224.084.626 1.956 2.444 3.379 4.6 3.419-2.07 1.623-4.678 2.348-7.29 2.04 2.179 1.397 4.768 2.212 7.548 2.212 9.142 0 14.307-7.721 13.995-14.646.962-.695 1.797-1.562 2.457-2.549z"/></svg></a></h1>
<div class="examples">
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 01</h3>
			<strong><span>x <span class="comb">+</span> y</span></strong>
			<p><span>x + y</span></p>
		</div>
		<div class="example-inner" id="example_01_correct"><y></y><y></y><y></y><y></y><y></y><x></x><y class="filled"></y><y></y><y></y><y></y><y></y></div>
		<div class="example-inner" id="example_01"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 02</h3>
			<strong><span>x <span class="comb">++</span> y</span></strong>
			<p><span>x ~ y</span></p>
		</div>
		<div class="example-inner" id="example_02_correct"><y></y><y></y><y></y><y></y><y></y><x></x><y class="filled"></y><y class="filled"></y><y class="filled"></y><y class="filled"></y><y class="filled"></y></div>
		<div class="example-inner" id="example_02"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 03</h3>
			<strong><span>x <span class="comb">+3</span> y</span></strong>
			<p><span>x + * + * + y</span></p>
		</div>
		<div class="example-inner" id="example_03_correct"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y class="filled"></y><y></y><y></y></div>
		<div class="example-inner" id="example_03"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 04</h3>
			<strong><span>x <span class="comb">+&lt;3</span> y</span></strong>
			<p><span>x + y,<br>x + * + y,<br>x + * + * + y</span></p>
		</div>
		<div class="example-inner" id="example_04_correct"><y></y><y></y><y></y><y></y><y></y><x></x><y class="filled"></y><y class="filled"></y><y class="filled"></y><y></y><y></y></div>
		<div class="example-inner" id="example_04"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 05</h3>
			<strong><span>x <span class="comb">+&gt;3</span> y</span></strong>
			<p><span>x + * + * ~ y</span></p>
		</div>
		<div class="example-inner" id="example_05_correct"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y class="filled"></y><y class="filled"></y><y class="filled"></y></div>
		<div class="example-inner" id="example_05"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 06</h3>
			<strong><span>x <span class="comb">-</span> y</span></strong>
			<p><span>y:has(+ x)</span></p>
		</div>
		<div class="example-inner" id="example_06_correct"><y></y><y></y><y></y><y></y><y class="filled"></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
		<div class="example-inner" id="example_06"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 07</h3>
			<strong><span>x <span class="comb">--</span> y</span></strong>
			<p><span>y:has(~ x)</span></p>
		</div>
		<div class="example-inner" id="example_07_correct"><y class="filled"></y><y class="filled"></y><y class="filled"></y><y class="filled"></y><y class="filled"></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
		<div class="example-inner" id="example_07"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 08</h3>
			<strong><span>x <span class="comb">-3</span> y</span></strong>
			<p><span>y:has(+ * + * + x)</span></p>
		</div>
		<div class="example-inner" id="example_08_correct"><y></y><y></y><y class="filled"></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
		<div class="example-inner" id="example_08"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 09</h3>
			<strong><span>x <span class="comb">-&lt;3</span> y</span></strong>
			<p><span>y:has(+ x, + * + x, + * + * + x)</span></p>
		</div>
		<div class="example-inner" id="example_09_correct"><y></y><y></y><y class="filled"></y><y class="filled"></y><y class="filled"></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
		<div class="example-inner" id="example_09"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 10</h3>
			<strong><span>x <span class="comb">-&gt;3</span> y</span></strong>
			<p><span>y:has(~ * + * + x)</span></p>
		</div>
		<div class="example-inner" id="example_10_correct"><y class="filled"></y><y class="filled"></y><y class="filled"></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
		<div class="example-inner" id="example_10"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 11</h3>
			<strong><span>x <span class="comb">%</span> y</span></strong>
			<p><span>x + y,<br>y:has(+ x)</span></p>
		</div>
		<div class="example-inner" id="example_11_correct"><y></y><y></y><y></y><y></y><y class="filled"></y><x></x><y class="filled"></y><y></y><y></y><y></y><y></y></div>
		<div class="example-inner" id="example_11"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 12</h3>
			<strong><span>x <span class="comb">%%</span> y</span></strong>
			<p><span>x ~ y,<br>y:has(~ x)</span></p>
		</div>
		<div class="example-inner" id="example_12_correct"><y class="filled"></y><y class="filled"></y><y class="filled"></y><y class="filled"></y><y class="filled"></y><x></x><y class="filled"></y><y class="filled"></y><y class="filled"></y><y class="filled"></y><y class="filled"></y></div>
		<div class="example-inner" id="example_12"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 13</h3>
			<strong><span>x <span class="comb">%3</span> y</span></strong>
			<p><span>x + * + * + y,<br>y:has(+ * + * + x)</span></p>
		</div>
		<div class="example-inner" id="example_13_correct"><y></y><y></y><y class="filled"></y><y></y><y></y><x></x><y></y><y></y><y class="filled"></y><y></y><y></y></div>
		<div class="example-inner" id="example_13"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 14</h3>
			<strong><span>x <span class="comb">%&lt;3</span> y</span></strong>
			<p><span>x + y,<br>x + * + y,<br>x + * + * + y,<br>y:has(+ x, + * + x, + * + * + x)</span></p>
		</div>
		<div class="example-inner" id="example_14_correct"><y></y><y></y><y class="filled"></y><y class="filled"></y><y class="filled"></y><x></x><y class="filled"></y><y class="filled"></y><y class="filled"></y><y></y><y></y></div>
		<div class="example-inner" id="example_14"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="peer example">
		<div class="example-heading">
			<h3>Example 15</h3>
			<strong><span>x <span class="comb">%&gt;3</span> y</span></strong>
			<p><span>x + * + * ~ y,<br>y:has(~ * + * + x)</span></p>
		</div>
		<div class="example-inner" id="example_15_correct"><y class="filled"></y><y class="filled"></y><y class="filled"></y><y></y><y></y><x></x><y></y><y></y><y class="filled"></y><y class="filled"></y><y class="filled"></y></div>
		<div class="example-inner" id="example_15"><y></y><y></y><y></y><y></y><y></y><x></x><y></y><y></y><y></y><y></y><y></y></div>
	</div>
	<div class="nested example">
		<div class="example-heading">
			<h3>Example 16</h3>
			<strong><span>x <span class="comb">&gt;</span> y</span></strong>
			<p><span>x &gt; y</span></p>
		</div>
		<div class="example-inner" id="example_16_correct"><y><y><x><y class="filled"><y></y></y></x></y></y></div>
		<div class="example-inner" id="example_16"><y><y><x><y><y></y></y></x></y></y></div>
	</div>
	<div class="nested example">
		<div class="example-heading">
			<h3>Example 17</h3>
			<strong><span>x <span class="comb">&lt;</span> y</span></strong>
			<p><span>y:has(> x)</span></p>
		</div>
		<div class="example-inner" id="example_17_correct"><y><y class="filled"><x><y><y></y></y></x></y></y></div>
		<div class="example-inner" id="example_17"><y><y><x><y><y></y></y></x></y></y></div>
	</div>
	<div class="nested example">
		<div class="example-heading">
			<h3>Example 18</h3>
			<strong><span>x <span class="comb">&lt;&gt;</span> y</span></strong>
			<p><span>x > y,<br>y:has(> x)</span></p>
		</div>
		<div class="example-inner" id="example_18_correct"><y><y class="filled"><x><y class="filled"><y></y></y></x></y></y></div>
		<div class="example-inner" id="example_18"><y><y><x><y><y></y></y></x></y></y></div>
	</div>
	<div class="nested example">
		<div class="example-heading">
			<h3>Example 19</h3>
			<strong><span>x y</span></strong>
			<p><span>x y</span></p>
		</div>
		<div class="example-inner" id="example_19_correct"><y><y><x><y class="filled"><y class="filled"></y></y></x></y></y></div>
		<div class="example-inner" id="example_19"><y><y><x><y><y></y></y></x></y></y></div>
	</div>
	<div class="nested example">
		<div class="example-heading">
			<h3>Example 20</h3>
			<strong><span>x <span class="comb">^</span> y</span></strong>
			<p><span>y:has(x)</span></p>
		</div>
		<div class="example-inner" id="example_20_correct"><y class="filled"><y class="filled"><x><y><y></y></y></x></y></y></div>
		<div class="example-inner" id="example_20"><y><y><x><y><y></y></y></x></y></y></div>
	</div>
	<div class="nested example">
		<div class="example-heading">
			<h3>Example 21</h3>
			<strong><span>x <span class="comb">^<span style="display: inline-block; transform: rotate(180deg);">^</span></span> y</span></strong>
			<p><span>x y,<br>y:has(x)</span></p>
		</div>
		<div class="example-inner" id="example_21_correct"><y class="filled"><y class="filled"><x><y class="filled"><y class="filled"></y></y></x></y></y></div>
		<div class="example-inner" id="example_21"><y><y><x><y><y></y></y></x></y></y></div>
	</div>
</div>
              
            
!

CSS

              
                $system: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
body {
	font-family: $system;
}
h1 {
	text-align: center;
	span {
		display: block;
		@media (max-width: 699px) { max-width: 23ch; }
		margin: min(2vw, 20px) auto 0;
		font-size: min(5vw, 28px);
		text-align: center;
		code {
			color: blueviolet;
		}
	}
	a {
		display: inline-block;
		position: relative;
		padding: 8px 16px 10px;
		margin: 12px auto 0;
		background-color: #1da1f2;
		border-radius: 500px;
		font-size: 14px;
		font-weight: 500;
		color: #fff;
		text-decoration: none;
		border-bottom: 3px solid #0d83e8;
		transition: all .15s linear;
		&:active {
			margin: 12px auto 3px;
			border-bottom-width: 0;
			transform: translateY(3px);
		}
		svg {
			position: relative;
			top: 3px;
			margin-left: 4px;
			width: 17px;
			height: auto;
			fill: currentcolor;
		}
	}
}
.examples {
	// display: flex;
	// flex-direction: column;
	// gap: min(2vw, 20px);
	// padding: min(2vw, 20px);
	display: grid;
	grid-template-columns: 1fr;
	@media (min-width: 600px) {
		grid-template-columns: repeat(auto-fill, minmax(500px, 1fr));
	}
	align-items: stretch;
	gap: min(2vw, 20px);
	padding: min(2vw, 20px);
}
.example {
	display: flex;
	flex-direction: column;
	align-items: stretch;
	justify-content: center;
	padding: 0;
	border: 3px solid blueviolet;
	border-radius: 5px;
	&.nested {
		.example-inner {
			padding-bottom: min(8vw, 80px);
			> y {
				transform: translateX(calc(-1 * min(3.5vw, 35px)));
			}
			x > y {
				margin-top: clamp(1px, .3vw, 3px);
				margin-left: clamp(1px, .3vw, 3px);
			}
			x::after {
				width: 87.5%;
				height: 87.5%;
			}
		}
	}
	.example-heading {
		text-align: center;
		flex: 1;
		h3 {
			padding: 5px 0;
			margin: 0 0 10px;
			background-color: blueviolet;
			color: #fff;
		}
		strong, p {
			display: flex;
			flex-direction: column;
			font-family: consolas, monospace;
			font-weight: 400;
			padding-inline: 10px;
			margin: 0 0 10px;
			.comb { color: blueviolet; }
			.comb, &::before { font-weight: 700; }
			&::before { margin-bottom: 5px; }
		}
		strong::before {
			content: "Combinator";
			font-family: $system;
		}
		p::before {
			content: "Implementation";
			font-family: $system;
		}
	}
	.example-inner {
		display: flex;
		align-items: flex-start;
		justify-content: center;
		flex-wrap: wrap;
		gap: 5px;
		padding: 10px;
		margin-bottom: 10px;
		x, y {
			position: relative;
			width: min(3vw, 30px);
			aspect-ratio: 1;
			background-color: white;
			border: clamp(1.5px, .2vw, 2px) solid blueviolet;
			border-radius: clamp(1px, .5vw, 8px);
			&.filled {
				background-color: blueviolet;
			}
			> x, y {
				position: absolute;
				width: 100%;
				height: 100%;
				left: 50%;
				top: 50%;
				z-index: 1;
			}
			> y {
				box-shadow: 0 0 0 clamp(1.5px, .2vw, 2px) white;
			}
		}
		x {
			border-color: transparent;
			background-color: transparent;
			&::after {
				content: "";
				display: block;
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate(-50%, -50%);
				width: 75%;
				height: 75%;
				background-color: #e22b84;
				border-color: #e22b84;
				border-radius: 50%;
				box-shadow: 0 0 0 clamp(1.5px, .2vw, 2px) white;
				animation: pulse 1.5s ease-in-out normal infinite;
			}
		}
		&::before {
			display: block;
			width: 100%;
			margin-bottom: 5px;
			text-align: center;
			font-weight: 700;
		}
		&:is([id*="_correct"])::before {
			content: "Should be";
		}
		&:not([id*="_correct"])::before {
			content: "Actually rendered";
		}
		&#example {
			&_01 x + y,
			&_02 x ~ y,
			&_03 x + * + * + y,
			&_04 x + y,
			&_04 x + * + y,
			&_04 x + * + * + y,
			&_05 x + * + * ~ y,
			&_06 y:has(+ x),
			&_07 y:has(~ x),
			&_08 y:has(+ * + * + x),
			&_09 y:has(+ x, + * + x, + * + * + x),
			&_10 y:has(~ * + * + x),
			&_11 x + y,
			&_11 y:has(+ x),
			&_12 x ~ y,
			&_12 y:has(~ x),
			&_13 x + * + * + y,
			&_13 y:has(+ * + * + x),
			&_14 x + y,
			&_14 x + * + y,
			&_14 x + * + * + y,
			&_14 y:has(+ x, + * + x, + * + * + x),
			&_15 x + * + * ~ y,
			&_15 y:has(~ * + * + x),
			&_16 x > y,
			&_17 y:has(> x),
			&_18 x > y,
			&_18 y:has(> x),
			&_19 x y,
			&_20 y:has(x),
			&_21 x y,
			&_21 y:has(x) {
				background-color: blueviolet;
			}
		}
	}
}
@keyframes pulse {
	0% {
		// transform: translate(-50%, -50%) scale(1) rotate(0deg);
		opacity: 1;
		// border-radius: inherit;
	} 50% {
		// transform: translate(-50%, -50%) scale(.5) rotate(0deg);
		opacity: .5;
		// border-radius: 50%;
	} 100% {
		// transform: translate(-50%, -50%) scale(1) rotate(90deg);
		opacity: 1;
		// border-radius: inherit;
	}
}
              
            
!

JS

              
                
              
            
!
999px

Console