
Hiding Empty Elements with CSS

A very quick tip: the :empty CSS pseudo‑class is simple, easy to understand and (now) incredibly well‑supported. So, to hide an empty element, it is as simple as:
.classname:empty { // styles in here will only be applied // if the element is empty display: none;}:empty can be used on more‑or‑less any CSS selector or element type (although originally intended for form elements such as textarea which has not yet been written in), and will only apply if the targeted element is absolutely and entirely empty. This definition is extremely strict: it will not match an element that contains whitespace (e.g.: a single space). It also will not match an element which has children, even if they themselves are empty.
For a more experimental approach, :‑moz‑only‑whitespace will match any element which contains either nothing, or only whitespace. Unsurprisingly, however, support is limited to Firefox for the time being.
Whilst there is currently some discussion about how :only‑whitespace, :blank, and :empty might be defined in Selectors Level 4, at the time of writing nothing has yet been formally agreed or implemented by any of the browser vendors. It seems likely that eventually :empty will incorporate elements that contain whitespace too.
Related Articles

Disabling Text Selection Highlighting with CSS. 
Understanding JavaScript's sort() Method. Understanding JavaScript's
sort()Method
Rest and Spread Operators in JavaScript: A Beginner's Guide. Rest and Spread Operators in JavaScript: A Beginner's Guide

Using the Modulo Operator in JavaScript. Using the Modulo Operator in JavaScript

Understanding Short‑Circuiting in JavaScript. Understanding Short‑Circuiting in JavaScript
Looping in JavaScript ES5 and ES6: forEach and for...of. Looping in JavaScript ES5 and ES6:
forEachandfor...of
Angular Change Detection: How It Works and How to Optimise It. Angular Change Detection: How It Works and How to Optimise It

If Not Internet Explorer Conditional HTML. If Not Internet Explorer Conditional HTML

React's Virtual DOM vs. the Real DOM. React's Virtual DOM vs. the Real DOM

Understanding the Difference Between <b> and <strong>. Understanding the Difference Between
<b>and<strong>
Understanding setTimeout() in JavaScript. Understanding
setTimeout()in JavaScript
Using the CSS :has Pseudo‑Class. Using the CSS
:hasPseudo‑Class