An open-source, inline CSS framework powered by data-attributes.
An open-source, inline CSS framework powered by data-attributes.
What is Hydrogen?
Hydrogen is a CSS framework that combines the power of inline styling with the efficiency of token-style settings to help you create consistent, beautiful experiences.
How does it work?
Hydrogen scans your code for data-h2
attributes, parses their values, and seamlessly creates a production-ready CSS file containing exactly what you've asked for.
Why should I use it?
Hydrogen helps you move beyond the chaos of maintaining CSS. It handles naming methodologies, typography, and enforcing your brand all while being fast, legible, and open-source.
Hydrogen's syntax supports any CSS property you can think of (and a few custom ones) while enhancing them with configurable, inline queries and modifiers. You can write familiar CSS syntax while easily targeting custom themes, dark mode, and interaction states.
and more...
Rather than compiling a library, Hydrogen generates CSS on the fly by scanning your code and parsing unique data-h2
attributes. Integrate it into your build tools and run it in the background as you develop for on-demand styling.
1
2
3
4
5
6
☼ Hydrogen - System - Starting the build...
Message > Hydrogen v1.1.20
☼ Hydrogen - System - 28 files were processed...
☼ Hydrogen - System - Exporting CSS...
☼ Hydrogen - Timers - 0646ms (Total build)
☼ Hydrogen - Success - Exporting CSS
Embracing a design-token-style approach, Hydrogen's configuration allows you to centrally define decisions such as color, typography, and shadows. These values then become usable in Hydrogen's attributes, allowing you to update them product-wide in a matter of seconds.
Inline media queries
Define media queries in your configuration and then call them directly in attributes.
Inline states
Style native HTML interaction states like :hover
and :focus
right in your markup.
Inline selectors
Using the :selectors
modifier, apply styles to a specific ID, class, or attribute.
Inline nested elements
Using the :children
modifier, apply styles to nested tags or selectors for bulk styling.
Automated dark mode
Define sibling values for dark mode and apply them instantly using a single value.
Automated theming
Create entire themes for your project and apply them app-wide in an instant.
Automated typography
Automatically generate a type scale, vertical rhythm, and whitespace tokens.
Open-source code
Hydrogen is provided under an MIT license; fork the code and change it to suit your needs.
Install Hydrogen using NPM
Ensure you have Node installed on your machine. Then navigate to your project in a terminal and run the NPM installation command to install Hydrogen.
1
npm install @hydrogen-css/hydrogen --save
Create a configuration file
From your project, run the h2-init
command to create a configuration file. You'll be asked to specify your input and output directories.
1
npx h2-init
Add data-h2
to your html
element
To apply Hydrogen to your entire project, add the data-h2
attribute to your html
element. Hydrogen's styles won't work outside of this attribute, so feel free to apply it elsewhere if you only need to style a subset of your project.
1
2
3
4
<!DOCTYPE html>
<html data-h2>
<body />
</html>
Import the Hydrogen CSS file
Like any other CSS file, you'll need to import Hydrogen's CSS into the head
of your document.
1
2
3
4
<head>
...
<link rel="stylesheet" href="path/to/hydrogen.css">
</head>
Use Hydrogen to style an element
Now that the CSS file is ready to be loaded in, you can start going wild with Hydrogen attributes to style your project.
1
2
3
<p data-h2-color="base(primary)">
Hello!
</p>
Watch the magic
When you're ready to view your masterpiece, you can run the build (or watch) command to compile your custom built CSS file.
1
npx h2-build
Installation
Styling
Properties