Pen Settings

HTML

CSS

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

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

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.

HTML

              
                
<div id="root">
	<h1>Check CSS inheritance for all supported properties</h1>
	<form id="form">
		<label for="form-filter">Filter by keywords:</label>
		<input id="form-filter" name="filter" type="text" placeholder="Enter keywords…">
		<label for="form-sort">Sort by:</label>
		<select id="form-sort" name="sort">
			<option value="prop-asc">Property ASC</option>
			<option value="prop-desc">Property DESC</option>
			<option value="value-asc">Value ASC</option>
			<option value="value-desc">Value DESC</option>
			<option value="inherits-asc">Inherits ASC</option>
			<option value="inherits-desc">Inherits DESC</option>
		</select>
		<button type="submit">Update</button>
	</form>
	<p>Total: <span id="total">0</span></p>
	<table id="table" border="1" cellspacing="0" cellpadding="5">
		<thead>
			<th>Property</th>
			<th>Value</th>
			<th>Inherits</th>
		</thead>
		<tbody id="table-body">
		</tbody>
	</table>
</div>

<hr>

<h2>Test</h2>
<div id="test-parent">
	Parent
	<div id="test-child">
		Child
	</div>
</div>

              
            
!

CSS

              
                table {
	width: 100%;
	max-width: 100ch;
}

td:last-child {
	white-space: nowrap;
}

/* Force different box sizes to prevent false positives. */
#test-parent {
	margin: 12px;
	padding: 12px;
	border: 12px solid;
}

#test-child {
	margin: 13px;
	padding: 13px;
	border: 13px solid;
}

              
            
!

JS

              
                const style = window.getComputedStyle(document.body);

const props = Object.keys(style).filter((key) => Number.isNaN(Number(key)));

let values = props.reduce((result, prop) => {
    result[prop] = style[prop];
    return result;
}, {});

function inherits(prop, value) {
	const parent = window['test-parent'];
	const child = window['test-child'];
	let hasMatch = false;

	if (value === '') {
		// Empty
		// ¯\_(ツ)_/¯
	} else if (value.match(/^rgb\(.+\)$/)) {
		// Color: RGB
		hasMatch = true;
		parent.style[prop] = 'rgb(1, 2, 3)';
	} else if (value.match(/^rgba\(.+\)$/)) {
		// Color: RGBA
		hasMatch = true;
		parent.style[prop] = 'rgba(1, 2, 3, 4)';
	} else if (!Number.isNaN(Number(value))) {
		// Number: Unitless
		hasMatch = true;
		
		let possibleValues = new Set(['0', '0.5', '1', '2', '123']);
		possibleValues.delete(value);
		possibleValues = Array.from(possibleValues);
		
		for (let val of possibleValues) {
			parent.style[prop] = val;
			if (window.getComputedStyle(parent)[prop] === val) {
				break;
			}
		}
	} else if (value.match(/^([\d.]+px ?)+$/)) {
		// Number: Pixels
		hasMatch = true;
		parent.style[prop] = value.replace(/[\d.]+px/, '123px');
	} else if (value.match(/^([\d.]+% ?)+$/)) {
		// Number: Percentages
		hasMatch = true;
		parent.style[prop] = value.replace(/[\d.]+%/, '123%');
		// DEBUG
		// console.log(parent.style[prop]);
	}
	
	if (hasMatch) {
		const parentStyle = window.getComputedStyle(parent)[prop];
		const childStyle = window.getComputedStyle(child)[prop];
		const result = parentStyle === childStyle;

		// DEBUG:
		// console.log({
		// 	prop,
		// 	value,
		// 	parentStyle,
		// 	childStyle,
		// 	inherits: result,
		// });

		parent.style[prop] = '';

		return result ? 1 : 0;
	}
	
	return -1;
}

function inheritsText(inherits) {
	return inherits === -1 ? '❓ Unknown' : (inherits ? '✅ Yes' : '❌ No');
}

values = Object.entries(values).map(([prop, value]) => ({
	prop,
	value,
	inherits: inherits(prop, value),
}));

function updateTable() {
	// Values
	const filter = form.elements.filter.value;
	const sort = form.elements.sort.value;
	let [sortProp, sortDir] = sort.split('-');
	sortDir = sortDir === 'asc' ? 1 : -1;
	
	let result = values.filter(({ prop, value, inherits }) => (
		`${prop} ${value} ${inheritsText(inherits)}`.toLowerCase()
			.includes(filter.toLowerCase())
	));

	result = result.sort((a, b) => {
		let _a = a[sortProp];
		let _b = b[sortProp];

		if (_a < _b) { return -1 * sortDir; }
		if (_a > _b) { return 1 * sortDir; }

		return 0;
	});

	result = result.map(({ prop, value, inherits }) => `
		<tr>
			<td>${prop}</td>
			<td>${value}</td>
			<td>${inheritsText(inherits)}</td>
		</tr>
	`);

	window['table-body'].innerHTML = result.join('');
	total.innerHTML = result.length;

	// Save
	localStorage.setItem('form-filter', filter);
	localStorage.setItem('form-sort', sort);
}

const initialFormFilterValue = localStorage.getItem('form-filter');
const initialFormSortValue = localStorage.getItem('form-sort');

if (initialFormFilterValue) {
	window['form-filter'].value = initialFormFilterValue;
}
if (initialFormSortValue) {
	window['form-sort'].value = initialFormSortValue;
}

updateTable();

form.addEventListener('input', updateTable);
form.addEventListener('submit', (event) => {
	event.preventDefault();
	updateTable();
});

              
            
!
999px

Console