HTML attributes
Every attribute Media Boxes reads on the grid, on items and media links and on outside controls, plus the hooks it sets for CSS and which options need JSON.
You can build a whole grid with attributes alone, with no script and no JSON. This page lists every attribute the engine reads, and the ones it sets so your CSS can use them.
On the <media-boxes> element #
These attributes are options. Changing one on a running grid, with setAttribute, updates the grid.
| Attribute | Option | Values | Example |
|---|---|---|---|
layout | layout | grid, masonry, justified, mosaic | layout="justified" |
columns | columns | A number, or auto | columns="4" |
min-column-width | minColumnWidth | A number in pixels | min-column-width="240" |
gap | gap | One number, or two (row column) separated by a space or comma | gap="16", gap="24 12" |
aspect-ratio | aspectRatio | A number, or W/H or W:H | aspect-ratio="3/2" |
row-height | rowHeight | A number in pixels | row-height="220" |
skin | skin | card, plain, caption, overlay, hover, image | skin="overlay" |
enter | enter | none, fade, fade-up, scale, flip | enter="scale" |
theme | theme | light, dark, auto | theme="auto" |
load | load.mode | all, button, scroll, pages | load="pages" |
initial | load.initial | A whole number | initial="12" |
step | load.step | A whole number | step="8" |
hover-overlay | hover.overlay | See Skins and captions | hover-overlay="slide-up" |
hover-image | hover.image | See Skins and captions | hover-image="zoom" |
filter | filters | One group, or several separated by commas. Each becomes a pills filter. | filter="category,tone" |
search | search | Present means on. search="false", "0", "off" and "no" mean off. | search |
lightbox | lightbox.enabled | false, 0, off or no turn it off | lightbox="false" |
Two other attributes matter: id (needed for deep links and for outside controls) and dir (rtl for right-to-left).
Options that have no attribute go in the JSON block or in el.options: lastRow, mosaicPattern, breakpoints, filterLogic, filter settings other than the group name, sort, deepLink, lightbox settings, items, showTerms, currency, locale, priceDecimals, videoBadge, stagger, duration and i18n.
The JSON options block #
<media-boxes id="work" columns="3">
<script type="application/json" data-mb-options>
{ "skin": "overlay", "sort": { "options": ["title", "date"] } }
</script>
<!-- items -->
</media-boxes>The block must be a direct child of the element and contain a JSON object. Attributes win over the block, so columns="3" above beats a "columns" in the JSON. Invalid JSON is reported in the console and ignored.
On items #
Each item is a direct child with the class mb-item.
| Attribute | Meaning |
|---|---|
data-id | A stable id, used by deep links, openLightbox('id') and removeItems('id'). Without it the item is mb-0, mb-1, and so on. |
data-<group> | The terms of a filter group, separated by commas, for example data-category="Nature, Outside". The group must be listed in filters. Without any filters, data-category is read. |
data-title | The title for sorting and search, when it should differ from the .mb-title text. |
data-date | An ISO date such as 2026-04-05. Used by the date sort key. |
data-cols, data-rows | Cells the item covers in mosaic. data-cols also works in masonry. |
data-mb-play | inline or lightbox. Where this item's video plays; wins over the videoPlay option. |
data-duration | The length of a video, such as 4:12, shown as a chip on the image. |
data-<name> | Any other data attribute. Numbers are kept as numbers. You can sort by it, and search it with search.fields. |
On the media link #
The .mb-media element is an <a> that opens the lightbox, or a <div> that does nothing.
| Attribute | Meaning |
|---|---|
href | The large image, video, embed address or #id of an HTML block. |
data-mb-src | The same as href, for a <div class="mb-media">. |
data-mb-type | image, video, youtube, vimeo, iframe, html or link. Detected from the address when omitted. See Lightbox. |
data-mb-width, data-mb-height | Natural size of the media. Gives the layout a ratio when the image has no size, and limits zoom. |
data-mb-caption | A longer caption for the lightbox. |
data-mb-poster | Poster image for a video slide. |
data-mb-srcset, data-mb-sizes | Candidates for the large image. |
Extra slides of an item go in a hidden <ul class="mb-gallery"> inside the item. See Lightbox.
On the <img>, width and height set the ratio of the thumbnail. If they are missing the engine measures the image once it loads.
Controls outside the grid #
Any element can drive a grid when it names the grid's id in data-mb-for. See Filtering and search.
| Attribute | On | Meaning |
|---|---|---|
data-mb-for | any control | The id of the grid it controls. |
data-mb-filter | a button | group:slug toggles one term. group alone clears the group. |
data-mb-sort | a button | key or key:desc. |
data-mb-search | an <input> | Filters the grid as you type. |
data-mb-load-more | a button | Adds the next step of items. |
Active controls get the class is-active and aria-pressed="true".
Attributes and classes the engine sets #
You never write these, but you can style on them.
| Where | What | Meaning |
|---|---|---|
media-boxes | data-ready | Present once the grid is built. |
media-boxes | data-skin, data-layout, data-theme, data-enter | The resolved option values. |
media-boxes | data-hover-overlay, data-hover-image | The resolved hover effects. |
.mb-grid | is-animated | Added after the first layout, when positions begin to animate. |
.mb-item | is-hidden, is-entering, is-leaving | Item states. |
.mb-media | is-loaded | The image finished loading (or failed). |
.mb-media | data-mb-dir | top, right, bottom or left: where the pointer entered or left, used by the direction overlay. |
.mb-filters | data-group, data-ui | The group name and its UI style. |
.mb-sort-order | data-order | asc or desc. |
.mb-filter, .mb-page | is-active, aria-pressed or aria-current | The selected state. |
| generated overlays and badges | data-mb-auto | Marks elements the engine added and may remove again. |
Markup structure after upgrade #
When the element starts, it wraps your items:
<media-boxes id="work" data-ready data-layout="masonry" data-skin="card">
<div class="mb-toolbar">...</div> <!-- only with filters, search or sort -->
<div class="mb-grid">... .mb-item ...</div>
<div class="mb-empty" hidden>...</div>
<div class="mb-footer">...</div> <!-- load more, pages or the scroll marker -->
<div class="mb-status mb-sr-only" aria-live="polite"></div>
</media-boxes>Call grid.destroy() to put your original items back.