DocumentationHTML attributes

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.

AttributeOptionValuesExample
layoutlayoutgrid, masonry, justified, mosaiclayout="justified"
columnscolumnsA number, or autocolumns="4"
min-column-widthminColumnWidthA number in pixelsmin-column-width="240"
gapgapOne number, or two (row column) separated by a space or commagap="16", gap="24 12"
aspect-ratioaspectRatioA number, or W/H or W:Haspect-ratio="3/2"
row-heightrowHeightA number in pixelsrow-height="220"
skinskincard, plain, caption, overlay, hover, imageskin="overlay"
enterenternone, fade, fade-up, scale, flipenter="scale"
themethemelight, dark, autotheme="auto"
loadload.modeall, button, scroll, pagesload="pages"
initialload.initialA whole numberinitial="12"
stepload.stepA whole numberstep="8"
hover-overlayhover.overlaySee Skins and captionshover-overlay="slide-up"
hover-imagehover.imageSee Skins and captionshover-image="zoom"
filterfiltersOne group, or several separated by commas. Each becomes a pills filter.filter="category,tone"
searchsearchPresent means on. search="false", "0", "off" and "no" mean off.search
lightboxlightbox.enabledfalse, 0, off or no turn it offlightbox="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 #

html
<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.

AttributeMeaning
data-idA 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-titleThe title for sorting and search, when it should differ from the .mb-title text.
data-dateAn ISO date such as 2026-04-05. Used by the date sort key.
data-cols, data-rowsCells the item covers in mosaic. data-cols also works in masonry.
data-mb-playinline or lightbox. Where this item's video plays; wins over the videoPlay option.
data-durationThe 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.

The .mb-media element is an <a> that opens the lightbox, or a <div> that does nothing.

AttributeMeaning
hrefThe large image, video, embed address or #id of an HTML block.
data-mb-srcThe same as href, for a <div class="mb-media">.
data-mb-typeimage, video, youtube, vimeo, iframe, html or link. Detected from the address when omitted. See Lightbox.
data-mb-width, data-mb-heightNatural size of the media. Gives the layout a ratio when the image has no size, and limits zoom.
data-mb-captionA longer caption for the lightbox.
data-mb-posterPoster image for a video slide.
data-mb-srcset, data-mb-sizesCandidates 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.

AttributeOnMeaning
data-mb-forany controlThe id of the grid it controls.
data-mb-filtera buttongroup:slug toggles one term. group alone clears the group.
data-mb-sorta buttonkey or key:desc.
data-mb-searchan <input>Filters the grid as you type.
data-mb-load-morea buttonAdds 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.

WhereWhatMeaning
media-boxesdata-readyPresent once the grid is built.
media-boxesdata-skin, data-layout, data-theme, data-enterThe resolved option values.
media-boxesdata-hover-overlay, data-hover-imageThe resolved hover effects.
.mb-gridis-animatedAdded after the first layout, when positions begin to animate.
.mb-itemis-hidden, is-entering, is-leavingItem states.
.mb-mediais-loadedThe image finished loading (or failed).
.mb-mediadata-mb-dirtop, right, bottom or left: where the pointer entered or left, used by the direction overlay.
.mb-filtersdata-group, data-uiThe group name and its UI style.
.mb-sort-orderdata-orderasc or desc.
.mb-filter, .mb-pageis-active, aria-pressed or aria-currentThe selected state.
generated overlays and badgesdata-mb-autoMarks elements the engine added and may remove again.

Markup structure after upgrade #

When the element starts, it wraps your items:

html
<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.