Milligram CSS Framework
Milligram is a minimalist CSS framework designed to provide a lightweight and clean starting point for web projects. Weighing in at only 2kb gzipped, it prioritizes performance and developer productivity by offering a basic set of styles with fewer properties to reset compared to larger UI frameworks. It focuses on core HTML elements like typography, forms, tables, buttons, and a simple grid system. The current stable version is 1.4.1, released in 2023, following a cadence of sporadic updates that address compatibility and add minor feature enhancements, such as responsive tables and new form input types. Its primary differentiation lies in its extreme minimalism, providing only essential styling without dictating a specific UI component library.
Common errors
-
My custom styles are being unexpectedly overridden, or Milligram styles don't seem to apply correctly.
cause Incorrect order of CSS imports or missing Normalize.css.fixEnsure `normalize.css` is imported/linked *before* `milligram.css` in your project. Custom styles should typically be included *after* Milligram to allow for proper overrides. -
My page's typography looks different after upgrading Milligram.
cause Milligram v1.2.0 removed its custom font family definition, relying on `normalize.css` defaults.fixExplicitly define your desired font-family in your custom CSS if you had specific requirements that Milligram previously handled. -
Buttons with a disabled class no longer appear styled as disabled.
cause The `.button-disabled` class was removed in Milligram v1.2.0.fixUse the native `disabled` HTML attribute on `<button>` elements, which Milligram styles by default, or create a custom class for disabled button styling. -
My layouts are broken, or elements are taking up unexpected space, potentially due to box-sizing.
cause Milligram v1.1.0 changed all elements to inherit `box-sizing` from the root.fixEnsure your `html` and `body` elements have `box-sizing: border-box;` defined (often done via `normalize.css` or a reset) for consistent behavior. -
Milligram styles are not loading, or I'm seeing a blank unstyled page in a JavaScript project.
cause Incorrect import path for the Milligram CSS file in your JavaScript entry point or bundler configuration.fixVerify the import statement `import 'milligram/dist/milligram.min.css';` is correct and placed after any `normalize.css` import. Check your bundler configuration for proper CSS loading.
Warnings
- breaking Milligram v1.2.0 removed support for Internet Explorer 6 and 7. Projects requiring compatibility with these legacy browsers should use an older version or provide custom fallbacks.
- breaking The `.button-disabled` class was removed in Milligram v1.2.0. Existing elements relying on this class for disabled styling will lose their visual state.
- breaking Milligram v1.2.0 removed its custom font family definition, now deferring to the default specified by `normalize.css`. This may alter your project's typography if you previously relied on Milligram's implicit font stack.
- breaking In Milligram v1.1.0, all elements were updated to inherit `box-sizing` from the root element. This change ensures consistent box model behavior but could break layouts if your root element (html or body) does not have a `box-sizing` property defined or if you had specific element-level `box-sizing` overrides.
- breaking The `.blockquote` class was removed in Milligram v1.0.3.
Install
-
npm install milligram -
yarn add milligram -
pnpm add milligram
Imports
- Milligram CSS via HTML
<link rel="stylesheet" href="milligram.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.min.css">
- Milligram CSS via bundler
import { milligram } from 'milligram';import 'milligram/dist/milligram.min.css';
- Milligram CSS via CSS @import
@import 'milligram';
@import url('https://cdnjs.cloudflare.com/ajax/libs/milligram/1.4.1/milligram.min.css');
Quickstart
// main.js or App.js (for a React/Vue/Angular project using a bundler)
// 1. Ensure normalize.css is included for consistent base styles.
// You might already have this from a project setup tool.
import 'normalize.css';
// 2. Import Milligram's main CSS file.
// This assumes you have installed it via npm/yarn: `npm install milligram`
import 'milligram/dist/milligram.min.css';
// Now, your application's components will automatically pick up Milligram's styles.
// For example, a simple React component demonstrating usage:
import React from 'react';
function App() {
return (
<div className="container" style={{maxWidth: '960px', margin: '0 auto', padding: '20px'}}>
<h1>Welcome to My App</h1>
<p>This paragraph is styled by Milligram. It's a lightweight and modern CSS framework.</p>
<button className="button-primary">Click Me</button>
<button>Learn More</button>
<form>
<fieldset>
<label htmlFor="nameField">Your Name</label>
<input type="text" placeholder="Jane Doe" id="nameField" />
<label htmlFor="ageRange">Age Range</label>
<select id="ageRange">
<option value="0-18">0-18</option>
<option value="19-35">19-35</option>
<option value="36+">36+</option>
</select>
<input className="button-primary" type="submit" value="Submit" />
</fieldset>
</form>
</div>
);
}
export default App;