7 days of unlimited WordPress themes, plugins & graphics - for free!* Unlimited asset downloads! Start 7-Day Free Trial
  1. Web Design
  2. JavaScript

Quick Tip: Styling Restricted Content for Online Publishers

Scroll to top
Read Time: 4 mins

Many popular online newspapers (e.g. The Wall Street JournalLe Figaro, The Telegraph) offer some free content, but require users to purchase a subscription if they want unlimited reading.

And in a world where many people expect content on the internet to be free, finding the most suitable payment model is an ongoing challenge for online publishers.

“One of the most essential all-time challenges for journalism is its economic sustainability.” – Aurelija Gackaitė

Take for example a post from The Wall Street Journal, where users are permitted an excerpt of an article for free, but need to subscribe to gain access to the full piece:

A post from The Whole Street JournalA post from The Whole Street JournalA post from The Whole Street Journal

In this short tutorial, we’ll use JavaScript to mimic this behavior. First we’ll create a post with restricted content, masked by a gradient, and then we’ll let subscribed users reveal the full post.

Here’s our demo:

1. Begin With the Page Markup

We’ll start by using the article element to represent a typical blog post or newspaper article. We’ll also wrap it inside a .container for setting a maximum page width.

Here’s the relevant markup:

2. Add the CSS

By default we’ll add a not-member class to the html element (here we’re using the Add Class tool provided by CodePen:

Add the not-member class to the html elementAdd the not-member class to the html elementAdd the not-member class to the html element

This ensures that only a small part of the post will initially be visible to the readers:

The restricted post contentThe restricted post contentThe restricted post content

More specifically we’ll show just the header, the first two paragraphs, and the call-to-action links. We do this by using the “general sibling combinator” to select everything after the second paragraph (p:nth-child(2) ~ *) where .not-member is present:

Next we’ll add a few styles to the last visible paragraph (second). We’ll gradually hide its contents and add a padlock icon on top of it. These styles will let readers know that access is restricted to the whole article.

Here’s the CSS needed for this bit:

To round off these basic styling rules, we’ll style the call-to-action section:

3. Unlock Premium Content

For the purposes of our simple demo, let’s assume that a reader becomes a premium member each time he or she clicks on a call-to-action. 

In our case, at that point the not-member class is removed from the html element and the full post content becomes visible. 

Here's the JavaScript code responsible for that functionality:

By the time the full post appears, there’s no need to style the second paragraph differently as well as show the initial call-to-actions. So, let’s hide them all:

Finally, we can restart the subscription/unsubscription process by clicking on the Unsubscribe/Sign Out link which can be found at the bottom of the post content:

UnsubscribeSign Out linkUnsubscribeSign Out linkUnsubscribeSign Out link

Here’s the required JavaScript code:


In this quick tutorial, we built a simple demo that covered some ideas for styling restricted content. Similar techniques are used by big online newspapers and publishers, but you may find a use for this yourself.

We only simulated the subscription, so to implement this properly you would have to work out the signup process behind the scenes. And it’s important to note that the content we’ve hidden is only hidden visually–the page source still contains the restricted content. Bear this in mind if you’re publishing genuinely sensitive material.

As always, thanks for reading!

Read All About it!

Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Web Design tutorials. Never miss out on learning about the next big thing.
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.