A lightweight React component that programmatically generates and plays an HTML <video> element with a clean, reusable API. This library does not rely on CSS-in-JS, with styles are intentionally kept minimal. Created with Typescript support.
npm install react-create-html-video- Built for modern React with support for Typescript
- A lightweight API surface that is easy to understand
- Helps render a native HTML
<video>element on the browser - Provides support for MP4 and Webm based Video displays
- No manual CSS import is required — styles are bundled with the package.
export type TReactCreateHTMLVideo = {
mp4: string;
webm: string;
};"peerDependencies": {
"react": ">=17",
"react-dom": ">=17"
}- Detects browser support using
HTMLVideoElement.canPlayType - Prefers MP4 if supported
- Falls back to WebM if MP4 is unavailable
- Disables video rendering on Internet Explorer
- Returns
nullwhen no supported format is available
/* node modules */
import { ReactCreateHTMLVideo } from "react-create-html-video";
/* module */
function UIComponent() {
return (
{/* make sure your parent container is positioned: relative, imagine here min-height of 100vh */}
<div className="heroSection positionRelative">
<ReactCreateHTMLVideo
mp4="/path/to/mp4/video.mp4"
webm="/path/to/webm/video.webm"
/>
</div>
)
}
/* exports */
export default UIComponent;Contributions, suggestions, and improvements are welcome.
Feel free to open issues or pull requests.
Like this project? Support it with a github star, it would mean a lot to me! Cheers and Happy Coding.
