JavaScript

Custom script

Create script.js in your project root. moss loads it after all built-in scripts, so the DOM is ready when your code runs.

// script.js
document.querySelectorAll('.moss-collection-card').forEach(card => {
  card.addEventListener('mouseenter', () => {
    card.style.transform = 'scale(1.02)';
  });
  card.addEventListener('mouseleave', () => {
    card.style.transform = '';
  });
});

No build step required. The file is loaded automatically on every page.

Data attributes

moss sets data attributes on HTML elements that you can read or style against.

AttributeElementValuesPurpose
data-theme<html>"light", "dark"Current color theme
data-moss-preview<body>present/absentSet when in preview mode
data-comments<article>"true", "false"Whether comments are enabled
data-source-lineheadings, paragraphsline numberSource markdown line (dev aid)
data-content-width<article>"wide"Content width override

Theme detection

const isDark = document.documentElement.getAttribute('data-theme') === 'dark';

DOM structure

The generated HTML follows a consistent structure across all pages.

<html data-theme="light">
  <body>
    <nav class="main-nav">
      <div class="nav-content">...</div>
    </nav>
    <main class="container">
      <article>
        <h1 class="article-title">...</h1>
        <div class="article-meta">
          <time class="article-date">...</time>
        </div>
        <!-- page content -->
      </article>
    </main>
    <footer class="moss-colophon">...</footer>
  </body>
</html>

Key elements to hook into:

SelectorWhat it is
.main-navTop navigation bar
.containerMain content wrapper
articlePage content area
.article-titlePage heading
.article-metaDate and metadata
.moss-colophonFooter

Safe to modify: Anything inside article and .moss-colophon. The navigation structure is managed by moss — add styles but avoid removing or reordering its children.

Published with moss