html-to-react-components splits HTML at data-component attributes, and you annotate the markup by hand
Converts HTML pages into React components
At a glance
- What is it?
- html-to-react-components is a Node.js tool that cuts an HTML file into React component modules wherever an element carries a data-component attribute. This article covers the annotation syntax, the CLI and API options, the TypeScript default, the browser build flag and what the tool leaves undone.
- Who is it for?
- Use html-to-react-components when a designer hands you a large static HTML page and you want its structure turned into component files without retyping markup, and you accept annotating the HTML first. Skip it if you need a conversion that decides component boundaries for you, or a project with recent activity: the last push was on 14 April 2026 and the repository has no releases.
- Can I use it commercially?
- Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Activity is slowing. The repository last received commits 7 months ago.
- What is it written in?
- Mainly JavaScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 25, 2026, and from our analysis. They are not legal advice.
Star history
- roman01la/html-to-react-components2,177 ★ · +1
| Repository | 2026-10-08 | 2026-11-25 |
|---|---|---|
| roman01la/html-to-react-components | 2.2k | 2.2k |
1 Stars in the last 48 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
Only elements with a data-component attribute become modules
The tool does not guess where a component starts. You mark each element that should become a component with a data-component attribute, and the attribute value becomes the component name. The tool extracts those annotated portions into separate modules. Where one component contains another, the parent imports the child and the child's markup is replaced in the parent by a reference, so the original HTML structure survives as a tree of imports and the result is a full component tree ready to render.
The Node.js example in the README shows the nesting: a header marked as Header contains a heading marked Heading and a nav marked Nav, and the nav contains list items marked ListItem. Two list items share the name ListItem, so the same component is produced once and used twice.
The project's stated purpose is to free React developers from the task of translating HTML into components. It pictures a pile of HTML from designers, where the first job is breaking it into components, a job the author finds boring and wants automated. That automation starts after a person has decided the boundaries. The decision is yours, and it takes the form of editing attributes into the source markup.
Props come from a public: prefix and arrive as a typed interface by default
To expose an HTML attribute as a React prop, prefix it with public:. The README's one-line example is:
<input public:type="text" id="input" data-component="Input" />The generated module declares an interface and a functional component, and the place of use passes the prop:
// at usage place
<Input type="text" />;
// in component's module
interface InputProps {
type: string;
}
const Input = ({ type }: InputProps) => <input type={type} id="input" />;Output is TypeScript by default. Components that have public: props get typed interfaces and annotated parameters. The interface in the example types the prop as string, and the id attribute stays fixed inside the component, because only attributes with the prefix become props.
The README shows string props only. It does not describe how a number, a boolean or a function prop would be written in the HTML, since an HTML attribute is a string to begin with. If you need richer types, you edit the generated file afterwards. The README points to test.js in the repository for a usage example and output.
The CLI takes a glob in double quotes and writes into a components folder
After a global install, which requires Node.js 18 or later, the command is html2react followed by a glob pattern:
$ npm i -g html-to-react-components$ html2react "./src/*.html"A recursive pattern generates the corresponding files for a whole tree:
$ html2react "./src/**/*.html"The README insists on double quotes around the pattern. Without them your shell expands the glob before the tool sees it, and the two-star recursion is not what the tool receives. The bin entry in package.json maps html2react to lib/cli.js, and the CLI is built on meow, with glob 9 handling the patterns.
Output goes to a components directory in the current folder unless you pass an output path. The extension defaults to tsx, or js when TypeScript is turned off. One consequence is that a run from a different directory writes to a different components folder, so run it from the project root or set the output path explicitly.
Five options change component style, module format, language and file naming
componentType, also --component or -c, chooses between functional (the default), class and es5. The es5 value means components built without class or arrow syntax, though the README does not show an example of that output.
moduleType, or --module and -m, picks es for EcmaScript modules, the default, or cjs for CommonJS. The typescript option, --typescript or -t, defaults to true. To get plain JavaScript pass --no-typescript, and the file extension then falls back to js.
moduleFileNameDelimiter, set with --delimiter or -d, controls file names. With no delimiter, or with -d and no value, the component name in the HTML is used unchanged as the filename. If you give a delimiter character, the name is broken into words, joined with the delimiter and lower-cased, so a component named ListItem would become a lower-case, delimited name. The README does not show an example.
Output options are path, set with --out or -o, and fileExtension, set with --ext or -e. The Node.js API takes the same settings as an object, with output holding path and fileExtension. The options object in the README comments each value, and it leaves out moduleFileNameDelimiter, so check lib/ for that one in API form.
The Node.js API is async and returns a Promise of components
The API is a single function, imported with require("html-to-react-components") and called as await extractReactComponents(html, options). It returns a Promise. The README's sample passes a complete HTML document string and awaits the result, which holds the extracted components.
The example input is a full page with a doctype, head and body, and the annotated elements live inside the body. The README does not state what the resolved value looks like, such as an array or an object keyed by name, and it does not say whether the function also writes files when output is set. The options include an output block with a path and extension, which suggests file writing, but the text never says so. Run the function once on a small page and log the result before building anything on its shape.
To switch off types, pass typescript: false, and set output.fileExtension to js so the extension matches. The README shows this as a separate snippet, with componentType set to functional.
The browser bundle needs IN_BROWSER at compile time and drops code formatting
package.json points the browser field at dist/html2react.js and defines a build:browser script that runs webpack with webpack.browser.js. For in-browser use, an environment variable IN_BROWSER must be defined at compile time so that Node.js-specific modules are disabled. The README shows the Webpack way, with a DefinePlugin entry setting IN_BROWSER to the JSON-stringified value true.
One trade-off is spelled out: code formatting is not included in the in-browser bundle. The Node.js version formats output with prettier, listed in the dependencies, and the browser version does not, so generated code from the online REPL may look different from CLI output. The project's online REPL at roman01la.github.io/html-to-react-components/repl is the browser build in use.
The parsing stack is also visible in package.json: posthtml with its parser and renderer for HTML, and the Babel parser, traverse, types and generator for the JavaScript side. jsdom and chalk are also dependencies. The build tooling is old: webpack 4.29 and babel-loader 8 sit in devDependencies, and the test script runs jest 29, so rebuilding the browser bundle uses an older toolchain than the runtime Node 18 requirement suggests.
Annotating in an editor is awkward, and the last push was in April 2026
The README admits a workflow problem. Annotating HTML in an editor is not the best experience because you cannot see the rendered UI. It is possible to annotate through browser DevTools, but you then have to copy and paste markup from DevTools into the files that will be processed. A related extension, extract-to-react by jesstelford, is built on this library for Chrome and Chromium and extracts HTML and CSS into React components, which you can load in CodePen or JSFiddle.
CSS is not part of this tool's description. It converts markup into components and says nothing about moving class names or stylesheets, so styling stays your job unless you use the extension.
On status, the repository has no GitHub releases, package.json declares version 3.0.0, and a CHANGELOG.md is present. The last push was on 14 April 2026, more than six months back, and the repository is not archived. The README badges still point to Travis CI, which is the project's own CI link. The contribution policy is brief: send a pull request for a bug fix, and open an issue before adding a feature or changing behavior.
Editorial conclusion
Use html-to-react-components when a designer hands you a large static HTML page and you want its structure turned into component files without retyping markup, and you accept annotating the HTML first. Skip it if you need a conversion that decides component boundaries for you, or a project with recent activity: the last push was on 14 April 2026 and the repository has no releases. Before adopting, run the page through the online REPL and read the generated files for the attribute and prop handling you depend on.
Frequently asked questions
How do I install html-to-react-components?
Run npm i -g html-to-react-components. It requires Node.js 18 or later, and installs the html2react command.
How does html-to-react-components know what to turn into a component?
Any HTML element with a data-component attribute becomes a separate React component named by the attribute's value. Attributes prefixed with public: become React props.
Does html-to-react-components produce TypeScript?
Yes, by default. Components with public: props get typed interfaces, and the extension is tsx. Pass --no-typescript for plain JavaScript.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/roman01la-html-to-react-components)Star history chart for your README
[](https://hysenlabs.com/projects/roman01la-html-to-react-components)Was this useful?