Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ add another resource


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


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.


Auto Save

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.


	<h1>Calculate the Specificity of CSS Selectors with <code>@bramus/specificity</code></h1>
	<p><em>Supports CSS Selectors Level 4</em></p>
	<form onsubmit="return false;" autocomplete="off">
		<label for="selector">Selector(s):</label>
		<input type="text" name="selector" id="selector" value="a, .foo :is(.bar, #baz), main > p" placeholder=" " autocomplete="off" autocorrect="off" autocapitalize="off" optional />
		<label for="specificity">Number of detected Selectors</label>
		<output name="num_selectors" id="num_selectors">…</output>
		<label for="specificity">Specificity per Selector:</label>
		<output name="specificity" id="specificity">…</output>
		<label for="specificity">Highest Specificity:</label>
		<output name="highest_specificity" id="highest_specificity">…</output>
		<label for="specificity">Lowest Specificity:</label>
		<output name="lowest_specificity" id="lowest_specificity">…</output>

	<p>Demo for <a href="" target="_top"></a><br />Introductory Blogpost: <a href="" target="_top"></a><br />Looking for a fancier calculator? <a href="" target="_top"></a></p>


                * {
	box-sizing: border-box;

header {
	text-align: center;
header :is(h1, p) {
	margin: 0;

html {
	line-height: 1.75;
	font-size: 1.25em;
	height: 100%;
	padding: 0;

body {
	min-height: 100%;
	margin: 0;
	padding: 2em;
	display: grid;
	place-content: center;

body > * {
	width: 90%;
	max-width: 70ch;
	margin: auto;

#selector, output {
	font-family: monospace;

output {
	display: block;

/* Borrowed from pico … */
:root {
	--line-height: 1.5;
	--font-weight: 400;
	--font-size: 16px;
	--font-family: system-ui, -apple-system, "Segoe UI", "Roboto", "Ubuntu",
		"Cantarell", "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji",
		"Segoe UI Symbol", "Noto Color Emoji";
	--spacing: 1rem;
	--form-element-spacing-vertical: 0.25rem;
	--form-element-spacing-horizontal: 0.5rem;
	--border-radius: 0.25rem;
	--border-width: 1px;
	--primary: #1095c1;
	--primary-inverse: #fff;
	    --primary-hover: #08769b;
	--button-box-shadow: 0 0 0 rgba(0, 0, 0, 0);
	    --block-spacing-vertical: calc(var(--spacing) * 2);
	    --block-spacing-horizontal: calc(var(--spacing) * 1.75);
	--card-background-color: #f4f4f4;
	--card-box-shadow:0 0.125rem 1rem rgba(27, 40, 50, 0.04),0 0.125rem 2rem rgba(27, 40, 50, 0.08),0 0 0 0.0625rem rgba(27, 40, 50, 0.024);
	--transition: 0.2s ease-in-out;

body {
	font-family: var(--font-family);
	font-weight: var(--font-weight);
	font-size: var(--font-size);
	text-rendering: optimizeLegibility;
	line-height: var(--line-height);

form {
    margin: var(--block-spacing-vertical) 0;
    padding: var(--block-spacing-vertical) var(--block-spacing-horizontal);
    overflow: hidden;
    border-radius: var(--border-radius);
    background: var(--card-background-color);
    box-shadow: var(--card-box-shadow);

label {
	display: block;
	margin-bottom: calc(var(--spacing) * 0.25);

input, output {
	margin: 0;
	font-size: 1rem;
	font-family: inherit;
	letter-spacing: inherit;
	--border-color: currentcolor;
	border: var(--border-width) solid var(--border-color);
	border-radius: var(--border-radius);
	outline: 0;
	width: 100%;
	margin-bottom: var(--spacing);
	min-height: calc(
		1rem * var(--line-height) + var(--form-element-spacing-vertical) * 2 +
			var(--border-width) * 2
	appearance: none;
	padding: var(--form-element-spacing-vertical)

input:focus {
    --border-color: var(--primary);

footer {
	text-align: center;
	font-size: 0.8rem;
	font-style: italic;


                import Specificity from "";

const format = (selector) => `<code>${selector}</code> <em>${selector.selectorString()}</em>`;

const updateUI = () => {
	document.querySelector('#num_selectors').innerHTML = `0`;
	document.querySelector('#specificity').innerHTML = ``;
	document.querySelector('#highest_specificity').innerHTML = ``;
	document.querySelector('#lowest_specificity').innerHTML = ``;
	const selector = document.querySelector('#selector').value;
	try {
		const specificities = Specificity.calculate(selector);
		document.querySelector('#num_selectors').innerHTML = specificities.length;
		if (specificities.length) {
			document.querySelector('#specificity').innerHTML = => `- ${format(s)}`).join('<br />');
			document.querySelector('#highest_specificity').innerHTML = format(Specificity.max(...specificities));
			document.querySelector('#lowest_specificity').innerHTML = format(Specificity.min(...specificities));
	} catch (e) {
		document.querySelector('#specificity').innerHTML = `❌ ${e.message}`;

document.querySelector('#selector').addEventListener('input', (e) => {