{"id":13998447,"url":"https://github.com/ibrahimcesar/react-lite-youtube-embed","last_synced_at":"2025-05-14T21:06:44.564Z","repository":{"id":36464727,"uuid":"225513118","full_name":"ibrahimcesar/react-lite-youtube-embed","owner":"ibrahimcesar","description":"📺 ‏‏‎ ‎‏‏‎ ‎‏‏‎ ‎\u003c A private by default, faster and cleaner YouTube embed component for React applications /\u003e","archived":false,"fork":false,"pushed_at":"2025-04-20T21:40:57.000Z","size":3693,"stargazers_count":277,"open_issues_count":33,"forks_count":43,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-20T22:27:50.841Z","etag":null,"topics":["a11y","adaptive-loading","iframe","iframe-embeds","privacy","react","reactjs","reactjs-components","responsive","youtube"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-lite-youtube-embed","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ibrahimcesar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":["ibrahimcesar"]}},"created_at":"2019-12-03T02:30:29.000Z","updated_at":"2025-04-20T21:41:01.000Z","dependencies_parsed_at":"2023-01-17T01:45:23.456Z","dependency_job_id":"7f49668a-9013-47ed-9680-79c87ff12863","html_url":"https://github.com/ibrahimcesar/react-lite-youtube-embed","commit_stats":{"total_commits":180,"total_committers":26,"mean_commits":6.923076923076923,"dds":0.4722222222222222,"last_synced_commit":"3f423637c333da1fa69fa94adc2bf22ced6e4efd"},"previous_names":[],"tags_count":42,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimcesar%2Freact-lite-youtube-embed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimcesar%2Freact-lite-youtube-embed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimcesar%2Freact-lite-youtube-embed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ibrahimcesar%2Freact-lite-youtube-embed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ibrahimcesar","download_url":"https://codeload.github.com/ibrahimcesar/react-lite-youtube-embed/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254227612,"owners_count":22035669,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["a11y","adaptive-loading","iframe","iframe-embeds","privacy","react","reactjs","reactjs-components","responsive","youtube"],"created_at":"2024-08-09T19:01:40.768Z","updated_at":"2025-05-14T21:06:39.548Z","avatar_url":"https://github.com/ibrahimcesar.png","language":"TypeScript","funding_links":["https://github.com/sponsors/ibrahimcesar"],"categories":["TypeScript"],"sub_categories":[],"readme":" \u003cdiv align=\"center\"\u003e\n\n  \u003ch1\u003e📺  React Lite YouTube Embed\u003c/h1\u003e\n  \u003cblockquote\u003eA private by default, faster and cleaner YouTube embed component for React applications\u003c/blockquote\u003e\n\n[![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101)](https://www.typescriptlang.org/)\n\n[![Version](https://img.shields.io/npm/v/react-lite-youtube-embed?label=latest%20version)](https://www.npmjs.com/package/react-lite-youtube-embed)\u0026nbsp; \u0026nbsp;\u0026nbsp; \u0026nbsp;![Total Downloads](https://img.shields.io/npm/dt/react-lite-youtube-embed?color=%23FF0000\u0026logo=npm)\u0026nbsp; \u0026nbsp;\u0026nbsp; \u0026nbsp;[![License](https://badgen.net/github/license/ibrahimcesar/react-lite-youtube-embed)](./LICENSE)\u0026nbsp; \u0026nbsp;  \u0026nbsp;![GitHub issues by-label](https://img.shields.io/github/issues/ibrahimcesar/react-lite-youtube-embed/bug)\n\n\n\u003cp\u003eDeveloped in 🇧🇷 \u003cspan role=\"img\" aria-label=\"Flag for Brazil\"\u003eBrazil\u003c/p\u003e\n\n\u003cstrong\u003ePort of Paul Irish's [Lite YouTube Embed](https://github.com/paulirish/lite-youtube-embed) to a React Component. Provide videos with a supercharged focus on visual performance. The gain is not the same as the web component of the original implementation but saves some requests and gives you more control of the embed visual. An [\"Adaptive Loading\"](https://www.youtube.com/watch?v=puUPpVrIRkc) way to handle iframes for YouTube.\u003c/strong\u003e\n\n[![iFrame example](_example_lite.gif)](https://main.d1vubvlhfep0xm.amplifyapp.com/)\n\n## [View Demo](https://main.d1vubvlhfep0xm.amplifyapp.com/)\n\n\u003c/div\u003e\n\n## 🔒 Up 2.0.0 Privacy by Default\n\nThe biggest change is, from 2.0.0 this component is private by default. Meaning that will not preconnect with the ad network from Google and connect to YouTube via the Privacy-Enhanced Mode using https://www.youtube-nocookie.com.\n\n## 🚀 Install\n\nUse your favorite package manager:\n\n```bash\nyarn add react-lite-youtube-embed\n```\n\n```bash\nnpm install react-lite-youtube-embed -S\n```\n## 🕹️ Basic Usage\n\n```javascript\nimport React from \"react\";\nimport { render } from \"react-dom\";\nimport LiteYouTubeEmbed from 'react-lite-youtube-embed';\nimport 'react-lite-youtube-embed/dist/LiteYouTubeEmbed.css'\n\nconst App = () =\u003e (\n  \u003cdiv\u003e\n    \u003cLiteYouTubeEmbed\n        id=\"L2vS_050c-M\"\n        title=\"What’s new in Material Design for the web (Chrome Dev Summit 2019)\"\n    /\u003e\n  \u003c/div\u003e\n);\n\nrender(\u003cApp /\u003e, document.getElementById(\"root\"));\n```\n\nAnd that's it.\n\n## 💎 Pro Usage\n\n```javascript\nconst App = () =\u003e (\n  \u003cdiv\u003e\n    \u003cLiteYouTubeEmbed\n       id=\"L2vS_050c-M\" // Default none, id of the video or playlist\n       adNetwork={true} // Default true, to preconnect or not to doubleclick addresses called by YouTube iframe (the adnetwork from Google)\n       params=\"\" // any params you want to pass to the URL, assume we already had '\u0026' and pass your parameters string\n       playlist={false} // Use true when your ID be from a playlist\n       playlistCoverId=\"L2vS_050c-M\" // The ids for playlists did not bring the cover in a pattern to render so you'll need pick up a video from the playlist (or in fact, whatever id) and use to render the cover. There's a programmatic way to get the cover from YouTube API v3 but the aim of this component is do not make any another call and reduce requests and bandwidth usage as much as possibe\n       poster=\"hqdefault\" // Defines the image size to call on first render as poster image. Possible values are \"default\",\"mqdefault\",  \"hqdefault\", \"sddefault\" and \"maxresdefault\". Default value for this prop is \"hqdefault\". Please be aware that \"sddefault\" and \"maxresdefault\", high resolution images are not always avaialble for every video. See: https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api\n       title=\"YouTube Embed\" // a11y, always provide a title for iFrames: https://dequeuniversity.com/tips/provide-iframe-titles Help the web be accessible ;)\n       noCookie={true} // Default false, connect to YouTube via the Privacy-Enhanced Mode using https://www.youtube-nocookie.com\n       ref={myRef} // Use this ref prop to programmatically access the underlying iframe element\n    /\u003e\n  \u003c/div\u003e\n);\n```\n\n## 🧰 Bring Your Own Styles\n\nReact Lite YouTube Embed comes with all original styles from Paul Irish's [Lite YouTube Embed](https://github.com/paulirish/lite-youtube-embed) but you can customize them as you wish passing as a props.\n\n```javascript\nconst App = () =\u003e (\n  \u003cdiv\u003e\n    \u003cLiteYouTubeEmbed\n       id=\"L2vS_050c-M\"\n       activeClass=\"lyt-activated\" // Default as \"lyt-activated\", gives control to wrapper once clicked\n       iframeClass=\"\" // Default none, gives control to add a class to iframe element itself\n       playerClass=\"lty-playbtn\" // Default as \"lty-playbtn\" to control player button styles\n       wrapperClass=\"yt-lite\" // Default as \"yt-lite\" for the div wrapping the area, the most important class and needs extra attention, please refer to LiteYouTubeEmbed.css for a reference.\n    /\u003e\n  \u003c/div\u003e\n);\n```\n\n## ⚠️ After version 1.0.0 - BREAKING CHANGES ⚠️\n\nTo play nice with new frameworks like [NextJS](https://nextjs.org/), we now don't import the `.css` necessary. Since version `2.0.9` you can pass custom aspect-ratio props, so be aware of any changes needed in the CSS options. Instead use now you have three options:\n\n### Option 1\n\nPlace the necessary CSS in your Global CSS file method of preference\n\n\u003cdetails\u003e\n\n\u003csummary\u003e Show me the code!\u003c/summary\u003e\n\n```css\n.yt-lite {\n    background-color: #000;\n    position: relative;\n    display: block;\n    contain: content;\n    background-position: center center;\n    background-size: cover;\n    cursor: pointer;\n}\n\n/* gradient */\n.yt-lite::before {\n    content: '';\n    display: block;\n    position: absolute;\n    top: 0;\n    background-position: top;\n    background-repeat: repeat-x;\n    height: 60px;\n    padding-bottom: 50px;\n    width: 100%;\n    transition: all 0.2s cubic-bezier(0, 0, 0.2, 1);\n}\n\n/* responsive iframe with a 16:9 aspect ratio\n    thanks https://css-tricks.com/responsive-iframes/\n*/\n.yt-lite::after {\n    content: \"\";\n    display: block;\n    padding-bottom: calc(100% / (16 / 9));\n}\n.yt-lite \u003e iframe {\n    width: 100%;\n    height: 100%;\n    position: absolute;\n    top: 0;\n    left: 0;\n}\n\n/* play button */\n.yt-lite \u003e .lty-playbtn {\n    width: 65px;\n    height: 46px;\n    z-index: 1;\n    opacity: 0.8;\n    border: none;\n    background: url(\"data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20xmlns%3Axlink%3D%22http%3A%2F%2Fwww.w3.org%2F1999%2Fxlink%22%20version%3D%221.1%22%20id%3D%22YouTube_Icon%22%20x%3D%220px%22%20y%3D%220px%22%20viewBox%3D%220%200%201024%20721%22%20enable-background%3D%22new%200%200%201024%20721%22%20xml%3Aspace%3D%22preserve%22%3E%3Cscript%20xmlns%3D%22%22%3E%0A%20%20%20%20try%20%7B%0A%20%20%20%20%20%20Object.defineProperty(navigator%2C%20%22globalPrivacyControl%22%2C%20%7B%0A%20%20%20%20%20%20%20%20value%3A%20false%2C%0A%20%20%20%20%20%20%20%20configurable%3A%20false%2C%0A%20%20%20%20%20%20%20%20writable%3A%20false%0A%20%20%20%20%20%20%7D)%3B%0A%20%20%20%20%20%20document.currentScript.parentElement.removeChild(document.currentScript)%3B%0A%20%20%20%20%7D%20catch(e)%20%7B%7D%3B%0A%20%20%20%20%20%20%3C%2Fscript%3E%0A%3Cpath%20id%3D%22Triangle%22%20fill%3D%22%23FFFFFF%22%20d%3D%22M407%2C493l276-143L407%2C206V493z%22%2F%3E%0A%3Cpath%20id%3D%22The_Sharpness%22%20opacity%3D%220.12%22%20fill%3D%22%23420000%22%20d%3D%22M407%2C206l242%2C161.6l34-17.6L407%2C206z%22%2F%3E%0A%3Cg%20id%3D%22Lozenge%22%3E%0A%09%3Cg%3E%0A%09%09%0A%09%09%09%3ClinearGradient%20id%3D%22SVGID_1_%22%20gradientUnits%3D%22userSpaceOnUse%22%20x1%3D%22512.5%22%20y1%3D%22719.7%22%20x2%3D%22512.5%22%20y2%3D%221.2%22%20gradientTransform%3D%22matrix(1%200%200%20-1%200%20721)%22%3E%0A%09%09%09%3Cstop%20offset%3D%220%22%20style%3D%22stop-color%3A%23E52D27%22%2F%3E%0A%09%09%09%3Cstop%20offset%3D%221%22%20style%3D%22stop-color%3A%23BF171D%22%2F%3E%0A%09%09%3C%2FlinearGradient%3E%0A%09%09%3Cpath%20fill%3D%22url(%23SVGID_1_)%22%20d%3D%22M1013%2C156.3c0%2C0-10-70.4-40.6-101.4C933.6%2C14.2%2C890%2C14%2C870.1%2C11.6C727.1%2C1.3%2C512.7%2C1.3%2C512.7%2C1.3%20%20%20%20h-0.4c0%2C0-214.4%2C0-357.4%2C10.3C135%2C14%2C91.4%2C14.2%2C52.6%2C54.9C22%2C85.9%2C12%2C156.3%2C12%2C156.3S1.8%2C238.9%2C1.8%2C321.6v77.5%20%20%20%20C1.8%2C481.8%2C12%2C564.4%2C12%2C564.4s10%2C70.4%2C40.6%2C101.4c38.9%2C40.7%2C89.9%2C39.4%2C112.6%2C43.7c81.7%2C7.8%2C347.3%2C10.3%2C347.3%2C10.3%20%20%20%20s214.6-0.3%2C357.6-10.7c20-2.4%2C63.5-2.6%2C102.3-43.3c30.6-31%2C40.6-101.4%2C40.6-101.4s10.2-82.7%2C10.2-165.3v-77.5%20%20%20%20C1023.2%2C238.9%2C1013%2C156.3%2C1013%2C156.3z%20M407%2C493V206l276%2C144L407%2C493z%22%2F%3E%0A%09%3C%2Fg%3E%0A%3C%2Fg%3E%0A%3C%2Fsvg%3E\");\n    transition: all 0.2s cubic-bezier(0, 0, 0.2, 1);\n}\n.yt-lite:hover \u003e .lty-playbtn {\n    opacity: 1;\n}\n/* play button triangle */\n.yt-lite \u003e .lty-playbtn:before {\n    content: '';\n    border-style: solid;\n    border-width: 11px 0 11px 19px;\n    border-color: transparent transparent transparent #fff;\n}\n\n.yt-lite \u003e .lty-playbtn,\n.yt-lite \u003e .lty-playbtn:before {\n    position: absolute;\n    top: 50%;\n    left: 50%;\n    transform: translate3d(-50%, -50%, 0);\n}\n\n/* Post-click styles */\n.yt-lite.lyt-activated {\n    cursor: unset;\n}\n.yt-lite.lyt-activated::before,\n.yt-lite.lyt-activated \u003e .lty-playbtn {\n    opacity: 0;\n    pointer-events: none;\n}\n```\n\nFor example, for NextJS:\n\n```jsx\n\u003cstyle jsx global\u003e{`\n        html,\n        body {\n          padding: 0;\n          margin: 0;\n          font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,\n            Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue,\n            sans-serif;\n        }\n\n        * {\n          box-sizing: border-box;\n\n        // CSS above\n\n`}\u003c/style\u003e\n\n```\n\n\u003c/details\u003e\n\n### Option 2\n\nUsing your CSS-In-JS tool of choice encapsulate this component and use the css provided as a guide.\n\n### Option 3\n\nNot work on every framework but you can import the css directly, check what works best with your bundler / framework.\n\n\u003cdetails\u003e\n\u003csummary\u003eShow me the code!\u003c/summary\u003e\n\n```ts\nimport 'react-lite-youtube-embed/dist/LiteYouTubeEmbed.css';\n```\n\nor in a *.css/scss etc:\n\n```css\n@import \"~react-lite-youtube-embed/dist/LiteYouTubeEmbed.css\";\n```\n\n\u003c/details\u003e\n\n## All our props belongs to you\n\nThe most minimalist implementation requires two props: `id` from the YouTube you want to render and `title`, for the iFrame.\n\n| Prop   |      Type      |  Description |\n|----------|:--------:|------------|\n| **id** |  string | id of the video or playlist |\n| **title** |    string   | Here goes your video title. Always provide a title for iFrames: [https://dequeuniversity.com/tips/provide-iframe-titles](https://dequeuniversity.com/tips/provide-iframe-titles) Help the web be accessible ;) #a11y |\n| activeClass | string | Pass the string class for the active state |\n| adNetwork | boolean | Default: `false`  To preconnect or not to doubleclick addresses called by YouTube iframe (the adnetwork from Google) |\n| announce |    string   | Default: `Watch`. This will added to the button announce to the final user as in `Clickable Watch, ${title}, button` , customize to match your own language #a11y #i18n |\n| aspectHeight |    number   | Default: `9`. Use this optional prop if you want a custom aspect-ratio. Please be aware of aspect height and width relation and also any custom CSS you are using. |\n| aspectWidth |    number   | Default: `16`. Use this optional prop if you want a custom aspect-ratio. Please be aware of aspect height and width relation and also any custom CSS you are using. |\n| cookie | boolean |    Default: `false` Connect to YouTube via the Privacy-Enhanced Mode using [https://www.youtube-nocookie.com](https://www.youtube-nocookie.com). You should opt-in to allow cookies|\n| iframeClass | string |    Pass the string class for the own iFrame |\n| muted | boolean | If the video has sound or not. Required autoplay `true` to work |\n| noCookie | boolean |    `Deprecated` Default `false` _use option **cookie** to opt-in_|\n| onIframeAdded | function | Callback that will fired when iframe loads |\n| params | string |    any params you want to pass to the URL in the iFrame. Two important points to notice: You need to add the params, we already setup for you, so you should write `start=1150` and not `?start=1150` or `\u0026start=1150`. You can place more params but it will need to fully form: `start=1150\u0026other=value\u0026another=value`. First, when you share a YouTube url the param of time is `t`, but the embed needs `start`.|\n| playerClass | string | Pass the string class for the player, once you can customize it |\n| playlist | boolean |    Use `true` when your id be from a playlist |\n| playlistCoverId | string | The ids for playlists did not bring the cover in a pattern to render so you'll need pick up a video from the playlist (or in fact, whatever id) and use to render the cover. There's a programmatic way to get the cover from YouTube API v3 but the aim of this component is do not make any another call and reduce requests and bandwidth usage as much as possible  |\n| poster | string. One of `default` `mqdefault`  `hqdefault` `sddefault` `maxresdefault` |   Defines the image size to call on first render as poster image. See: [https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api](https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api) |\n| rel | string |   Default `preload`. allows for prefetch or preload of the link url |\n| thumbnail | string |   Pass an optional image url to override the default poster and set a custom poster image |\n| webp | boolean |   Default `false`. When set, uses the WebP format for poster images |\n| wrapperClass | string |   Pass the string class that wraps the iFrame |\n| containerElement | string | Default `article`. Pass the element to be used for the container. |\n| style | object | Pass the style object to be used for the container, overriding any root styles. |\n\n## 🙇‍♂️ Thanks\n\n- Paul Irish ([paulirish](https://github.com/paulirish)) for [Lite YouTube Embed](https://github.com/paulirish/lite-youtube-embed)\n- Addy Osmani ([addyosmani](https://github.com/addyosmani)) for the Adaptive Loading ideas\n- [All contributors](https://github.com/ibrahimcesar/react-lite-youtube-embed/graphs/contributors)\n\n### 📝 Read more\n\n- [Why I made my open source React component private by default](https://ibrahimcesar.cloud/blog/why-i-made-my-open-source-react-component-private-by-default/)\n\n### 🈺 TODO\n\n- [ ] Add tests\n\n## MIT License\n\nCopyright (c) 2021 — 2023 [Ibrahim Cesar](https://ibrahimcesar.cloud)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibrahimcesar%2Freact-lite-youtube-embed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fibrahimcesar%2Freact-lite-youtube-embed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fibrahimcesar%2Freact-lite-youtube-embed/lists"}