@ghs-hazard-pictograms/css

中文文档
1.1.0发布于 2026/11/16MITTypeScriptESM + CJS构建来源已验证近 30 天下载 4794

CSS background-image sprite for GHS hazard and ADR/UN transport pictograms — class-based display, no JavaScript required

原始使用文档
文档目录11 节
  1. Installation
  2. Quick start
  3. CSS class reference
  4. GHS chemical hazard pictograms
  5. UN transport hazard class pictograms
  6. JavaScript / TypeScript API
  7. getCssClassName(id)
  8. pictogramCssClasses
  9. How the sprite works
  10. Related packages
  11. Links

@ghs-hazard-pictograms/css

CSS sprite utilities for all GHS chemical hazard pictograms (GHS01–GHS09) and UN transport hazard class pictograms. Import a single stylesheet and use short class names to display any pictogram as a background image.

Installation

npm install @ghs-hazard-pictograms/css @ghs-hazard-pictograms/assets
# or
yarn add @ghs-hazard-pictograms/css @ghs-hazard-pictograms/assets
# or
pnpm add @ghs-hazard-pictograms/css @ghs-hazard-pictograms/assets

Note: @ghs-hazard-pictograms/assets must be installed alongside this package because the CSS file references image files from it.

Quick start

1. Import the stylesheet once in your application entry point:

import '@ghs-hazard-pictograms/css/sprite.css';

Or link it in HTML:

<link rel="stylesheet" href="node_modules/@ghs-hazard-pictograms/css/sprite.css" />

2. Apply a class to any block-level element sized with width and height:

<div class="ghs-ghs01" style="width: 64px; height: 64px;" role="img" aria-label="Explosive"></div>
<div className="ghs-ghs01" style={{ width: 64, height: 64 }} role="img" aria-label="Explosive" />

CSS class reference

GHS chemical hazard pictograms

ClassPictogram
.ghs-ghs01GHS01 Explosive
.ghs-ghs02GHS02 Flammable
.ghs-ghs03GHS03 Oxidizing
.ghs-ghs04GHS04 Compressed Gas
.ghs-ghs05GHS05 Corrosive
.ghs-ghs06GHS06 Toxic
.ghs-ghs07GHS07 Health Hazard / Hazardous to the Atmospheric System
.ghs-ghs08GHS08 Serious Health Hazard
.ghs-ghs09GHS09 Hazardous to the Environment

UN transport hazard class pictograms

ClassPictogram
.ghs-adr-1Divisions 1.1, 1.2, 1.3 — Explosives
.ghs-adr-1-4Division 1.4 — Explosives
.ghs-adr-1-5Division 1.5 — Explosives
.ghs-adr-1-6Division 1.6 — Explosives
.ghs-adr-2-1Division 2.1 — Flammable Gas
.ghs-adr-2-2Division 2.2 — Non-Flammable Gas
.ghs-adr-2-3Division 2.3 — Toxic Gas
.ghs-adr-3Class 3 — Flammable Liquid
.ghs-adr-5-1Division 5.1 — Oxidizing Substances
.ghs-adr-5-2Division 5.2 — Organic Peroxides
.ghs-adr-6-1Division 6.1 — Toxic Substances
.ghs-adr-8Class 8 — Corrosive Substances
.ghs-un-6-2Class 6.2 — Infectious Substances
.ghs-un-7Class 7 — Radioactive Material
.ghs-un-8Class 8 (UN) — Corrosive
.ghs-un-9Class 9 — Miscellaneous Dangerous Goods

JavaScript / TypeScript API

In addition to the CSS file, this package exports helpers for looking up class names programmatically.

getCssClassName(id)

import { getCssClassName } from '@ghs-hazard-pictograms/css';

const cls = getCssClassName('ghs01-explosive');
// → 'ghs-ghs01'

Returns the CSS class name for a pictogram slug ID, or undefined if not found.

pictogramCssClasses

import { pictogramCssClasses } from '@ghs-hazard-pictograms/css';

// { 'ghs01-explosive': 'ghs-ghs01', 'ghs02-flammable': 'ghs-ghs02', ... }

A read-only map of pictogram slug ID → CSS class name for all 27 pictograms.

How the sprite works

Each CSS class sets background-image to the corresponding SVG from @ghs-hazard-pictograms/assets, along with:

background-position: center;
background-repeat: no-repeat;
background-size: contain;

The element itself must have an explicit width and height — the stylesheet does not set dimensions so you stay in control of sizing.

PackageDescription
@ghs-hazard-pictograms/coreRaw data, inline SVGs, and lookup helpers (framework-agnostic)
@ghs-hazard-pictograms/reactReady-to-use React components for each pictogram
@ghs-hazard-pictograms/assetsStatic SVG/PNG/JPG/WebP image files (required peer)
@ghs-hazard-pictograms/spriteSVG <symbol> sprite for <use href> embedding

版本与发布记录

@ghs-hazard-pictograms/css 共发布 10 个版本,首次发布于 2026/04/14;过去 12 个月发布了 10 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.0latest2026/11/16今天
1.0.92026/10/161 个月前
1.0.82026/09/191 个月前
1.0.72026/05/156 个月前
1.0.62026/05/086 个月前
1.0.52026/05/086 个月前

关于 @ghs-hazard-pictograms/css 的常见问题

@ghs-hazard-pictograms/css 是什么?

CSS background-image sprite for GHS hazard and ADR/UN transport pictograms — class-based display, no JavaScript required

如何安装 @ghs-hazard-pictograms/css?

在项目目录运行 npm install @ghs-hazard-pictograms/css,或使用 pnpm add / yarn add / bun add。

@ghs-hazard-pictograms/css 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ghs-hazard-pictograms/css 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ghs-hazard-pictograms/css 可以商用吗?

@ghs-hazard-pictograms/css 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ghs-hazard-pictograms/css 的下载量有多少?

根据 npm 官方下载统计,@ghs-hazard-pictograms/css 在 2026/10/17 – 2026/11/15 这 30 天内被下载 4,794 次,日均约 160 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ghs-hazard-pictograms/css 还在维护吗?

最新版本 1.1.0 发布于 2026/11/16(今天);至今共发布 10 个版本,其中过去 12 个月发布了 10 个;首次发布于 2026/04/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。