Install
Hairline is two files: a stylesheet and a behavior script. It needs no build tools and depends on no framework.
Get the files
Both files are in this site’s assets folder. Copy them into your project:
| File | What’s in it | Size |
|---|---|---|
hairline.css | Every token (color, type, spacing, radius, shadow) and the styles for all components, in both day and night themes | 109 KB |
hairline.js | Behavior for dialogs, menus, the calendar, and other components. Optional: without it, components still display | 34 KB |
tokens.json | The raw token data, for design tools and other platforms. Its descriptions are in Chinese | 20 KB |
Hairline isn’t published to npm yet, and there’s no public CDN address. Keep the files in your own project and link to them there.
Include
Link the fonts and the stylesheet in the page’s <head>, and the script at the end of <body>:
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,500;0,6..72,600;1,6..72,400&family=Noto+Serif+SC:wght@600;700;900&display=swap">
<link rel="stylesheet" href="hairline.css">
<!-- Your content -->
<script src="hairline.js"></script>
- The two serif faces for titles, Newsreader and Noto Serif SC, load from Google Fonts. Offline, or where Google Fonts can’t be reached, titles fall back to the system’s Songti and Georgia.
- Text uses the system’s PingFang and San Francisco on Apple devices, and Noto Sans SC elsewhere. For a consistent look off Apple platforms, add Noto Sans SC to the font link.
- Put the script after the content, or add
defer.
Day and night themes
Set data-theme="light" or data-theme="dark" on <html>. Leave it out and the page follows the system’s light or dark setting. To let readers switch, write their choice to this attribute with a few lines of script. The switch at the top right of this site works that way.
Use the tokens
Every token is a CSS variable whose name starts with --hao-, so it won’t collide with variables already on your page. Where the docs say tint or space-4, you write var(--hao-tint) or var(--hao-space-4).
Language
Set lang="en" or lang="zh-CN" on <html>. Title size and letter spacing, paragraph alignment, quote marks, and the calendar’s weekdays and lunar dates all follow the language. See English interfaces.
Browsers
Hairline targets the last two years of Chrome, Safari, Edge, and Firefox. Patterns, icons, and moon phases use CSS masks. Automatic spacing between Chinese and Latin text and punctuation trimming are newer features. Older browsers skip them, and everything still works.