Enforce consistent, maintainable code across the project following modern web standards.
Use semantic HTML elements over generic divs:
<!-- ✓ Correct -->
<header>
<nav>
<ul>
<li><a href="/">Home</a></li>
</ul>
</nav>
</header>
<main>
<article>
<h1>Article Title</h1>
<section>
<h2>Section Heading</h2>
<p>Content...</p>
</section>
</article>
</main>
<footer>
<p>© 2024</p>
</footer>
<!-- ✗ Avoid -->
<div class="header">
<div class="nav">
<div class="nav-item">Home</div>
</div>
</div>- One
<h1>per page - Proper heading hierarchy (no skipped levels)
- Use
<section>and<article>appropriately
Use CSS Grid and Flexbox for layout:
/* ✓ Correct - CSS Grid */
.grid-layout {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
gap: var(--space-md);
}
/* ✓ Correct - Flexbox */
.flex-layout {
display: flex;
flex-wrap: wrap;
gap: var(--space-sm);
}
/* ✗ Avoid - floats for layout */
.old-layout {
float: left;
width: 33.33%;
}Use CSS custom properties for theming:
/* ✓ Define in :root */
:root {
--color-primary: #1a1a2e;
--color-secondary: #16213e;
--color-accent: #e94560;
--space-xs: 0.25rem;
--space-sm: 0.5rem;
--space-md: 1rem;
--space-lg: 2rem;
--space-xl: 4rem;
--font-body: system-ui, sans-serif;
--font-heading: Georgia, serif;
}
/* ✓ Use throughout */
.component {
color: var(--color-primary);
padding: var(--space-md);
font-family: var(--font-body);
}Prefer logical properties for internationalization:
/* ✓ Correct - logical properties */
.component {
margin-inline: auto;
padding-block: var(--space-md);
border-inline-start: 2px solid var(--color-accent);
}
/* ✗ Avoid - physical properties when logical exists */
.component {
margin-left: auto;
margin-right: auto;
padding-top: 1rem;
padding-bottom: 1rem;
}Write semantic, maintainable CSS:
/* ✓ Correct - semantic class names */
.product-card {
display: grid;
gap: var(--space-md);
padding: var(--space-lg);
background: var(--color-surface);
border-radius: 8px;
}
.product-card__title {
font-size: 1.25rem;
font-weight: 600;
}
/* ✗ Avoid - utility classes */
<div class="flex flex-col gap-4 p-8 bg-white rounded-lg">Start with mobile, enhance for larger screens:
/* ✓ Mobile-first */
.component {
padding: var(--space-sm);
}
@media (min-width: 768px) {
.component {
padding: var(--space-md);
}
}
@media (min-width: 1024px) {
.component {
padding: var(--space-lg);
}
}Use modern JavaScript features:
// ✓ Correct - const/let, arrow functions, destructuring
const processItems = (items) => {
const { data, meta } = items;
return data.map((item) => ({
...item,
processed: true,
}));
};
// ✓ Correct - async/await
const fetchData = async (url) => {
try {
const response = await fetch(url);
return await response.json();
} catch (error) {
console.error('Fetch failed:', error);
throw error;
}
};Prefer native web components:
// ✓ Correct - Custom Element
class ProductCard extends HTMLElement {
connectedCallback() {
this.render();
}
render() {
this.innerHTML = `
<article class="product-card">
<h2>${this.getAttribute('title')}</h2>
</article>
`;
}
}
customElements.define('product-card', ProductCard);Core functionality without JavaScript:
<!-- ✓ Works without JS, enhanced with JS -->
<details class="accordion">
<summary>Section Title</summary>
<div class="accordion__content">Content here...</div>
</details>
<!-- Enhanced with JavaScript for animations -->kebab-casefor files:product-card.js,main-header.css- Component files match component name:
ProductCard→product-card.js
- BEM methodology:
block__element--modifier - Semantic names describing purpose, not appearance
/* ✓ Correct */
.product-card {
}
.product-card__title {
}
.product-card--featured {
}
/* ✗ Avoid */
.red-box {
}
.left-aligned {
}
.big-text {
}camelCasefor variables and functionsPascalCasefor classes and componentsUPPER_SNAKE_CASEfor constants
src/
├── components/
│ ├── product-card.js
│ └── product-card.css
├── layouts/
│ └── main-layout.css
├── utilities/
│ └── helpers.js
└── index.js
- External dependencies
- Internal modules
- Styles
- Types (if TypeScript)
// External
import { createApp } from 'framework';
// Internal
import { formatPrice } from './utilities/helpers.js';
import { ProductCard } from './components/product-card.js';
// Styles
import './styles/main.css';- Agents check against these rules before completing tasks
- Pre-commit hook validates compliance
- Review agent uses these as evaluation criteria