placeholderify

Placeholderify CSS library

A pure CSS library that automatically transforms real HTML elements into placeholders to simplify loading states, without requiring any JavaScript or efforts from your side.

The classic approach requires designing separate HTML code for placeholders when a component is in a loading state. However, this means you have to manage and sync two versions of the element: the real one and its placeholder representation.

This CSS library allows you to manage only one version of an HTML component - the real HTML code. The library automatically converts the design of the real HTML elements into a placeholder style.

All you have to do is apply the placeholderify CSS class to the root HTML element of your component, and all child elements will be converted into placeholders automatically.

Example

Let’s imagine that you have a Bootstrap Card like this:

<div class="card">
  <img src="https://picsum.photos/600/400" class="card-img-top" alt="My image">
  <div class="card-body">
    <h5 class="card-title">Card title</h5>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="btn btn-primary">Go somewhere</a>
  </div>
</div>

And to make a placeholder from it, you should just add a CSS library and the placeholdify class to the component:

<link rel="stylesheet" media="all" href="//murznn.github.io/placeholderify/dist/placeholderify.min.css" />

<div class="card placeholderify" >
  <img src="https://picsum.photos/600/400" class="card-img-top" alt="My image">
  <div class="card-body">
    <h5 class="card-title">Card title</h5>
    <p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
    <a href="#" class="btn btn-primary">Go somewhere</a>
  </div>
</div>

And that’s it! 😎 No code duplication and no separate templates for placeholders!

To restore the real component, simply remove the placeholderify class.

Also, the library provides a placeholder for reloading element, when you don’t need to hide the current content, for that cases include the reloadify.css file and use the reloadify class.

For a live demonstration and customization options, check out the example HTML file.

Usage

The library provides several separate CSS files with different approaches:

Customization

The library supports customization through CSS variables. Here are the available options:

Opacity Settings

Background and Animation

Usage Example:

.my-custom-placeholder {
  --placeholderify-opacity: 0.5;
  --placeholderify-background-color: #e0e0e0;
  --placeholderify-cover-animation-duration: 1s;
}

Excluding specific elements

To exclude specific elements from being transformed into placeholders, add the placeholderify-ignore class to them.

Keeping images

In some cases you probably want to keep images visible in the placeholders. To keep only specific images visible, use the placeholderify-ignore class. To make all images visible - use the placeholderify-img.css file and the placeholderify-img class. See example HTML file with keeping images.

Shorten names

To make your HTML code more compact, the library provides shorten versions of classes in the correspoindig CSS files: