
CSS media queries let us style elements based on the size of the screen. What if we wanted to style them based on the size of their container? A widget or block should often look different if it’s full-width or constrained within a column or sidebar, but we didn’t have any way to write container queries to style those elements based on their on-screen width… until now!
This plugin loads a small JavaScript file that conditionally applies classes to elements based on how wide those elements are in the browser. This can be used by other themes and plugins to write container-specific styles for editor blocks or widgets, so that they will display correctly wherever they are placed in the page.
The script works on the frontend and in the block editor — see your responsive styles live while you’re composing your post, and trust that your widgets and blocks will look their best whether they’re full-width or in the narrowest sidebar.
If you have a block or widget in your site that you wish to use as a responsive container, add the data-responsive-container attribute to that block’s container element. For example, the parent <div> for a calendar block might look like this:
<div class="calendar-block" data-responsive-container>
By adding that data-attribute and nothing more, your container will now be tagged with additional classes based on how big they appear:
– No special class if the container is below 420px (style for this narrow context as your default).
– container-sm if the container is 420px wide or more,
– container-md if it is wider than 600px,
– container-lg if it is wider than 720px, and
– container-xl for any element 960px or wider.
These are default values and therefore somewhat arbitrary, so you may also provide your own custom theme- or plugin-specific breakpoint values using the data-responsive-container attribute. When rendering your element or block in PHP, pass an array of class names and the minimum width at which each class should be applied. These class names can be generic like the default .container-* classes, or they may be specific to the element being styled:
echo sprintf( '<div class="myblock" data-responsive-container="%s">', esc_attr( wp_json_encode( [ 'myblock--2-column' => 600, 'myblock--3-column' => 900, ] ) );
In this example your container would receive the .myblock--2-column class from 600px up, and .myblock--3-column at or above 900px.
Note that in this case the .myblock element receives no custom class below 600px. We don’t apply any class names below your specified minimum because we assume styles are written narrow-context-first, but you may ensure your smallest class is always applied by providing a minimum width of 0:
echo sprintf( '<div class="myblock" data-responsive-container="%s">', esc_attr( wp_json_encode( [ 'myblock--1-column' => 0, // Will apply in all circumstances. 'myblock--2-column' => 600, 'myblock--3-column' => 900, ] ) );
This plugin is licensed under the terms of the GNU General Public License (or “GPL”). It is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
It was created by K. Adam White at Human Made, based on a concept popularized by Philip Walton.
This plugin utilizes the resize-observer-polyfill library by Denis Rul, released under the MIT license and © 2016 Denis Rul.
Starting from $0 per month.
Rating
Reviewers
No reviews
Tags
Developed By
K. Adam White
Quick & Easy
Common Ninja has a large selection of powerful Wordpress plugins that are easy to use, fully customizable, mobile-friendly and rich with features — so be sure to check them out!
Testimonial plugins for Wordpress
Galleries plugins for Wordpress
SEO plugins for Wordpress
Contact Form plugins for Wordpress
Forms plugins for Wordpress
Social Feeds plugins for Wordpress
Social Sharing plugins for Wordpress
Events Calendar plugins for Wordpress
Sliders plugins for Wordpress
Analytics plugins for Wordpress
Reviews plugins for Wordpress
Comments plugins for Wordpress
Portfolio plugins for Wordpress
Maps plugins for Wordpress
Security plugins for Wordpress
Translation plugins for Wordpress
Ads plugins for Wordpress
Video Player plugins for Wordpress
Music Player plugins for Wordpress
Backup plugins for Wordpress
Privacy plugins for Wordpress
Optimize plugins for Wordpress
Chat plugins for Wordpress
Countdown plugins for Wordpress
Email Marketing plugins for Wordpress
Tabs plugins for Wordpress
Membership plugins for Wordpress
popup plugins for Wordpress
SiteMap plugins for Wordpress
Payment plugins for Wordpress
Coming Soon plugins for Wordpress
Ecommerce plugins for Wordpress
Customer Support plugins for Wordpress
Inventory plugins for Wordpress
Video Player plugins for Wordpress
Testimonials plugins for Wordpress
Tabs plugins for Wordpress
Social Sharing plugins for Wordpress
Social Feeds plugins for Wordpress
Slider plugins for Wordpress
Reviews plugins for Wordpress
Portfolio plugins for Wordpress
Membership plugins for Wordpress
Forms plugins for Wordpress
Events Calendar plugins for Wordpress
Contact plugins for Wordpress
Comments plugins for Wordpress
Analytics plugins for Wordpress
Common Ninja Apps
Browse our extensive collection of compatible plugins, and easily embed them on any website, blog, online store, e-commerce platform, or site builder.
Showcase visuals with an image slider that displays multiple images in a smooth slideshow, improves design, and keeps visitors engaged.
Display Bluesky posts with a Bluesky feed carousel that auto updates, shows posts in a clear layout, and keeps visitors engaged.
Add an interactive spinning wheel to offer prizes, capture leads, and drive user engagement through gamified rewards.
Add an Instagram slider to your site to display social posts dynamically and keep your visual content engaging and current.
Create headlines with background images that blend text and visuals and let you control animation, position, and fonts.
Showcase photos with an image stack gallery that layers images in a stacked display with smooth transitions to create a visually striking presentation.
Create interactive quizzes with a quiz maker that lets you build custom questions, collect responses, and increase engagement with easy site integration.
Add customizable popups to your site to capture attention, deliver messages, and drive actions like signups or conversions.

Show Facebook posts in a live Facebook feed that keeps content fresh, boosts social proof, and helps visitors engage more with your brand.
Show inspiring quotes with a quotes carousel that rotates messages, enhances design, and keeps visitors engaged.
Add an event agenda to your site to display schedules clearly, helping users understand timing and plan their attendance.
Show payment method logos that highlight accepted payment options, build trust at checkout, and help visitors feel confident completing their purchase.
More plugins
The Common Ninja Search Engine platform helps website builders find the best site widgets, apps, plugins, tools, add-ons, and extensions! Compatible with all major website building platforms - big or small - and updated regularly, our Search Engine tool provides you with the business tools your site needs!
