{"componentChunkName":"component---src-gatsby-theme-try-ghost-templates-post-js","path":"/best-websites-to-find-free-resources-for-frontend-web-developers-and-designers/","result":{"data":{"customPost":{"id":"Ghost__Post__6127ba1b3ed159214d382e6d","title":"Best Websites to Find Free Resources for Frontend Web Developers and Designers","slug":"best-websites-to-find-free-resources-for-frontend-web-developers-and-designers","featured":false,"feature_image":"https://res-2.cloudinary.com/hbqmf3mbz/image/upload/q_auto/v1/ghost-blog-images/photo-1505304451-3b3b85a91afe.jpg","excerpt":"Perhaps one of the hardest tasks is finding free resources for your projects. This list will hold websites that offer freebies.","custom_excerpt":"Perhaps one of the hardest tasks is finding free resources for your projects. This list will hold websites that offer freebies.","visibility":"public","created_at_pretty":"26 Oct 2020","published_at_pretty":"26 Aug 2019","updated_at_pretty":"26 Aug 2021","created_at":"2020-10-26T21:33:46.000+00:00","published_at":"2019-08-26T21:33:00.000+00:00","updated_at":"2021-08-26T17:54:20.000+00:00","meta_title":null,"meta_description":null,"og_description":null,"og_image":null,"og_title":null,"twitter_description":null,"twitter_image":null,"twitter_title":null,"authors":[{"slug":"shahed","url":"https://backend.shahednasser.com/author/shahed/","name":"Shahed Nasser","bio":null,"cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/03/IMG_0591.jpg","location":null,"website":null,"twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":null}],"primary_author":{"slug":"shahed","url":"https://backend.shahednasser.com/author/shahed/","name":"Shahed Nasser","bio":null,"cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/03/IMG_0591.jpg","location":null,"website":null,"twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":{"base":"IMG_0591.jpg","publicURL":"/static/ceb49c3c631485453e71e00d7f84b069/IMG_0591.jpg","imageMeta":{"width":1182,"height":1179},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAUABQDASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAMEAQL/xAAWAQEBAQAAAAAAAAAAAAAAAAADBAL/2gAMAwEAAhADEAAAAdXiFM6i0CohUWXoKn//xAAcEAACAgIDAAAAAAAAAAAAAAACAwESBBEhM0H/2gAIAQEAAQUCWySE3WEr7SzbXjAj4iKty+sOQ//EABYRAQEBAAAAAAAAAAAAAAAAAAERIP/aAAgBAwEBPwEhj//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8BH//EAB4QAAIBBAMBAAAAAAAAAAAAAAABIRESMUECECJx/9oACAEBAAY/ApVGWvOjzgtUwLlTZA0sdL4f/8QAHBAAAwACAwEAAAAAAAAAAAAAAAERITFBkbHB/9oACAEBAAE/IahkCy+N2GwZpjQiJHJCspUFY0QrSi+HqiW2rgf/2gAMAwEAAgADAAAAEPw3/wD/xAAYEQEBAAMAAAAAAAAAAAAAAAAAARExQf/aAAgBAwEBPxCtjDqP/8QAFxEBAQEBAAAAAAAAAAAAAAAAAQAxEf/aAAgBAgEBPxBFus6Tt//EAB8QAQEAAgIBBQAAAAAAAAAAAAERACExQWFRcYGR0f/aAAgBAQABPxAuaBPPzkO1wyX7F4wkwXanfZrFQgeqE9JgS14vVOvrERIJomVBKwt2jebAeP0yVa8h1n//2Q==","aspectRatio":1,"src":"/static/ceb49c3c631485453e71e00d7f84b069/31709/IMG_0591.jpg","srcSet":"/static/ceb49c3c631485453e71e00d7f84b069/f340b/IMG_0591.jpg 28w,\n/static/ceb49c3c631485453e71e00d7f84b069/22d64/IMG_0591.jpg 55w,\n/static/ceb49c3c631485453e71e00d7f84b069/31709/IMG_0591.jpg 110w,\n/static/ceb49c3c631485453e71e00d7f84b069/aa249/IMG_0591.jpg 165w,\n/static/ceb49c3c631485453e71e00d7f84b069/0dc33/IMG_0591.jpg 220w,\n/static/ceb49c3c631485453e71e00d7f84b069/d8257/IMG_0591.jpg 1182w","srcWebp":"/static/ceb49c3c631485453e71e00d7f84b069/8678c/IMG_0591.webp","srcSetWebp":"/static/ceb49c3c631485453e71e00d7f84b069/59cda/IMG_0591.webp 28w,\n/static/ceb49c3c631485453e71e00d7f84b069/7da75/IMG_0591.webp 55w,\n/static/ceb49c3c631485453e71e00d7f84b069/8678c/IMG_0591.webp 110w,\n/static/ceb49c3c631485453e71e00d7f84b069/f282e/IMG_0591.webp 165w,\n/static/ceb49c3c631485453e71e00d7f84b069/a7b21/IMG_0591.webp 220w,\n/static/ceb49c3c631485453e71e00d7f84b069/63099/IMG_0591.webp 1182w","sizes":"(max-width: 110px) 100vw, 110px"}}}},"primary_tag":{"slug":"beginner","url":"https://backend.shahednasser.com/tag/beginner/","name":"Beginners","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1521185496955-15097b20c5fe-2.jpeg","description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","meta_title":"Beginners","meta_description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","featureImageSharp":{"base":"photo-1521185496955-15097b20c5fe-2.jpeg","publicURL":"/static/13f953658eaecb779984996ea356b1c4/photo-1521185496955-15097b20c5fe-2.jpeg","imageMeta":{"width":2000,"height":1547},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAPABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAQCBf/EABYBAQEBAAAAAAAAAAAAAAAAAAIAAf/aAAwDAQACEAMQAAABhU05c9sV/8QAGRAAAwEBAQAAAAAAAAAAAAAAAQIDABIR/9oACAEBAAEFAuTgGxGjVeRdPLOHf//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8BP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8BP//EABkQAAMBAQEAAAAAAAAAAAAAAAABEXECEP/aAAgBAQAGPwL2dJaOqYVH/8QAGhAAAwADAQAAAAAAAAAAAAAAAAERITFBYf/aAAgBAQABPyFpWJH6IutKCacL+lRRGxiDm+H/2gAMAwEAAgADAAAAEK//AP/EABYRAQEBAAAAAAAAAAAAAAAAAAEREP/aAAgBAwEBPxAI3P/EABYRAQEBAAAAAAAAAAAAAAAAAAERAP/aAAgBAgEBPxBaR03/xAAbEAEBAAIDAQAAAAAAAAAAAAABEQAhMUGxcf/aAAgBAQABPxAInmDF9wQ6urfMI5JgA/si0141k9pEa4fcjFJmybz/2Q==","aspectRatio":1.2935323383084578,"src":"/static/13f953658eaecb779984996ea356b1c4/d5c54/photo-1521185496955-15097b20c5fe-2.jpg","srcSet":"/static/13f953658eaecb779984996ea356b1c4/65d8c/photo-1521185496955-15097b20c5fe-2.jpg 260w,\n/static/13f953658eaecb779984996ea356b1c4/c5f21/photo-1521185496955-15097b20c5fe-2.jpg 520w,\n/static/13f953658eaecb779984996ea356b1c4/d5c54/photo-1521185496955-15097b20c5fe-2.jpg 1040w,\n/static/13f953658eaecb779984996ea356b1c4/81a53/photo-1521185496955-15097b20c5fe-2.jpg 1560w,\n/static/13f953658eaecb779984996ea356b1c4/4e5f3/photo-1521185496955-15097b20c5fe-2.jpg 2000w","srcWebp":"/static/13f953658eaecb779984996ea356b1c4/e4875/photo-1521185496955-15097b20c5fe-2.webp","srcSetWebp":"/static/13f953658eaecb779984996ea356b1c4/dc8f3/photo-1521185496955-15097b20c5fe-2.webp 260w,\n/static/13f953658eaecb779984996ea356b1c4/2db4b/photo-1521185496955-15097b20c5fe-2.webp 520w,\n/static/13f953658eaecb779984996ea356b1c4/e4875/photo-1521185496955-15097b20c5fe-2.webp 1040w,\n/static/13f953658eaecb779984996ea356b1c4/f5845/photo-1521185496955-15097b20c5fe-2.webp 1560w,\n/static/13f953658eaecb779984996ea356b1c4/49d6b/photo-1521185496955-15097b20c5fe-2.webp 2000w","sizes":"(max-width: 1040px) 100vw, 1040px"}}}},"tags":[{"slug":"beginner","url":"https://backend.shahednasser.com/tag/beginner/","name":"Beginners","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1521185496955-15097b20c5fe-2.jpeg","description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","meta_title":"Beginners","meta_description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","featureImageSharp":null},{"slug":"tips","url":"https://backend.shahednasser.com/tag/tips/","name":"Tips","visibility":"public","feature_image":null,"description":"Learn more about programming and development through these articles that have essential tips!","meta_title":"Tips on Technology and Programming","meta_description":null,"featureImageSharp":null},{"slug":"open-source","url":"https://backend.shahednasser.com/tag/open-source/","name":"Open Source","visibility":"public","feature_image":null,"description":null,"meta_title":null,"meta_description":null,"featureImageSharp":null},{"slug":"design","url":"https://backend.shahednasser.com/tag/design/","name":"Design","visibility":"public","feature_image":null,"description":"Learn more about Web Design through tutorials, articles and tips.","meta_title":null,"meta_description":null,"featureImageSharp":null}],"plaintext":"Perhaps one of the hardest tasks is finding free resources for your projects.\nThis list will hold websites that offer freebies. I will try to keep the list\nupdated along the way.\n\nSome of the websites may have a different license for each resource they offer,\nso you might need to look out for that.\n\n\n--------------------------------------------------------------------------------\n\nGeneral\n 1. Freebie Supply [https://freebiesupply.com/]: Free icons, vectors, fonts,\n    templates, themes and more.\n 2. Freebiesbug [https://freebiesbug.com/]: Another website that has a wide\n    collection of icons, vectors, templates, and more.\n 3. Neede [https://neede.co/]: It’s aimed more towards designers, but developers\n    might find some useful stuff like templates, colors, illustrations and more.\n\nFonts\n 1. Google Fonts [https://fonts.google.com/]\n 2. 1001 Fonts [https://www.1001fonts.com/]\n\nIcons\n 1. Material Design Icons [https://material.io/resources/icons/]\n 2. Feather [https://feathericons.com/]\n 3. SVG Repo [https://www.svgrepo.com/]\n\nWebsite Templates\n 1. Free CSS [https://www.free-css.com/]: Free CSS templates, layouts, and\n    menus.\n 2. Free Web Templates [https://www.freewebtemplates.com/]\n 3. Free Website Templates [https://freewebsitetemplates.com/]\n 4. One Page HTML templates [https://onepagelove.com/templates/html-templates]\n 5. BootstrapMade [https://bootstrapmade.com/]: Free website templates (requires\n    attribution)\n 6. HTML5 UP! [https://html5up.net/]: Free responsive HTML5 templates (requires\n    attribution)\n 7. TEMPLATD [https://templated.co/]: Free HTML templates (requires attribution)\n\nIllustrations\n 1. unDraw [https://undraw.co/]: Free illustrations for any project you can\n    think of.\n 2. Lukasz Adam’s Free Illustrations [https://lukaszadam.com/illustrations]: \n    Free unique illustrations.\n 3. DrawKit [https://www.drawkit.io/]: Free wide range of illustrations.\n\nImages\n 1. Unsplash [https://unsplash.com/]: Free images with no attribution required.\n 2. Pexels [https://www.pexels.com/]: Free stock images with no attribution\n    required.\n\nGradients and Colors\n 1. WebGradients [https://webgradients.com/]: Free gradients that you can either\n    copy as CSS rules or download them as .sketch or .psd\n 2. uiGradients [https://uigradients.com/#Pinky]: Free gradients that you can\n    either copy as CSS rules or download them as .jpg images.\n 3. Gradient Hunt [https://gradienthunt.com/]: Free gradients that you can\n    either copy as CSS rules or download them as .png images. They also offer a\n    Chrome extension.\n 4. Color Hunt [https://colorhunt.co/]: Free color schemas. Also offers a Chrome\n    extension.\n\nOther\n 1. Pattern Cooler [https://www.patterncooler.com/]: Free background patterns.\n 2. The Pattern Library [http://thepatternlibrary.com/]: Free background\n    patterns.\n 3. hatchful [https://hatchful.shopify.com/]: Free logo generator.","html":"<p>Perhaps one of the hardest tasks is finding free resources for your projects. This list will hold websites that offer freebies. I will try to keep the list updated along the way.</p><p>Some of the websites may have a different license for each resource they offer, so you might need to look out for that.</p><hr><h2 id=\"general\">General</h2><ol><li><a href=\"https://freebiesupply.com/\" rel=\"noopener nofollow\"><strong><strong>Freebie Supply</strong></strong></a><strong><strong>: </strong></strong>Free icons, vectors, fonts, templates, themes and more.</li><li><a href=\"https://freebiesbug.com/\" rel=\"noopener nofollow\"><strong><strong>Freebiesbug</strong></strong></a>: Another website that has a wide collection of icons, vectors, templates, and more.</li><li><a href=\"https://neede.co/\" rel=\"noopener nofollow\"><strong><strong>Neede</strong></strong></a><strong><strong>: </strong></strong>It’s aimed more towards designers, but developers might find some useful stuff like templates, colors, illustrations and more.</li></ol><h2 id=\"fonts\">Fonts</h2><ol><li><a href=\"https://fonts.google.com/\" rel=\"noopener nofollow\"><strong><strong>Google Fonts</strong></strong></a></li><li><a href=\"https://www.1001fonts.com/\" rel=\"noopener nofollow\"><strong><strong>1001 Fonts</strong></strong></a></li></ol><h2 id=\"icons\">Icons</h2><ol><li><a href=\"https://material.io/resources/icons/\" rel=\"noopener nofollow\"><strong><strong>Material Design Icons</strong></strong></a></li><li><a href=\"https://feathericons.com/\" rel=\"noopener nofollow\"><strong><strong>Feather</strong></strong></a></li><li><a href=\"https://www.svgrepo.com/\" rel=\"noopener nofollow\"><strong><strong>SVG Repo</strong></strong></a></li></ol><h2 id=\"website-templates\">Website Templates</h2><ol><li><a href=\"https://www.free-css.com/\" rel=\"noopener nofollow\"><strong><strong>Free CSS</strong></strong></a>: Free CSS templates, layouts, and menus.</li><li><a href=\"https://www.freewebtemplates.com/\" rel=\"noopener nofollow\"><strong><strong>Free Web Templates</strong></strong></a></li><li><a href=\"https://freewebsitetemplates.com/\" rel=\"noopener nofollow\"><strong><strong>Free Website Templates</strong></strong></a></li><li><a href=\"https://onepagelove.com/templates/html-templates\" rel=\"noopener nofollow\"><strong><strong>One Page HTML templates</strong></strong></a></li><li><a href=\"https://bootstrapmade.com/\" rel=\"noopener nofollow\"><strong><strong>BootstrapMade</strong></strong></a>: Free website templates (requires attribution)</li><li><a href=\"https://html5up.net/\" rel=\"noopener nofollow\"><strong><strong>HTML5 UP!</strong></strong></a><strong><strong>: </strong></strong>Free responsive HTML5 templates (requires attribution)</li><li><a href=\"https://templated.co/\" rel=\"noopener nofollow\"><strong><strong>TEMPLATD</strong></strong></a>: Free HTML templates (requires attribution)</li></ol><h2 id=\"illustrations\">Illustrations</h2><ol><li><a href=\"https://undraw.co/\" rel=\"noopener nofollow\"><strong><strong>unDraw</strong></strong></a>: Free illustrations for any project you can think of.</li><li><a href=\"https://lukaszadam.com/illustrations\" rel=\"noopener nofollow\"><strong><strong>Lukasz Adam’s Free Illustrations</strong></strong></a><strong><strong>: </strong></strong>Free unique illustrations.</li><li><a href=\"https://www.drawkit.io/\" rel=\"noopener nofollow\"><strong><strong>DrawKit</strong></strong></a>: Free wide range of illustrations.</li></ol><h2 id=\"images\">Images</h2><ol><li><a href=\"https://unsplash.com/\" rel=\"noopener nofollow\"><strong><strong>Unsplash</strong></strong></a><strong><strong>: </strong></strong>Free images with no attribution required.</li><li><a href=\"https://www.pexels.com/\" rel=\"noopener nofollow\"><strong><strong>Pexels</strong></strong></a>: Free stock images with no attribution required.</li></ol><h2 id=\"gradients-and-colors\">Gradients and Colors</h2><ol><li><a href=\"https://webgradients.com/\" rel=\"noopener nofollow\"><strong><strong>WebGradients</strong></strong></a>: Free gradients that you can either copy as CSS rules or download them as .sketch or .psd</li><li><a href=\"https://uigradients.com/#Pinky\" rel=\"noopener nofollow\"><strong><strong>uiGradients</strong></strong></a>: Free gradients that you can either copy as CSS rules or download them as .jpg images.</li><li><a href=\"https://gradienthunt.com/\" rel=\"noopener nofollow\"><strong><strong>Gradient Hunt</strong></strong></a>: Free gradients that you can either copy as CSS rules or download them as .png images. They also offer a Chrome extension.</li><li><a href=\"https://colorhunt.co/\" rel=\"noopener nofollow\"><strong><strong>Color Hunt</strong></strong></a>: Free color schemas. Also offers a Chrome extension.</li></ol><h2 id=\"other\">Other</h2><ol><li><a href=\"https://www.patterncooler.com/\" rel=\"noopener nofollow\"><strong><strong>Pattern Cooler</strong></strong></a>: Free background patterns.</li><li><a href=\"http://thepatternlibrary.com/\" rel=\"noopener nofollow\"><strong><strong>The Pattern Library</strong></strong></a>: Free background patterns.</li><li><a href=\"https://hatchful.shopify.com/\" rel=\"noopener nofollow\"><strong><strong>hatchful</strong></strong></a>: Free logo generator.</li></ol>","url":"https://backend.shahednasser.com/best-websites-to-find-free-resources-for-frontend-web-developers-and-designers/","canonical_url":null,"uuid":"09c132ce-ef97-45b9-8943-a38cf875e93f","codeinjection_foot":null,"codeinjection_head":null,"codeinjection_styles":null,"comment_id":"5f9740bab366d4001e86cc8c","reading_time":1,"send_email_when_published":null,"email_subject":null,"childHtmlRehype":{"html":"<p>Perhaps one of the hardest tasks is finding free resources for your projects. This list will hold websites that offer freebies. I will try to keep the list updated along the way.</p><p>Some of the websites may have a different license for each resource they offer, so you might need to look out for that.</p><hr><h2 id=\"general\">General</h2><ol><li><a href=\"https://freebiesupply.com/\" rel=\"noopener nofollow\"><strong><strong>Freebie Supply</strong></strong></a><strong><strong>: </strong></strong>Free icons, vectors, fonts, templates, themes and more.</li><li><a href=\"https://freebiesbug.com/\" rel=\"noopener nofollow\"><strong><strong>Freebiesbug</strong></strong></a>: Another website that has a wide collection of icons, vectors, templates, and more.</li><li><a href=\"https://neede.co/\" rel=\"noopener nofollow\"><strong><strong>Neede</strong></strong></a><strong><strong>: </strong></strong>It’s aimed more towards designers, but developers might find some useful stuff like templates, colors, illustrations and more.</li></ol><h2 id=\"fonts\">Fonts</h2><ol><li><a href=\"https://fonts.google.com/\" rel=\"noopener nofollow\"><strong><strong>Google Fonts</strong></strong></a></li><li><a href=\"https://www.1001fonts.com/\" rel=\"noopener nofollow\"><strong><strong>1001 Fonts</strong></strong></a></li></ol><h2 id=\"icons\">Icons</h2><ol><li><a href=\"https://material.io/resources/icons/\" rel=\"noopener nofollow\"><strong><strong>Material Design Icons</strong></strong></a></li><li><a href=\"https://feathericons.com/\" rel=\"noopener nofollow\"><strong><strong>Feather</strong></strong></a></li><li><a href=\"https://www.svgrepo.com/\" rel=\"noopener nofollow\"><strong><strong>SVG Repo</strong></strong></a></li></ol><h2 id=\"website-templates\">Website Templates</h2><ol><li><a href=\"https://www.free-css.com/\" rel=\"noopener nofollow\"><strong><strong>Free CSS</strong></strong></a>: Free CSS templates, layouts, and menus.</li><li><a href=\"https://www.freewebtemplates.com/\" rel=\"noopener nofollow\"><strong><strong>Free Web Templates</strong></strong></a></li><li><a href=\"https://freewebsitetemplates.com/\" rel=\"noopener nofollow\"><strong><strong>Free Website Templates</strong></strong></a></li><li><a href=\"https://onepagelove.com/templates/html-templates\" rel=\"noopener nofollow\"><strong><strong>One Page HTML templates</strong></strong></a></li><li><a href=\"https://bootstrapmade.com/\" rel=\"noopener nofollow\"><strong><strong>BootstrapMade</strong></strong></a>: Free website templates (requires attribution)</li><li><a href=\"https://html5up.net/\" rel=\"noopener nofollow\"><strong><strong>HTML5 UP!</strong></strong></a><strong><strong>: </strong></strong>Free responsive HTML5 templates (requires attribution)</li><li><a href=\"https://templated.co/\" rel=\"noopener nofollow\"><strong><strong>TEMPLATD</strong></strong></a>: Free HTML templates (requires attribution)</li></ol><h2 id=\"illustrations\">Illustrations</h2><ol><li><a href=\"https://undraw.co/\" rel=\"noopener nofollow\"><strong><strong>unDraw</strong></strong></a>: Free illustrations for any project you can think of.</li><li><a href=\"https://lukaszadam.com/illustrations\" rel=\"noopener nofollow\"><strong><strong>Lukasz Adam’s Free Illustrations</strong></strong></a><strong><strong>: </strong></strong>Free unique illustrations.</li><li><a href=\"https://www.drawkit.io/\" rel=\"noopener nofollow\"><strong><strong>DrawKit</strong></strong></a>: Free wide range of illustrations.</li></ol><h2 id=\"images\">Images</h2><ol><li><a href=\"https://unsplash.com/\" rel=\"noopener nofollow\"><strong><strong>Unsplash</strong></strong></a><strong><strong>: </strong></strong>Free images with no attribution required.</li><li><a href=\"https://www.pexels.com/\" rel=\"noopener nofollow\"><strong><strong>Pexels</strong></strong></a>: Free stock images with no attribution required.</li></ol><h2 id=\"gradients-and-colors\">Gradients and Colors</h2><ol><li><a href=\"https://webgradients.com/\" rel=\"noopener nofollow\"><strong><strong>WebGradients</strong></strong></a>: Free gradients that you can either copy as CSS rules or download them as .sketch or .psd</li><li><a href=\"https://uigradients.com/#Pinky\" rel=\"noopener nofollow\"><strong><strong>uiGradients</strong></strong></a>: Free gradients that you can either copy as CSS rules or download them as .jpg images.</li><li><a href=\"https://gradienthunt.com/\" rel=\"noopener nofollow\"><strong><strong>Gradient Hunt</strong></strong></a>: Free gradients that you can either copy as CSS rules or download them as .png images. They also offer a Chrome extension.</li><li><a href=\"https://colorhunt.co/\" rel=\"noopener nofollow\"><strong><strong>Color Hunt</strong></strong></a>: Free color schemas. Also offers a Chrome extension.</li></ol><h2 id=\"other\">Other</h2><ol><li><a href=\"https://www.patterncooler.com/\" rel=\"noopener nofollow\"><strong><strong>Pattern Cooler</strong></strong></a>: Free background patterns.</li><li><a href=\"http://thepatternlibrary.com/\" rel=\"noopener nofollow\"><strong><strong>The Pattern Library</strong></strong></a>: Free background patterns.</li><li><a href=\"https://hatchful.shopify.com/\" rel=\"noopener nofollow\"><strong><strong>hatchful</strong></strong></a>: Free logo generator.</li></ol>","htmlAst":{"type":"root","children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Perhaps one of the hardest tasks is finding free resources for your projects. This list will hold websites that offer freebies. I will try to keep the list updated along the way."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Some of the websites may have a different license for each resource they offer, so you might need to look out for that."}]},{"type":"element","tagName":"hr","properties":{},"children":[]},{"type":"element","tagName":"h2","properties":{"id":"general"},"children":[{"type":"text","value":"General"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://freebiesupply.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Freebie Supply"}]}]}]},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":": "}]}]},{"type":"text","value":"Free icons, vectors, fonts, templates, themes and more."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://freebiesbug.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Freebiesbug"}]}]}]},{"type":"text","value":": Another website that has a wide collection of icons, vectors, templates, and more."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://neede.co/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Neede"}]}]}]},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":": "}]}]},{"type":"text","value":"It’s aimed more towards designers, but developers might find some useful stuff like templates, colors, illustrations and more."}]}]},{"type":"element","tagName":"h2","properties":{"id":"fonts"},"children":[{"type":"text","value":"Fonts"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://fonts.google.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Google Fonts"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.1001fonts.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1001 Fonts"}]}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"icons"},"children":[{"type":"text","value":"Icons"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://material.io/resources/icons/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Material Design Icons"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://feathericons.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Feather"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.svgrepo.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"SVG Repo"}]}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"website-templates"},"children":[{"type":"text","value":"Website Templates"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.free-css.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Free CSS"}]}]}]},{"type":"text","value":": Free CSS templates, layouts, and menus."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.freewebtemplates.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Free Web Templates"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://freewebsitetemplates.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Free Website Templates"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://onepagelove.com/templates/html-templates","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"One Page HTML templates"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://bootstrapmade.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"BootstrapMade"}]}]}]},{"type":"text","value":": Free website templates (requires attribution)"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://html5up.net/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"HTML5 UP!"}]}]}]},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":": "}]}]},{"type":"text","value":"Free responsive HTML5 templates (requires attribution)"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://templated.co/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"TEMPLATD"}]}]}]},{"type":"text","value":": Free HTML templates (requires attribution)"}]}]},{"type":"element","tagName":"h2","properties":{"id":"illustrations"},"children":[{"type":"text","value":"Illustrations"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://undraw.co/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"unDraw"}]}]}]},{"type":"text","value":": Free illustrations for any project you can think of."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://lukaszadam.com/illustrations","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Lukasz Adam’s Free Illustrations"}]}]}]},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":": "}]}]},{"type":"text","value":"Free unique illustrations."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.drawkit.io/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"DrawKit"}]}]}]},{"type":"text","value":": Free wide range of illustrations."}]}]},{"type":"element","tagName":"h2","properties":{"id":"images"},"children":[{"type":"text","value":"Images"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://unsplash.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Unsplash"}]}]}]},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":": "}]}]},{"type":"text","value":"Free images with no attribution required."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.pexels.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Pexels"}]}]}]},{"type":"text","value":": Free stock images with no attribution required."}]}]},{"type":"element","tagName":"h2","properties":{"id":"gradients-and-colors"},"children":[{"type":"text","value":"Gradients and Colors"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://webgradients.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"WebGradients"}]}]}]},{"type":"text","value":": Free gradients that you can either copy as CSS rules or download them as .sketch or .psd"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://uigradients.com/#Pinky","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"uiGradients"}]}]}]},{"type":"text","value":": Free gradients that you can either copy as CSS rules or download them as .jpg images."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://gradienthunt.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Gradient Hunt"}]}]}]},{"type":"text","value":": Free gradients that you can either copy as CSS rules or download them as .png images. They also offer a Chrome extension."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://colorhunt.co/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Color Hunt"}]}]}]},{"type":"text","value":": Free color schemas. Also offers a Chrome extension."}]}]},{"type":"element","tagName":"h2","properties":{"id":"other"},"children":[{"type":"text","value":"Other"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.patterncooler.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Pattern Cooler"}]}]}]},{"type":"text","value":": Free background patterns."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"http://thepatternlibrary.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"The Pattern Library"}]}]}]},{"type":"text","value":": Free background patterns."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://hatchful.shopify.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"hatchful"}]}]}]},{"type":"text","value":": Free logo generator."}]}]}],"data":{"quirksMode":false}},"tableOfContents":[{"id":"general","heading":"General"},{"id":"fonts","heading":"Fonts"},{"id":"icons","heading":"Icons"},{"id":"website-templates","heading":"Website Templates"},{"id":"illustrations","heading":"Illustrations"},{"id":"images","heading":"Images"},{"id":"gradients-and-colors","heading":"Gradients and Colors"},{"id":"other","heading":"Other"}]},"featureImageSharp":{"base":"photo-1505304451-3b3b85a91afe.jpg","publicURL":"/static/5b5b3cb18304a6e7b147980c13d0c5b3/photo-1505304451-3b3b85a91afe.jpg","imageMeta":{"width":2000,"height":1125},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAALABQDASIAAhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAAMEAv/EABUBAQEAAAAAAAAAAAAAAAAAAAAB/9oADAMBAAIQAxAAAAFdUUwgwR//xAAbEAEAAgIDAAAAAAAAAAAAAAABAgMABBMiMf/aAAgBAQABBQLX7FsXJqTqsmPPasvf/8QAFREBAQAAAAAAAAAAAAAAAAAAEBH/2gAIAQMBAT8Bh//EABYRAAMAAAAAAAAAAAAAAAAAABARIf/aAAgBAgEBPwFwf//EABsQAQACAgMAAAAAAAAAAAAAAAEAAhEhEBIx/9oACAEBAAY/An0me9tRhUdRzd4//8QAGhAAAwEBAQEAAAAAAAAAAAAAAAERITFBUf/aAAgBAQABPyGW9r2xJGLH0paKO3fSKn5GiMDNu31n/9oADAMBAAIAAwAAABBv3//EABYRAAMAAAAAAAAAAAAAAAAAAAABIf/aAAgBAwEBPxCHRn//xAAWEQEBAQAAAAAAAAAAAAAAAAAAIQH/2gAIAQIBAT8QuGP/xAAdEAEAAwABBQAAAAAAAAAAAAABABEhMUFRYXGh/9oACAEBAAE/EKUdjLuR9lP3wg8Zce+b0WxhiG0Ngsg4MipLor1n/9k=","aspectRatio":1.7808219178082192,"src":"/static/5b5b3cb18304a6e7b147980c13d0c5b3/d5c54/photo-1505304451-3b3b85a91afe.jpg","srcSet":"/static/5b5b3cb18304a6e7b147980c13d0c5b3/65d8c/photo-1505304451-3b3b85a91afe.jpg 260w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/c5f21/photo-1505304451-3b3b85a91afe.jpg 520w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/d5c54/photo-1505304451-3b3b85a91afe.jpg 1040w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/81a53/photo-1505304451-3b3b85a91afe.jpg 1560w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/4e5f3/photo-1505304451-3b3b85a91afe.jpg 2000w","srcWebp":"/static/5b5b3cb18304a6e7b147980c13d0c5b3/e4875/photo-1505304451-3b3b85a91afe.webp","srcSetWebp":"/static/5b5b3cb18304a6e7b147980c13d0c5b3/dc8f3/photo-1505304451-3b3b85a91afe.webp 260w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/2db4b/photo-1505304451-3b3b85a91afe.webp 520w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/e4875/photo-1505304451-3b3b85a91afe.webp 1040w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/f5845/photo-1505304451-3b3b85a91afe.webp 1560w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/49d6b/photo-1505304451-3b3b85a91afe.webp 2000w","sizes":"(max-width: 1040px) 100vw, 1040px"}}}},"ghostPost":{"id":"Ghost__Post__6127ba1b3ed159214d382e6d","title":"Best Websites to Find Free Resources for Frontend Web Developers and Designers","slug":"best-websites-to-find-free-resources-for-frontend-web-developers-and-designers","featured":false,"feature_image":"https://res-2.cloudinary.com/hbqmf3mbz/image/upload/q_auto/v1/ghost-blog-images/photo-1505304451-3b3b85a91afe.jpg","excerpt":"Perhaps one of the hardest tasks is finding free resources for your projects. This list will hold websites that offer freebies.","custom_excerpt":"Perhaps one of the hardest tasks is finding free resources for your projects. This list will hold websites that offer freebies.","visibility":"public","created_at_pretty":"26 Oct 2020","published_at_pretty":"26 Aug 2019","updated_at_pretty":"26 Aug 2021","created_at":"2020-10-26T21:33:46.000+00:00","published_at":"2019-08-26T21:33:00.000+00:00","updated_at":"2021-08-26T17:54:20.000+00:00","meta_title":null,"meta_description":null,"og_description":null,"og_image":null,"og_title":null,"twitter_description":null,"twitter_image":null,"twitter_title":null,"authors":[{"slug":"shahed","url":"https://backend.shahednasser.com/author/shahed/","name":"Shahed Nasser","bio":null,"cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/03/IMG_0591.jpg","location":null,"website":null,"twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":null}],"primary_author":{"slug":"shahed","url":"https://backend.shahednasser.com/author/shahed/","name":"Shahed Nasser","bio":null,"cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/03/IMG_0591.jpg","location":null,"website":null,"twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":{"base":"IMG_0591.jpg","publicURL":"/static/ceb49c3c631485453e71e00d7f84b069/IMG_0591.jpg","imageMeta":{"width":1182,"height":1179},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAUABQDASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAMEAQL/xAAWAQEBAQAAAAAAAAAAAAAAAAADBAL/2gAMAwEAAhADEAAAAdXiFM6i0CohUWXoKn//xAAcEAACAgIDAAAAAAAAAAAAAAACAwESBBEhM0H/2gAIAQEAAQUCWySE3WEr7SzbXjAj4iKty+sOQ//EABYRAQEBAAAAAAAAAAAAAAAAAAERIP/aAAgBAwEBPwEhj//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8BH//EAB4QAAIBBAMBAAAAAAAAAAAAAAABIRESMUECECJx/9oACAEBAAY/ApVGWvOjzgtUwLlTZA0sdL4f/8QAHBAAAwACAwEAAAAAAAAAAAAAAAERITFBkbHB/9oACAEBAAE/IahkCy+N2GwZpjQiJHJCspUFY0QrSi+HqiW2rgf/2gAMAwEAAgADAAAAEPw3/wD/xAAYEQEBAAMAAAAAAAAAAAAAAAAAARExQf/aAAgBAwEBPxCtjDqP/8QAFxEBAQEBAAAAAAAAAAAAAAAAAQAxEf/aAAgBAgEBPxBFus6Tt//EAB8QAQEAAgIBBQAAAAAAAAAAAAERACExQWFRcYGR0f/aAAgBAQABPxAuaBPPzkO1wyX7F4wkwXanfZrFQgeqE9JgS14vVOvrERIJomVBKwt2jebAeP0yVa8h1n//2Q==","aspectRatio":1,"src":"/static/ceb49c3c631485453e71e00d7f84b069/31709/IMG_0591.jpg","srcSet":"/static/ceb49c3c631485453e71e00d7f84b069/f340b/IMG_0591.jpg 28w,\n/static/ceb49c3c631485453e71e00d7f84b069/22d64/IMG_0591.jpg 55w,\n/static/ceb49c3c631485453e71e00d7f84b069/31709/IMG_0591.jpg 110w,\n/static/ceb49c3c631485453e71e00d7f84b069/aa249/IMG_0591.jpg 165w,\n/static/ceb49c3c631485453e71e00d7f84b069/0dc33/IMG_0591.jpg 220w,\n/static/ceb49c3c631485453e71e00d7f84b069/d8257/IMG_0591.jpg 1182w","srcWebp":"/static/ceb49c3c631485453e71e00d7f84b069/8678c/IMG_0591.webp","srcSetWebp":"/static/ceb49c3c631485453e71e00d7f84b069/59cda/IMG_0591.webp 28w,\n/static/ceb49c3c631485453e71e00d7f84b069/7da75/IMG_0591.webp 55w,\n/static/ceb49c3c631485453e71e00d7f84b069/8678c/IMG_0591.webp 110w,\n/static/ceb49c3c631485453e71e00d7f84b069/f282e/IMG_0591.webp 165w,\n/static/ceb49c3c631485453e71e00d7f84b069/a7b21/IMG_0591.webp 220w,\n/static/ceb49c3c631485453e71e00d7f84b069/63099/IMG_0591.webp 1182w","sizes":"(max-width: 110px) 100vw, 110px"}}}},"primary_tag":{"slug":"beginner","url":"https://backend.shahednasser.com/tag/beginner/","name":"Beginners","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1521185496955-15097b20c5fe-2.jpeg","description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","meta_title":"Beginners","meta_description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","featureImageSharp":{"base":"photo-1521185496955-15097b20c5fe-2.jpeg","publicURL":"/static/13f953658eaecb779984996ea356b1c4/photo-1521185496955-15097b20c5fe-2.jpeg","imageMeta":{"width":2000,"height":1547},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAPABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAQCBf/EABYBAQEBAAAAAAAAAAAAAAAAAAIAAf/aAAwDAQACEAMQAAABhU05c9sV/8QAGRAAAwEBAQAAAAAAAAAAAAAAAQIDABIR/9oACAEBAAEFAuTgGxGjVeRdPLOHf//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8BP//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQIBAT8BP//EABkQAAMBAQEAAAAAAAAAAAAAAAABEXECEP/aAAgBAQAGPwL2dJaOqYVH/8QAGhAAAwADAQAAAAAAAAAAAAAAAAERITFBYf/aAAgBAQABPyFpWJH6IutKCacL+lRRGxiDm+H/2gAMAwEAAgADAAAAEK//AP/EABYRAQEBAAAAAAAAAAAAAAAAAAEREP/aAAgBAwEBPxAI3P/EABYRAQEBAAAAAAAAAAAAAAAAAAERAP/aAAgBAgEBPxBaR03/xAAbEAEBAAIDAQAAAAAAAAAAAAABEQAhMUGxcf/aAAgBAQABPxAInmDF9wQ6urfMI5JgA/si0141k9pEa4fcjFJmybz/2Q==","aspectRatio":1.2935323383084578,"src":"/static/13f953658eaecb779984996ea356b1c4/d5c54/photo-1521185496955-15097b20c5fe-2.jpg","srcSet":"/static/13f953658eaecb779984996ea356b1c4/65d8c/photo-1521185496955-15097b20c5fe-2.jpg 260w,\n/static/13f953658eaecb779984996ea356b1c4/c5f21/photo-1521185496955-15097b20c5fe-2.jpg 520w,\n/static/13f953658eaecb779984996ea356b1c4/d5c54/photo-1521185496955-15097b20c5fe-2.jpg 1040w,\n/static/13f953658eaecb779984996ea356b1c4/81a53/photo-1521185496955-15097b20c5fe-2.jpg 1560w,\n/static/13f953658eaecb779984996ea356b1c4/4e5f3/photo-1521185496955-15097b20c5fe-2.jpg 2000w","srcWebp":"/static/13f953658eaecb779984996ea356b1c4/e4875/photo-1521185496955-15097b20c5fe-2.webp","srcSetWebp":"/static/13f953658eaecb779984996ea356b1c4/dc8f3/photo-1521185496955-15097b20c5fe-2.webp 260w,\n/static/13f953658eaecb779984996ea356b1c4/2db4b/photo-1521185496955-15097b20c5fe-2.webp 520w,\n/static/13f953658eaecb779984996ea356b1c4/e4875/photo-1521185496955-15097b20c5fe-2.webp 1040w,\n/static/13f953658eaecb779984996ea356b1c4/f5845/photo-1521185496955-15097b20c5fe-2.webp 1560w,\n/static/13f953658eaecb779984996ea356b1c4/49d6b/photo-1521185496955-15097b20c5fe-2.webp 2000w","sizes":"(max-width: 1040px) 100vw, 1040px"}}}},"tags":[{"slug":"beginner","url":"https://backend.shahednasser.com/tag/beginner/","name":"Beginners","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1521185496955-15097b20c5fe-2.jpeg","description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","meta_title":"Beginners","meta_description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","featureImageSharp":null},{"slug":"tips","url":"https://backend.shahednasser.com/tag/tips/","name":"Tips","visibility":"public","feature_image":null,"description":"Learn more about programming and development through these articles that have essential tips!","meta_title":"Tips on Technology and Programming","meta_description":null,"featureImageSharp":null},{"slug":"open-source","url":"https://backend.shahednasser.com/tag/open-source/","name":"Open Source","visibility":"public","feature_image":null,"description":null,"meta_title":null,"meta_description":null,"featureImageSharp":null},{"slug":"design","url":"https://backend.shahednasser.com/tag/design/","name":"Design","visibility":"public","feature_image":null,"description":"Learn more about Web Design through tutorials, articles and tips.","meta_title":null,"meta_description":null,"featureImageSharp":null}],"plaintext":"Perhaps one of the hardest tasks is finding free resources for your projects.\nThis list will hold websites that offer freebies. I will try to keep the list\nupdated along the way.\n\nSome of the websites may have a different license for each resource they offer,\nso you might need to look out for that.\n\n\n--------------------------------------------------------------------------------\n\nGeneral\n 1. Freebie Supply [https://freebiesupply.com/]: Free icons, vectors, fonts,\n    templates, themes and more.\n 2. Freebiesbug [https://freebiesbug.com/]: Another website that has a wide\n    collection of icons, vectors, templates, and more.\n 3. Neede [https://neede.co/]: It’s aimed more towards designers, but developers\n    might find some useful stuff like templates, colors, illustrations and more.\n\nFonts\n 1. Google Fonts [https://fonts.google.com/]\n 2. 1001 Fonts [https://www.1001fonts.com/]\n\nIcons\n 1. Material Design Icons [https://material.io/resources/icons/]\n 2. Feather [https://feathericons.com/]\n 3. SVG Repo [https://www.svgrepo.com/]\n\nWebsite Templates\n 1. Free CSS [https://www.free-css.com/]: Free CSS templates, layouts, and\n    menus.\n 2. Free Web Templates [https://www.freewebtemplates.com/]\n 3. Free Website Templates [https://freewebsitetemplates.com/]\n 4. One Page HTML templates [https://onepagelove.com/templates/html-templates]\n 5. BootstrapMade [https://bootstrapmade.com/]: Free website templates (requires\n    attribution)\n 6. HTML5 UP! [https://html5up.net/]: Free responsive HTML5 templates (requires\n    attribution)\n 7. TEMPLATD [https://templated.co/]: Free HTML templates (requires attribution)\n\nIllustrations\n 1. unDraw [https://undraw.co/]: Free illustrations for any project you can\n    think of.\n 2. Lukasz Adam’s Free Illustrations [https://lukaszadam.com/illustrations]: \n    Free unique illustrations.\n 3. DrawKit [https://www.drawkit.io/]: Free wide range of illustrations.\n\nImages\n 1. Unsplash [https://unsplash.com/]: Free images with no attribution required.\n 2. Pexels [https://www.pexels.com/]: Free stock images with no attribution\n    required.\n\nGradients and Colors\n 1. WebGradients [https://webgradients.com/]: Free gradients that you can either\n    copy as CSS rules or download them as .sketch or .psd\n 2. uiGradients [https://uigradients.com/#Pinky]: Free gradients that you can\n    either copy as CSS rules or download them as .jpg images.\n 3. Gradient Hunt [https://gradienthunt.com/]: Free gradients that you can\n    either copy as CSS rules or download them as .png images. They also offer a\n    Chrome extension.\n 4. Color Hunt [https://colorhunt.co/]: Free color schemas. Also offers a Chrome\n    extension.\n\nOther\n 1. Pattern Cooler [https://www.patterncooler.com/]: Free background patterns.\n 2. The Pattern Library [http://thepatternlibrary.com/]: Free background\n    patterns.\n 3. hatchful [https://hatchful.shopify.com/]: Free logo generator.","html":"<p>Perhaps one of the hardest tasks is finding free resources for your projects. This list will hold websites that offer freebies. I will try to keep the list updated along the way.</p><p>Some of the websites may have a different license for each resource they offer, so you might need to look out for that.</p><hr><h2 id=\"general\">General</h2><ol><li><a href=\"https://freebiesupply.com/\" rel=\"noopener nofollow\"><strong><strong>Freebie Supply</strong></strong></a><strong><strong>: </strong></strong>Free icons, vectors, fonts, templates, themes and more.</li><li><a href=\"https://freebiesbug.com/\" rel=\"noopener nofollow\"><strong><strong>Freebiesbug</strong></strong></a>: Another website that has a wide collection of icons, vectors, templates, and more.</li><li><a href=\"https://neede.co/\" rel=\"noopener nofollow\"><strong><strong>Neede</strong></strong></a><strong><strong>: </strong></strong>It’s aimed more towards designers, but developers might find some useful stuff like templates, colors, illustrations and more.</li></ol><h2 id=\"fonts\">Fonts</h2><ol><li><a href=\"https://fonts.google.com/\" rel=\"noopener nofollow\"><strong><strong>Google Fonts</strong></strong></a></li><li><a href=\"https://www.1001fonts.com/\" rel=\"noopener nofollow\"><strong><strong>1001 Fonts</strong></strong></a></li></ol><h2 id=\"icons\">Icons</h2><ol><li><a href=\"https://material.io/resources/icons/\" rel=\"noopener nofollow\"><strong><strong>Material Design Icons</strong></strong></a></li><li><a href=\"https://feathericons.com/\" rel=\"noopener nofollow\"><strong><strong>Feather</strong></strong></a></li><li><a href=\"https://www.svgrepo.com/\" rel=\"noopener nofollow\"><strong><strong>SVG Repo</strong></strong></a></li></ol><h2 id=\"website-templates\">Website Templates</h2><ol><li><a href=\"https://www.free-css.com/\" rel=\"noopener nofollow\"><strong><strong>Free CSS</strong></strong></a>: Free CSS templates, layouts, and menus.</li><li><a href=\"https://www.freewebtemplates.com/\" rel=\"noopener nofollow\"><strong><strong>Free Web Templates</strong></strong></a></li><li><a href=\"https://freewebsitetemplates.com/\" rel=\"noopener nofollow\"><strong><strong>Free Website Templates</strong></strong></a></li><li><a href=\"https://onepagelove.com/templates/html-templates\" rel=\"noopener nofollow\"><strong><strong>One Page HTML templates</strong></strong></a></li><li><a href=\"https://bootstrapmade.com/\" rel=\"noopener nofollow\"><strong><strong>BootstrapMade</strong></strong></a>: Free website templates (requires attribution)</li><li><a href=\"https://html5up.net/\" rel=\"noopener nofollow\"><strong><strong>HTML5 UP!</strong></strong></a><strong><strong>: </strong></strong>Free responsive HTML5 templates (requires attribution)</li><li><a href=\"https://templated.co/\" rel=\"noopener nofollow\"><strong><strong>TEMPLATD</strong></strong></a>: Free HTML templates (requires attribution)</li></ol><h2 id=\"illustrations\">Illustrations</h2><ol><li><a href=\"https://undraw.co/\" rel=\"noopener nofollow\"><strong><strong>unDraw</strong></strong></a>: Free illustrations for any project you can think of.</li><li><a href=\"https://lukaszadam.com/illustrations\" rel=\"noopener nofollow\"><strong><strong>Lukasz Adam’s Free Illustrations</strong></strong></a><strong><strong>: </strong></strong>Free unique illustrations.</li><li><a href=\"https://www.drawkit.io/\" rel=\"noopener nofollow\"><strong><strong>DrawKit</strong></strong></a>: Free wide range of illustrations.</li></ol><h2 id=\"images\">Images</h2><ol><li><a href=\"https://unsplash.com/\" rel=\"noopener nofollow\"><strong><strong>Unsplash</strong></strong></a><strong><strong>: </strong></strong>Free images with no attribution required.</li><li><a href=\"https://www.pexels.com/\" rel=\"noopener nofollow\"><strong><strong>Pexels</strong></strong></a>: Free stock images with no attribution required.</li></ol><h2 id=\"gradients-and-colors\">Gradients and Colors</h2><ol><li><a href=\"https://webgradients.com/\" rel=\"noopener nofollow\"><strong><strong>WebGradients</strong></strong></a>: Free gradients that you can either copy as CSS rules or download them as .sketch or .psd</li><li><a href=\"https://uigradients.com/#Pinky\" rel=\"noopener nofollow\"><strong><strong>uiGradients</strong></strong></a>: Free gradients that you can either copy as CSS rules or download them as .jpg images.</li><li><a href=\"https://gradienthunt.com/\" rel=\"noopener nofollow\"><strong><strong>Gradient Hunt</strong></strong></a>: Free gradients that you can either copy as CSS rules or download them as .png images. They also offer a Chrome extension.</li><li><a href=\"https://colorhunt.co/\" rel=\"noopener nofollow\"><strong><strong>Color Hunt</strong></strong></a>: Free color schemas. Also offers a Chrome extension.</li></ol><h2 id=\"other\">Other</h2><ol><li><a href=\"https://www.patterncooler.com/\" rel=\"noopener nofollow\"><strong><strong>Pattern Cooler</strong></strong></a>: Free background patterns.</li><li><a href=\"http://thepatternlibrary.com/\" rel=\"noopener nofollow\"><strong><strong>The Pattern Library</strong></strong></a>: Free background patterns.</li><li><a href=\"https://hatchful.shopify.com/\" rel=\"noopener nofollow\"><strong><strong>hatchful</strong></strong></a>: Free logo generator.</li></ol>","url":"https://backend.shahednasser.com/best-websites-to-find-free-resources-for-frontend-web-developers-and-designers/","canonical_url":null,"uuid":"09c132ce-ef97-45b9-8943-a38cf875e93f","codeinjection_foot":null,"codeinjection_head":null,"codeinjection_styles":null,"comment_id":"5f9740bab366d4001e86cc8c","reading_time":1,"send_email_when_published":null,"email_subject":null,"childHtmlRehype":{"html":"<p>Perhaps one of the hardest tasks is finding free resources for your projects. This list will hold websites that offer freebies. I will try to keep the list updated along the way.</p><p>Some of the websites may have a different license for each resource they offer, so you might need to look out for that.</p><hr><h2 id=\"general\">General</h2><ol><li><a href=\"https://freebiesupply.com/\" rel=\"noopener nofollow\"><strong><strong>Freebie Supply</strong></strong></a><strong><strong>: </strong></strong>Free icons, vectors, fonts, templates, themes and more.</li><li><a href=\"https://freebiesbug.com/\" rel=\"noopener nofollow\"><strong><strong>Freebiesbug</strong></strong></a>: Another website that has a wide collection of icons, vectors, templates, and more.</li><li><a href=\"https://neede.co/\" rel=\"noopener nofollow\"><strong><strong>Neede</strong></strong></a><strong><strong>: </strong></strong>It’s aimed more towards designers, but developers might find some useful stuff like templates, colors, illustrations and more.</li></ol><h2 id=\"fonts\">Fonts</h2><ol><li><a href=\"https://fonts.google.com/\" rel=\"noopener nofollow\"><strong><strong>Google Fonts</strong></strong></a></li><li><a href=\"https://www.1001fonts.com/\" rel=\"noopener nofollow\"><strong><strong>1001 Fonts</strong></strong></a></li></ol><h2 id=\"icons\">Icons</h2><ol><li><a href=\"https://material.io/resources/icons/\" rel=\"noopener nofollow\"><strong><strong>Material Design Icons</strong></strong></a></li><li><a href=\"https://feathericons.com/\" rel=\"noopener nofollow\"><strong><strong>Feather</strong></strong></a></li><li><a href=\"https://www.svgrepo.com/\" rel=\"noopener nofollow\"><strong><strong>SVG Repo</strong></strong></a></li></ol><h2 id=\"website-templates\">Website Templates</h2><ol><li><a href=\"https://www.free-css.com/\" rel=\"noopener nofollow\"><strong><strong>Free CSS</strong></strong></a>: Free CSS templates, layouts, and menus.</li><li><a href=\"https://www.freewebtemplates.com/\" rel=\"noopener nofollow\"><strong><strong>Free Web Templates</strong></strong></a></li><li><a href=\"https://freewebsitetemplates.com/\" rel=\"noopener nofollow\"><strong><strong>Free Website Templates</strong></strong></a></li><li><a href=\"https://onepagelove.com/templates/html-templates\" rel=\"noopener nofollow\"><strong><strong>One Page HTML templates</strong></strong></a></li><li><a href=\"https://bootstrapmade.com/\" rel=\"noopener nofollow\"><strong><strong>BootstrapMade</strong></strong></a>: Free website templates (requires attribution)</li><li><a href=\"https://html5up.net/\" rel=\"noopener nofollow\"><strong><strong>HTML5 UP!</strong></strong></a><strong><strong>: </strong></strong>Free responsive HTML5 templates (requires attribution)</li><li><a href=\"https://templated.co/\" rel=\"noopener nofollow\"><strong><strong>TEMPLATD</strong></strong></a>: Free HTML templates (requires attribution)</li></ol><h2 id=\"illustrations\">Illustrations</h2><ol><li><a href=\"https://undraw.co/\" rel=\"noopener nofollow\"><strong><strong>unDraw</strong></strong></a>: Free illustrations for any project you can think of.</li><li><a href=\"https://lukaszadam.com/illustrations\" rel=\"noopener nofollow\"><strong><strong>Lukasz Adam’s Free Illustrations</strong></strong></a><strong><strong>: </strong></strong>Free unique illustrations.</li><li><a href=\"https://www.drawkit.io/\" rel=\"noopener nofollow\"><strong><strong>DrawKit</strong></strong></a>: Free wide range of illustrations.</li></ol><h2 id=\"images\">Images</h2><ol><li><a href=\"https://unsplash.com/\" rel=\"noopener nofollow\"><strong><strong>Unsplash</strong></strong></a><strong><strong>: </strong></strong>Free images with no attribution required.</li><li><a href=\"https://www.pexels.com/\" rel=\"noopener nofollow\"><strong><strong>Pexels</strong></strong></a>: Free stock images with no attribution required.</li></ol><h2 id=\"gradients-and-colors\">Gradients and Colors</h2><ol><li><a href=\"https://webgradients.com/\" rel=\"noopener nofollow\"><strong><strong>WebGradients</strong></strong></a>: Free gradients that you can either copy as CSS rules or download them as .sketch or .psd</li><li><a href=\"https://uigradients.com/#Pinky\" rel=\"noopener nofollow\"><strong><strong>uiGradients</strong></strong></a>: Free gradients that you can either copy as CSS rules or download them as .jpg images.</li><li><a href=\"https://gradienthunt.com/\" rel=\"noopener nofollow\"><strong><strong>Gradient Hunt</strong></strong></a>: Free gradients that you can either copy as CSS rules or download them as .png images. They also offer a Chrome extension.</li><li><a href=\"https://colorhunt.co/\" rel=\"noopener nofollow\"><strong><strong>Color Hunt</strong></strong></a>: Free color schemas. Also offers a Chrome extension.</li></ol><h2 id=\"other\">Other</h2><ol><li><a href=\"https://www.patterncooler.com/\" rel=\"noopener nofollow\"><strong><strong>Pattern Cooler</strong></strong></a>: Free background patterns.</li><li><a href=\"http://thepatternlibrary.com/\" rel=\"noopener nofollow\"><strong><strong>The Pattern Library</strong></strong></a>: Free background patterns.</li><li><a href=\"https://hatchful.shopify.com/\" rel=\"noopener nofollow\"><strong><strong>hatchful</strong></strong></a>: Free logo generator.</li></ol>","htmlAst":{"type":"root","children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Perhaps one of the hardest tasks is finding free resources for your projects. This list will hold websites that offer freebies. I will try to keep the list updated along the way."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Some of the websites may have a different license for each resource they offer, so you might need to look out for that."}]},{"type":"element","tagName":"hr","properties":{},"children":[]},{"type":"element","tagName":"h2","properties":{"id":"general"},"children":[{"type":"text","value":"General"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://freebiesupply.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Freebie Supply"}]}]}]},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":": "}]}]},{"type":"text","value":"Free icons, vectors, fonts, templates, themes and more."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://freebiesbug.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Freebiesbug"}]}]}]},{"type":"text","value":": Another website that has a wide collection of icons, vectors, templates, and more."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://neede.co/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Neede"}]}]}]},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":": "}]}]},{"type":"text","value":"It’s aimed more towards designers, but developers might find some useful stuff like templates, colors, illustrations and more."}]}]},{"type":"element","tagName":"h2","properties":{"id":"fonts"},"children":[{"type":"text","value":"Fonts"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://fonts.google.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Google Fonts"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.1001fonts.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"1001 Fonts"}]}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"icons"},"children":[{"type":"text","value":"Icons"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://material.io/resources/icons/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Material Design Icons"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://feathericons.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Feather"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.svgrepo.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"SVG Repo"}]}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"website-templates"},"children":[{"type":"text","value":"Website Templates"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.free-css.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Free CSS"}]}]}]},{"type":"text","value":": Free CSS templates, layouts, and menus."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.freewebtemplates.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Free Web Templates"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://freewebsitetemplates.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Free Website Templates"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://onepagelove.com/templates/html-templates","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"One Page HTML templates"}]}]}]}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://bootstrapmade.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"BootstrapMade"}]}]}]},{"type":"text","value":": Free website templates (requires attribution)"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://html5up.net/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"HTML5 UP!"}]}]}]},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":": "}]}]},{"type":"text","value":"Free responsive HTML5 templates (requires attribution)"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://templated.co/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"TEMPLATD"}]}]}]},{"type":"text","value":": Free HTML templates (requires attribution)"}]}]},{"type":"element","tagName":"h2","properties":{"id":"illustrations"},"children":[{"type":"text","value":"Illustrations"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://undraw.co/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"unDraw"}]}]}]},{"type":"text","value":": Free illustrations for any project you can think of."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://lukaszadam.com/illustrations","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Lukasz Adam’s Free Illustrations"}]}]}]},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":": "}]}]},{"type":"text","value":"Free unique illustrations."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.drawkit.io/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"DrawKit"}]}]}]},{"type":"text","value":": Free wide range of illustrations."}]}]},{"type":"element","tagName":"h2","properties":{"id":"images"},"children":[{"type":"text","value":"Images"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://unsplash.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Unsplash"}]}]}]},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":": "}]}]},{"type":"text","value":"Free images with no attribution required."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.pexels.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Pexels"}]}]}]},{"type":"text","value":": Free stock images with no attribution required."}]}]},{"type":"element","tagName":"h2","properties":{"id":"gradients-and-colors"},"children":[{"type":"text","value":"Gradients and Colors"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://webgradients.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"WebGradients"}]}]}]},{"type":"text","value":": Free gradients that you can either copy as CSS rules or download them as .sketch or .psd"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://uigradients.com/#Pinky","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"uiGradients"}]}]}]},{"type":"text","value":": Free gradients that you can either copy as CSS rules or download them as .jpg images."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://gradienthunt.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Gradient Hunt"}]}]}]},{"type":"text","value":": Free gradients that you can either copy as CSS rules or download them as .png images. They also offer a Chrome extension."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://colorhunt.co/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Color Hunt"}]}]}]},{"type":"text","value":": Free color schemas. Also offers a Chrome extension."}]}]},{"type":"element","tagName":"h2","properties":{"id":"other"},"children":[{"type":"text","value":"Other"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://www.patterncooler.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"Pattern Cooler"}]}]}]},{"type":"text","value":": Free background patterns."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"http://thepatternlibrary.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"The Pattern Library"}]}]}]},{"type":"text","value":": Free background patterns."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://hatchful.shopify.com/","rel":["noopener","nofollow"]},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"hatchful"}]}]}]},{"type":"text","value":": Free logo generator."}]}]}],"data":{"quirksMode":false}},"tableOfContents":[{"id":"general","heading":"General"},{"id":"fonts","heading":"Fonts"},{"id":"icons","heading":"Icons"},{"id":"website-templates","heading":"Website Templates"},{"id":"illustrations","heading":"Illustrations"},{"id":"images","heading":"Images"},{"id":"gradients-and-colors","heading":"Gradients and Colors"},{"id":"other","heading":"Other"}]},"featureImageSharp":{"base":"photo-1505304451-3b3b85a91afe.jpg","publicURL":"/static/5b5b3cb18304a6e7b147980c13d0c5b3/photo-1505304451-3b3b85a91afe.jpg","imageMeta":{"width":2000,"height":1125},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAALABQDASIAAhEBAxEB/8QAFwAAAwEAAAAAAAAAAAAAAAAAAAMEAv/EABUBAQEAAAAAAAAAAAAAAAAAAAAB/9oADAMBAAIQAxAAAAFdUUwgwR//xAAbEAEAAgIDAAAAAAAAAAAAAAABAgMABBMiMf/aAAgBAQABBQLX7FsXJqTqsmPPasvf/8QAFREBAQAAAAAAAAAAAAAAAAAAEBH/2gAIAQMBAT8Bh//EABYRAAMAAAAAAAAAAAAAAAAAABARIf/aAAgBAgEBPwFwf//EABsQAQACAgMAAAAAAAAAAAAAAAEAAhEhEBIx/9oACAEBAAY/An0me9tRhUdRzd4//8QAGhAAAwEBAQEAAAAAAAAAAAAAAAERITFBUf/aAAgBAQABPyGW9r2xJGLH0paKO3fSKn5GiMDNu31n/9oADAMBAAIAAwAAABBv3//EABYRAAMAAAAAAAAAAAAAAAAAAAABIf/aAAgBAwEBPxCHRn//xAAWEQEBAQAAAAAAAAAAAAAAAAAAIQH/2gAIAQIBAT8QuGP/xAAdEAEAAwABBQAAAAAAAAAAAAABABEhMUFRYXGh/9oACAEBAAE/EKUdjLuR9lP3wg8Zce+b0WxhiG0Ngsg4MipLor1n/9k=","aspectRatio":1.7808219178082192,"src":"/static/5b5b3cb18304a6e7b147980c13d0c5b3/d5c54/photo-1505304451-3b3b85a91afe.jpg","srcSet":"/static/5b5b3cb18304a6e7b147980c13d0c5b3/65d8c/photo-1505304451-3b3b85a91afe.jpg 260w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/c5f21/photo-1505304451-3b3b85a91afe.jpg 520w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/d5c54/photo-1505304451-3b3b85a91afe.jpg 1040w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/81a53/photo-1505304451-3b3b85a91afe.jpg 1560w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/4e5f3/photo-1505304451-3b3b85a91afe.jpg 2000w","srcWebp":"/static/5b5b3cb18304a6e7b147980c13d0c5b3/e4875/photo-1505304451-3b3b85a91afe.webp","srcSetWebp":"/static/5b5b3cb18304a6e7b147980c13d0c5b3/dc8f3/photo-1505304451-3b3b85a91afe.webp 260w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/2db4b/photo-1505304451-3b3b85a91afe.webp 520w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/e4875/photo-1505304451-3b3b85a91afe.webp 1040w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/f5845/photo-1505304451-3b3b85a91afe.webp 1560w,\n/static/5b5b3cb18304a6e7b147980c13d0c5b3/49d6b/photo-1505304451-3b3b85a91afe.webp 2000w","sizes":"(max-width: 1040px) 100vw, 1040px"}}}},"prev":{"id":"Ghost__Post__6127ba1b3ed159214d382e6f","title":"Quran In New Tab - Chrome Extension","slug":"quran-in-new-tab-chrome-extension","featured":false,"feature_image":"https://res-5.cloudinary.com/hbqmf3mbz/image/upload/q_auto/v1/ghost-blog-images/quran.jpg","excerpt":"Replace the new tab page with Quran verses and beautiful nature pictures. The verses and pictures are randomly generated hourly.","custom_excerpt":"Replace the new tab page with Quran verses and beautiful nature pictures. The verses and pictures are randomly generated hourly.","visibility":"public","created_at_pretty":"26 Oct 2020","published_at_pretty":"6 Nov 2019","updated_at_pretty":"26 Aug 2021","created_at":"2020-10-26T21:42:23.000+00:00","published_at":"2019-11-06T18:23:00.000+00:00","updated_at":"2021-08-26T17:54:06.000+00:00","meta_title":null,"meta_description":null,"og_description":null,"og_image":null,"og_title":null,"twitter_description":null,"twitter_image":null,"twitter_title":null,"authors":[{"slug":"shahed","url":"https://backend.shahednasser.com/author/shahed/","name":"Shahed Nasser","bio":null,"cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/03/IMG_0591.jpg","location":null,"website":null,"twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":null}],"primary_author":{"slug":"shahed","url":"https://backend.shahednasser.com/author/shahed/","name":"Shahed Nasser","bio":null,"cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/03/IMG_0591.jpg","location":null,"website":null,"twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":{"base":"IMG_0591.jpg","publicURL":"/static/ceb49c3c631485453e71e00d7f84b069/IMG_0591.jpg","imageMeta":{"width":1182,"height":1179},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAUABQDASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAMEAQL/xAAWAQEBAQAAAAAAAAAAAAAAAAADBAL/2gAMAwEAAhADEAAAAdXiFM6i0CohUWXoKn//xAAcEAACAgIDAAAAAAAAAAAAAAACAwESBBEhM0H/2gAIAQEAAQUCWySE3WEr7SzbXjAj4iKty+sOQ//EABYRAQEBAAAAAAAAAAAAAAAAAAERIP/aAAgBAwEBPwEhj//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8BH//EAB4QAAIBBAMBAAAAAAAAAAAAAAABIRESMUECECJx/9oACAEBAAY/ApVGWvOjzgtUwLlTZA0sdL4f/8QAHBAAAwACAwEAAAAAAAAAAAAAAAERITFBkbHB/9oACAEBAAE/IahkCy+N2GwZpjQiJHJCspUFY0QrSi+HqiW2rgf/2gAMAwEAAgADAAAAEPw3/wD/xAAYEQEBAAMAAAAAAAAAAAAAAAAAARExQf/aAAgBAwEBPxCtjDqP/8QAFxEBAQEBAAAAAAAAAAAAAAAAAQAxEf/aAAgBAgEBPxBFus6Tt//EAB8QAQEAAgIBBQAAAAAAAAAAAAERACExQWFRcYGR0f/aAAgBAQABPxAuaBPPzkO1wyX7F4wkwXanfZrFQgeqE9JgS14vVOvrERIJomVBKwt2jebAeP0yVa8h1n//2Q==","aspectRatio":1,"src":"/static/ceb49c3c631485453e71e00d7f84b069/31709/IMG_0591.jpg","srcSet":"/static/ceb49c3c631485453e71e00d7f84b069/f340b/IMG_0591.jpg 28w,\n/static/ceb49c3c631485453e71e00d7f84b069/22d64/IMG_0591.jpg 55w,\n/static/ceb49c3c631485453e71e00d7f84b069/31709/IMG_0591.jpg 110w,\n/static/ceb49c3c631485453e71e00d7f84b069/aa249/IMG_0591.jpg 165w,\n/static/ceb49c3c631485453e71e00d7f84b069/0dc33/IMG_0591.jpg 220w,\n/static/ceb49c3c631485453e71e00d7f84b069/d8257/IMG_0591.jpg 1182w","srcWebp":"/static/ceb49c3c631485453e71e00d7f84b069/8678c/IMG_0591.webp","srcSetWebp":"/static/ceb49c3c631485453e71e00d7f84b069/59cda/IMG_0591.webp 28w,\n/static/ceb49c3c631485453e71e00d7f84b069/7da75/IMG_0591.webp 55w,\n/static/ceb49c3c631485453e71e00d7f84b069/8678c/IMG_0591.webp 110w,\n/static/ceb49c3c631485453e71e00d7f84b069/f282e/IMG_0591.webp 165w,\n/static/ceb49c3c631485453e71e00d7f84b069/a7b21/IMG_0591.webp 220w,\n/static/ceb49c3c631485453e71e00d7f84b069/63099/IMG_0591.webp 1182w","sizes":"(max-width: 110px) 100vw, 110px"}}}},"primary_tag":{"slug":"projects","url":"https://backend.shahednasser.com/tag/projects/","name":"Projects","visibility":"public","feature_image":null,"description":null,"meta_title":null,"meta_description":null,"featureImageSharp":null},"tags":[{"slug":"projects","url":"https://backend.shahednasser.com/tag/projects/","name":"Projects","visibility":"public","feature_image":null,"description":null,"meta_title":null,"meta_description":null,"featureImageSharp":null}],"plaintext":" * Download Now\n   [https://chrome.google.com/webstore/detail/quran-in-new-tab/hggkcijghhpkdjeokpfgbhnpecliiijg?hl=en]\n\nReplace the new tab page with Quran verses and beautiful nature pictures. The\nverses and pictures are randomly generated hourly. You can choose to show or\nhide your top sites.\n\nNEW I am working on adding more languages to this extension, and I need help\nwith many of them. If you think you can help in translating it, please go here\n[https://crowdin.com/project/quran-in-new-tab-extension] to start helping!\n\n\n--------------------------------------------------------------------------------\n\nRecitations\nYou can play an audio of the recitation of the verse shown. You can choose from\nthe following reciters:\n\n * Mashary Rashid Alafasy\n * Abdallah Basfar\n * Abdurrahmaan As-Sudais\n * Abdul Samad\n\nand many more.\n\n\n--------------------------------------------------------------------------------\n\nTranslations\nYou can turn on the translation for the verses. Some of the languages available\nfor translations are:\n\n * English\n * German\n * Spanish\n * Indonesian\n * Italian\n\nand many more.\n\n\n--------------------------------------------------------------------------------\n\nAthkar\nStarting from version 1.0, you can show randomly generated Athkar on your new\ntab as well.\n\n\n--------------------------------------------------------------------------------\n\nCredits\nAll Quran verses, audios and translations use the API of Al Quran Cloud\nIcons from Feather\nLogo from https://www.freeiconspng.com/img/8824\n\n\n\n--------------------------------------------------------------------------------\n\nIssues\nIf you find any issues or bugs, please create an issue on the Github Repo\n[https://github.com/shahednasser/quran-extension].","html":"<!--kg-card-begin: html--><ul class=\"actions special\">\n                    <li><a href=\"https://chrome.google.com/webstore/detail/quran-in-new-tab/hggkcijghhpkdjeokpfgbhnpecliiijg?hl=en\" class=\"button large\">Download Now</a></li>\n                </ul><!--kg-card-end: html--><p>Replace the new tab page with Quran verses and beautiful nature pictures. The verses and pictures are randomly generated hourly. You can choose to show or hide your top sites.</p><p><strong>NEW </strong>I am working on adding more languages to this extension, and I need help with many of them. If you think you can help in translating it, please go <a href=\"https://crowdin.com/project/quran-in-new-tab-extension\">here</a> to start helping!</p><hr><h2 id=\"recitations\">Recitations</h2><p>You can play an audio of the recitation of the verse shown. You can choose from the following reciters:</p><ul><li>Mashary Rashid Alafasy</li><li>Abdallah Basfar</li><li>Abdurrahmaan As-Sudais</li><li>Abdul Samad</li></ul><p>and many more.</p><hr><h2 id=\"translations\">Translations</h2><p>You can turn on the translation for the verses. Some of the languages available for translations are:</p><ul><li>English</li><li>German</li><li>Spanish</li><li>Indonesian</li><li>Italian</li></ul><p>and many more.</p><hr><h2 id=\"athkar\">Athkar</h2><p>Starting from version 1.0, you can show randomly generated Athkar on your new tab as well.</p><hr><h2 id=\"credits\">Credits</h2><p>All Quran verses, audios and translations use the API of Al Quran Cloud<br>Icons from Feather<br>Logo from <a href=\"https://www.freeiconspng.com/img/8824\">https://www.freeiconspng.com/img/8824</a><br></p><hr><h2 id=\"issues\">Issues</h2><p>If you find any issues or bugs, please create an issue on the <a href=\"https://github.com/shahednasser/quran-extension\">Github Repo</a>.</p>","url":"https://backend.shahednasser.com/quran-in-new-tab-chrome-extension/","canonical_url":"https://shahednasserblog.tk/quran-in-new-tab-chrome-extension","uuid":"6cb8f7dc-9ccd-4e56-b4ad-d8e72803f26f","codeinjection_foot":null,"codeinjection_head":null,"codeinjection_styles":null,"comment_id":"5f9742bfb366d4001e86ccb9","reading_time":1,"send_email_when_published":null,"email_subject":null,"childHtmlRehype":{"html":"<!--kg-card-begin: html--><ul class=\"actions special\">\n                    <li><a href=\"https://chrome.google.com/webstore/detail/quran-in-new-tab/hggkcijghhpkdjeokpfgbhnpecliiijg?hl=en\" class=\"button large\">Download Now</a></li>\n                </ul><!--kg-card-end: html--><p>Replace the new tab page with Quran verses and beautiful nature pictures. The verses and pictures are randomly generated hourly. You can choose to show or hide your top sites.</p><p><strong>NEW </strong>I am working on adding more languages to this extension, and I need help with many of them. If you think you can help in translating it, please go <a href=\"https://crowdin.com/project/quran-in-new-tab-extension\">here</a> to start helping!</p><hr><h2 id=\"recitations\">Recitations</h2><p>You can play an audio of the recitation of the verse shown. You can choose from the following reciters:</p><ul><li>Mashary Rashid Alafasy</li><li>Abdallah Basfar</li><li>Abdurrahmaan As-Sudais</li><li>Abdul Samad</li></ul><p>and many more.</p><hr><h2 id=\"translations\">Translations</h2><p>You can turn on the translation for the verses. Some of the languages available for translations are:</p><ul><li>English</li><li>German</li><li>Spanish</li><li>Indonesian</li><li>Italian</li></ul><p>and many more.</p><hr><h2 id=\"athkar\">Athkar</h2><p>Starting from version 1.0, you can show randomly generated Athkar on your new tab as well.</p><hr><h2 id=\"credits\">Credits</h2><p>All Quran verses, audios and translations use the API of Al Quran Cloud<br>Icons from Feather<br>Logo from <a href=\"https://www.freeiconspng.com/img/8824\">https://www.freeiconspng.com/img/8824</a><br></p><hr><h2 id=\"issues\">Issues</h2><p>If you find any issues or bugs, please create an issue on the <a href=\"https://github.com/shahednasser/quran-extension\">Github Repo</a>.</p>","htmlAst":{"type":"root","children":[{"type":"comment","value":"kg-card-begin: html"},{"type":"element","tagName":"ul","properties":{"className":["actions","special"]},"children":[{"type":"text","value":"\n                    "},{"type":"element","tagName":"li","properties":{},"children":[{"type":"element","tagName":"a","properties":{"href":"https://chrome.google.com/webstore/detail/quran-in-new-tab/hggkcijghhpkdjeokpfgbhnpecliiijg?hl=en","className":["button","large"]},"children":[{"type":"text","value":"Download Now"}]}]},{"type":"text","value":"\n                "}]},{"type":"comment","value":"kg-card-end: html"},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Replace the new tab page with Quran verses and beautiful nature pictures. The verses and pictures are randomly generated hourly. You can choose to show or hide your top sites."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"NEW "}]},{"type":"text","value":"I am working on adding more languages to this extension, and I need help with many of them. If you think you can help in translating it, please go "},{"type":"element","tagName":"a","properties":{"href":"https://crowdin.com/project/quran-in-new-tab-extension"},"children":[{"type":"text","value":"here"}]},{"type":"text","value":" to start helping!"}]},{"type":"element","tagName":"hr","properties":{},"children":[]},{"type":"element","tagName":"h2","properties":{"id":"recitations"},"children":[{"type":"text","value":"Recitations"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can play an audio of the recitation of the verse shown. You can choose from the following reciters:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Mashary Rashid Alafasy"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Abdallah Basfar"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Abdurrahmaan As-Sudais"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Abdul Samad"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"and many more."}]},{"type":"element","tagName":"hr","properties":{},"children":[]},{"type":"element","tagName":"h2","properties":{"id":"translations"},"children":[{"type":"text","value":"Translations"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can turn on the translation for the verses. Some of the languages available for translations are:"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"English"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"German"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Spanish"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Indonesian"}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"Italian"}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"and many more."}]},{"type":"element","tagName":"hr","properties":{},"children":[]},{"type":"element","tagName":"h2","properties":{"id":"athkar"},"children":[{"type":"text","value":"Athkar"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Starting from version 1.0, you can show randomly generated Athkar on your new tab as well."}]},{"type":"element","tagName":"hr","properties":{},"children":[]},{"type":"element","tagName":"h2","properties":{"id":"credits"},"children":[{"type":"text","value":"Credits"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"All Quran verses, audios and translations use the API of Al Quran Cloud"},{"type":"element","tagName":"br","properties":{},"children":[]},{"type":"text","value":"Icons from Feather"},{"type":"element","tagName":"br","properties":{},"children":[]},{"type":"text","value":"Logo from "},{"type":"element","tagName":"a","properties":{"href":"https://www.freeiconspng.com/img/8824"},"children":[{"type":"text","value":"https://www.freeiconspng.com/img/8824"}]},{"type":"element","tagName":"br","properties":{},"children":[]}]},{"type":"element","tagName":"hr","properties":{},"children":[]},{"type":"element","tagName":"h2","properties":{"id":"issues"},"children":[{"type":"text","value":"Issues"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If you find any issues or bugs, please create an issue on the "},{"type":"element","tagName":"a","properties":{"href":"https://github.com/shahednasser/quran-extension"},"children":[{"type":"text","value":"Github Repo"}]},{"type":"text","value":"."}]}],"data":{"quirksMode":false}},"tableOfContents":[{"id":"recitations","heading":"Recitations"},{"id":"translations","heading":"Translations"},{"id":"athkar","heading":"Athkar"},{"id":"credits","heading":"Credits"},{"id":"issues","heading":"Issues"}]},"featureImageSharp":{"base":"quran.jpg","publicURL":"/static/34fbf15a86a81d576af29f787f7f9f04/quran.jpg","imageMeta":{"width":2000,"height":2000},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAUABQDASIAAhEBAxEB/8QAGQABAAMBAQAAAAAAAAAAAAAAAAECBAUD/8QAFwEAAwEAAAAAAAAAAAAAAAAAAAECA//aAAwDAQACEAMQAAABiPXZL4zqApQRnGk//8QAHBAAAgICAwAAAAAAAAAAAAAAAQIAAxESBCEi/9oACAEBAAEFAkZwqrYjCm0zjuWm65OSUrTVfQsHf//EABYRAAMAAAAAAAAAAAAAAAAAAAAQIf/aAAgBAwEBPwEj/8QAFhEBAQEAAAAAAAAAAAAAAAAAAAER/9oACAECAQE/AW1Uf//EABwQAAICAgMAAAAAAAAAAAAAAAABAhESISIxYf/aAAgBAQAGPwLGMHRxizo3R2i+Rko0/BaW0L1H/8QAGxABAAMAAwEAAAAAAAAAAAAAAQARITFhcZH/2gAIAQEAAT8hygnk5jjKt0hLFKb5DAWCu5Qr+0ChjpJSEaEXj1wh2imlXP/aAAwDAQACAAMAAAAQyy//AP/EABcRAQEBAQAAAAAAAAAAAAAAAAABETH/2gAIAQMBAT8QtYRev//EABgRAAIDAAAAAAAAAAAAAAAAAABRARAx/9oACAECAQE/EGKpiD//xAAdEAEAAwEAAgMAAAAAAAAAAAABABEhMUFRkaHR/9oACAEBAAE/EDnmh4F6kWROD1erfyWmXdi4b3JaDDzquW+eysWzpSybIjlo+4wwatkOOa8ybdone77bBUbUMDaZ8T//2Q==","aspectRatio":1,"src":"/static/34fbf15a86a81d576af29f787f7f9f04/ea4ab/quran.jpg","srcSet":"/static/34fbf15a86a81d576af29f787f7f9f04/477ba/quran.jpg 175w,\n/static/34fbf15a86a81d576af29f787f7f9f04/06776/quran.jpg 350w,\n/static/34fbf15a86a81d576af29f787f7f9f04/ea4ab/quran.jpg 700w,\n/static/34fbf15a86a81d576af29f787f7f9f04/3055e/quran.jpg 1050w,\n/static/34fbf15a86a81d576af29f787f7f9f04/eff08/quran.jpg 1400w,\n/static/34fbf15a86a81d576af29f787f7f9f04/4e5f3/quran.jpg 2000w","srcWebp":"/static/34fbf15a86a81d576af29f787f7f9f04/89afa/quran.webp","srcSetWebp":"/static/34fbf15a86a81d576af29f787f7f9f04/9fca7/quran.webp 175w,\n/static/34fbf15a86a81d576af29f787f7f9f04/37a4e/quran.webp 350w,\n/static/34fbf15a86a81d576af29f787f7f9f04/89afa/quran.webp 700w,\n/static/34fbf15a86a81d576af29f787f7f9f04/78e7a/quran.webp 1050w,\n/static/34fbf15a86a81d576af29f787f7f9f04/03d34/quran.webp 1400w,\n/static/34fbf15a86a81d576af29f787f7f9f04/49d6b/quran.webp 2000w","sizes":"(max-width: 700px) 100vw, 700px"}}}},"next":{"id":"Ghost__Post__6127ba1b3ed159214d382e6c","title":"CSS Variables and How To Use Them","slug":"css-variables-and-how-to-use-them","featured":false,"feature_image":"https://res-2.cloudinary.com/hbqmf3mbz/image/upload/q_auto/v1/ghost-blog-images/carbon--1-.png","excerpt":"A lot of people don’t know about CSS variables, and you might be one of them! It’s time to learn about CSS variables and how you can use them.","custom_excerpt":"A lot of people don’t know about CSS variables, and you might be one of them! It’s time to learn about CSS variables and how you can use them.","visibility":"public","created_at_pretty":"26 Oct 2020","published_at_pretty":"21 Apr 2019","updated_at_pretty":"26 Aug 2021","created_at":"2020-10-26T21:28:48.000+00:00","published_at":"2019-04-21T21:28:00.000+00:00","updated_at":"2021-08-26T17:54:30.000+00:00","meta_title":null,"meta_description":null,"og_description":null,"og_image":null,"og_title":null,"twitter_description":null,"twitter_image":null,"twitter_title":null,"authors":[{"slug":"shahed","url":"https://backend.shahednasser.com/author/shahed/","name":"Shahed Nasser","bio":null,"cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/03/IMG_0591.jpg","location":null,"website":null,"twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":null}],"primary_author":{"slug":"shahed","url":"https://backend.shahednasser.com/author/shahed/","name":"Shahed Nasser","bio":null,"cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/03/IMG_0591.jpg","location":null,"website":null,"twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":{"base":"IMG_0591.jpg","publicURL":"/static/ceb49c3c631485453e71e00d7f84b069/IMG_0591.jpg","imageMeta":{"width":1182,"height":1179},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAUABQDASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAMEAQL/xAAWAQEBAQAAAAAAAAAAAAAAAAADBAL/2gAMAwEAAhADEAAAAdXiFM6i0CohUWXoKn//xAAcEAACAgIDAAAAAAAAAAAAAAACAwESBBEhM0H/2gAIAQEAAQUCWySE3WEr7SzbXjAj4iKty+sOQ//EABYRAQEBAAAAAAAAAAAAAAAAAAERIP/aAAgBAwEBPwEhj//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8BH//EAB4QAAIBBAMBAAAAAAAAAAAAAAABIRESMUECECJx/9oACAEBAAY/ApVGWvOjzgtUwLlTZA0sdL4f/8QAHBAAAwACAwEAAAAAAAAAAAAAAAERITFBkbHB/9oACAEBAAE/IahkCy+N2GwZpjQiJHJCspUFY0QrSi+HqiW2rgf/2gAMAwEAAgADAAAAEPw3/wD/xAAYEQEBAAMAAAAAAAAAAAAAAAAAARExQf/aAAgBAwEBPxCtjDqP/8QAFxEBAQEBAAAAAAAAAAAAAAAAAQAxEf/aAAgBAgEBPxBFus6Tt//EAB8QAQEAAgIBBQAAAAAAAAAAAAERACExQWFRcYGR0f/aAAgBAQABPxAuaBPPzkO1wyX7F4wkwXanfZrFQgeqE9JgS14vVOvrERIJomVBKwt2jebAeP0yVa8h1n//2Q==","aspectRatio":1,"src":"/static/ceb49c3c631485453e71e00d7f84b069/31709/IMG_0591.jpg","srcSet":"/static/ceb49c3c631485453e71e00d7f84b069/f340b/IMG_0591.jpg 28w,\n/static/ceb49c3c631485453e71e00d7f84b069/22d64/IMG_0591.jpg 55w,\n/static/ceb49c3c631485453e71e00d7f84b069/31709/IMG_0591.jpg 110w,\n/static/ceb49c3c631485453e71e00d7f84b069/aa249/IMG_0591.jpg 165w,\n/static/ceb49c3c631485453e71e00d7f84b069/0dc33/IMG_0591.jpg 220w,\n/static/ceb49c3c631485453e71e00d7f84b069/d8257/IMG_0591.jpg 1182w","srcWebp":"/static/ceb49c3c631485453e71e00d7f84b069/8678c/IMG_0591.webp","srcSetWebp":"/static/ceb49c3c631485453e71e00d7f84b069/59cda/IMG_0591.webp 28w,\n/static/ceb49c3c631485453e71e00d7f84b069/7da75/IMG_0591.webp 55w,\n/static/ceb49c3c631485453e71e00d7f84b069/8678c/IMG_0591.webp 110w,\n/static/ceb49c3c631485453e71e00d7f84b069/f282e/IMG_0591.webp 165w,\n/static/ceb49c3c631485453e71e00d7f84b069/a7b21/IMG_0591.webp 220w,\n/static/ceb49c3c631485453e71e00d7f84b069/63099/IMG_0591.webp 1182w","sizes":"(max-width: 110px) 100vw, 110px"}}}},"primary_tag":{"slug":"css","url":"https://backend.shahednasser.com/tag/css/","name":"CSS","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1610986603166-f78428624e76-2.jpeg","description":"Learn more about CSS through tutorials, articles, and tips.","meta_title":null,"meta_description":null,"featureImageSharp":{"base":"photo-1610986603166-f78428624e76-2.jpeg","publicURL":"/static/2e4062ead6b64acea03c5c5ba3437c96/photo-1610986603166-f78428624e76-2.jpeg","imageMeta":{"width":2000,"height":1352},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAOABQDASIAAhEBAxEB/8QAGAAAAgMAAAAAAAAAAAAAAAAAAAIBAwX/xAAVAQEBAAAAAAAAAAAAAAAAAAAAAf/aAAwDAQACEAMQAAABymIKxiv/xAAaEAACAgMAAAAAAAAAAAAAAAAAEQECEBIh/9oACAEBAAEFAqolalUcx//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8BP//EABURAQEAAAAAAAAAAAAAAAAAAAAR/9oACAECAQE/AUf/xAAZEAACAwEAAAAAAAAAAAAAAAAQIQABEYH/2gAIAQEABj8CcVd0M//EABsQAAIDAAMAAAAAAAAAAAAAAAABESExEFGB/9oACAEBAAE/IdKGJM+nDWSDSdkH/9oADAMBAAIAAwAAABCL7//EABQRAQAAAAAAAAAAAAAAAAAAABD/2gAIAQMBAT8QP//EABURAQEAAAAAAAAAAAAAAAAAAAEQ/9oACAECAQE/EAY//8QAGhABAQADAQEAAAAAAAAAAAAAAREAITEQYf/aAAgBAQABPxAsEuSsxwBHaV8nMjhCkPIbwwjTs8f/2Q==","aspectRatio":1.4772727272727273,"src":"/static/2e4062ead6b64acea03c5c5ba3437c96/d5c54/photo-1610986603166-f78428624e76-2.jpg","srcSet":"/static/2e4062ead6b64acea03c5c5ba3437c96/65d8c/photo-1610986603166-f78428624e76-2.jpg 260w,\n/static/2e4062ead6b64acea03c5c5ba3437c96/c5f21/photo-1610986603166-f78428624e76-2.jpg 520w,\n/static/2e4062ead6b64acea03c5c5ba3437c96/d5c54/photo-1610986603166-f78428624e76-2.jpg 1040w,\n/static/2e4062ead6b64acea03c5c5ba3437c96/81a53/photo-1610986603166-f78428624e76-2.jpg 1560w,\n/static/2e4062ead6b64acea03c5c5ba3437c96/4e5f3/photo-1610986603166-f78428624e76-2.jpg 2000w","srcWebp":"/static/2e4062ead6b64acea03c5c5ba3437c96/e4875/photo-1610986603166-f78428624e76-2.webp","srcSetWebp":"/static/2e4062ead6b64acea03c5c5ba3437c96/dc8f3/photo-1610986603166-f78428624e76-2.webp 260w,\n/static/2e4062ead6b64acea03c5c5ba3437c96/2db4b/photo-1610986603166-f78428624e76-2.webp 520w,\n/static/2e4062ead6b64acea03c5c5ba3437c96/e4875/photo-1610986603166-f78428624e76-2.webp 1040w,\n/static/2e4062ead6b64acea03c5c5ba3437c96/f5845/photo-1610986603166-f78428624e76-2.webp 1560w,\n/static/2e4062ead6b64acea03c5c5ba3437c96/49d6b/photo-1610986603166-f78428624e76-2.webp 2000w","sizes":"(max-width: 1040px) 100vw, 1040px"}}}},"tags":[{"slug":"css","url":"https://backend.shahednasser.com/tag/css/","name":"CSS","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1610986603166-f78428624e76-2.jpeg","description":"Learn more about CSS through tutorials, articles, and tips.","meta_title":null,"meta_description":null,"featureImageSharp":null},{"slug":"beginner","url":"https://backend.shahednasser.com/tag/beginner/","name":"Beginners","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1521185496955-15097b20c5fe-2.jpeg","description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","meta_title":"Beginners","meta_description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","featureImageSharp":null},{"slug":"tips","url":"https://backend.shahednasser.com/tag/tips/","name":"Tips","visibility":"public","feature_image":null,"description":"Learn more about programming and development through these articles that have essential tips!","meta_title":"Tips on Technology and Programming","meta_description":null,"featureImageSharp":null}],"plaintext":"A lot of people don’t know about CSS variables, and you might be one of them!\nIt’s time to learn about CSS variables and how you can use them.\n\nCSS variables are declared for a specific element as a custom property. Then,\nyou can use that custom property anywhere you use that element.\n\n\n--------------------------------------------------------------------------------\n\nDeclaration and Usage\nHere’s how you declare a custom property:\n\nelement { \n\t--background-color: #f00;\n}\n\nHere, element can be a selector of any element, for example, div, p, .test, etc…\n\nWhat we did is that we declared a custom property for this element called \n--background-color . All CSS custom properties must start with -- .\n\nNow, we can use this custom property inside element using the var function.\n\nelement {  \n\tbackground-color: var(--background-color);\n}\n\nHere, we assigned the background-color property of element to the variable we\ndeclared earlier.\n\nThis is nice and all, but usually we have repetition inside different elements,\nnot just one. declaring a custom variable inside one element type is not very\nconvenient.\n\nIn order to use a custom property inside more than one element type, we can\ndeclare the custom property inside the :root pseudo-class.\n\n:root {  \n\t--primary-color: #333;\n}\n\nNow, we can use the variable --primary-color inside any element in our document:\n\ndiv {  \n\tcolor: var(--primary-color);\n}\np {  \n\tbackground-color: var(--primary-color);\n}\n.fancy {  \n\tborder-color: var(--primary-color);\n}\n\nBy declaring our custom property inside :root , we are now able to use it inside \ndiv to set the text color, p to set the background color, and any element having\nclass fancy to set the border color. This way, not only did we minimize\nrepetition, but we also made it easier to edit and change our website’s primary\ncolor at any given point.\n\n\n--------------------------------------------------------------------------------\n\nInheritance\nElements can also inherit custom properties. For example, let’s say we have the\nfollowing HTML:\n\n<div class=\"parent\">\n\t<div class=\"first-child\"></div>  \n    <div class=\"second-child\"><div>\n</div>\n\nThen, we declare a variable called --text-size on .parent :\n\n.parent {  \n\t--text-size: 15px;\n}\n\nNow, we can use --text-size not only inside .parent , but also inside its\nchildren as well:\n\n.first-child {\n    font-size: var(--text-size);\n}\n\nWe can also override custom properties. We can do that by redeclaring the custom\nproperty inside the child element:\n\n.second-child {  \n\t--text-size: 30px;\n}\n\nNow, if you use --text-size inside .second-child , it’ll be evaluated to 30px,\nbut if you use it inside .first-child or .parent, it will still be 15px.\n\n\n--------------------------------------------------------------------------------\n\nFallback Values\nYou can also define a fallback value for a variable by passing a second\nparameter to var . For example:\n\n.second-child {  \n\tfont-size: var(--text-size, 30px);\n}\n\nFallback values are used when the variable is not defined yet. They are not used\nas a fallback to browser incompatibility.\n\n\n--------------------------------------------------------------------------------\n\nConclusion\nAnd that’s how you can use CSS variables! Keep in mind that some browsers like\nInternet Explorer don’t support them, so if you need to support all browsers you\nneed to take that into consideration.","html":"<p>A lot of people don’t know about CSS variables, and you might be one of them! It’s time to learn about CSS variables and how you can use them.</p><p>CSS variables are declared for a specific element as a custom property. Then, you can use that custom property anywhere you use that element.</p><hr><h1 id=\"declaration-and-usage\">Declaration and Usage</h1><p>Here’s how you declare a custom property:</p><pre><code class=\"language-css\">element { \n\t--background-color: #f00;\n}</code></pre><p>Here, <code>element</code> can be a selector of any element, for example, div, p, .test, etc…</p><p>What we did is that we declared a custom property for this element called <code>--background-color</code> . All CSS custom properties must start with <code>--</code> .</p><p>Now, we can use this custom property inside <code>element</code> using the <code>var</code> function.</p><pre><code class=\"language-css\">element {  \n\tbackground-color: var(--background-color);\n}</code></pre><p>Here, we assigned the background-color property of <code>element</code> to the variable we declared earlier.</p><p>This is nice and all, but usually we have repetition inside different elements, not just one. declaring a custom variable inside one element type is not very convenient.</p><p>In order to use a custom property inside more than one element type, we can declare the custom property inside the <code>:root</code> pseudo-class.</p><pre><code class=\"language-css\">:root {  \n\t--primary-color: #333;\n}</code></pre><p>Now, we can use the variable <code>--primary-color</code> inside any element in our document:</p><pre><code class=\"language-css\">div {  \n\tcolor: var(--primary-color);\n}\np {  \n\tbackground-color: var(--primary-color);\n}\n.fancy {  \n\tborder-color: var(--primary-color);\n}</code></pre><p>By declaring our custom property inside <code>:root</code> , we are now able to use it inside <code>div</code> to set the text color, <code>p</code> to set the background color, and any element having class <code>fancy</code> to set the border color. This way, not only did we minimize repetition, but we also made it easier to edit and change our website’s primary color at any given point.</p><hr><h1 id=\"inheritance\">Inheritance</h1><p>Elements can also inherit custom properties. For example, let’s say we have the following HTML:</p><pre><code class=\"language-html\">&lt;div class=\"parent\"&gt;\n\t&lt;div class=\"first-child\"&gt;&lt;/div&gt;  \n    &lt;div class=\"second-child\"&gt;&lt;div&gt;\n&lt;/div&gt;</code></pre><p>Then, we declare a variable called <code>--text-size</code> on <code>.parent</code> :</p><pre><code class=\"language-css\">.parent {  \n\t--text-size: 15px;\n}</code></pre><p>Now, we can use <code>--text-size</code> not only inside <code>.parent</code> , but also inside its children as well:</p><pre><code class=\"language-css\">.first-child {\n    font-size: var(--text-size);\n}</code></pre><p>We can also override custom properties. We can do that by redeclaring the custom property inside the child element:</p><pre><code class=\"language-css\">.second-child {  \n\t--text-size: 30px;\n}</code></pre><p>Now, if you use <code>--text-size</code> inside <code>.second-child</code> , it’ll be evaluated to 30px, but if you use it inside <code>.first-child</code> or <code>.parent</code>, it will still be 15px.</p><hr><h1 id=\"fallback-values\">Fallback Values</h1><p>You can also define a fallback value for a variable by passing a second parameter to <code>var</code> . For example:</p><pre><code class=\"language-css\">.second-child {  \n\tfont-size: var(--text-size, 30px);\n}</code></pre><p>Fallback values are used when the variable is not defined yet. They are <strong><strong><em><em>not</em></em></strong></strong> used as a fallback to browser incompatibility.</p><hr><h1 id=\"conclusion\">Conclusion</h1><p>And that’s how you can use CSS variables! Keep in mind that some browsers like Internet Explorer don’t support them, so if you need to support all browsers you need to take that into consideration.</p>","url":"https://backend.shahednasser.com/css-variables-and-how-to-use-them/","canonical_url":null,"uuid":"294be2c5-8cd6-41a1-94b5-28838e34c151","codeinjection_foot":null,"codeinjection_head":null,"codeinjection_styles":null,"comment_id":"5f973f90b366d4001e86cc54","reading_time":2,"send_email_when_published":null,"email_subject":null,"childHtmlRehype":{"html":"<p>A lot of people don’t know about CSS variables, and you might be one of them! It’s time to learn about CSS variables and how you can use them.</p><p>CSS variables are declared for a specific element as a custom property. Then, you can use that custom property anywhere you use that element.</p><hr><h1 id=\"declaration-and-usage\">Declaration and Usage</h1><p>Here’s how you declare a custom property:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">element</span> <span class=\"token punctuation\">{</span> \n\t<span class=\"token property\">--background-color</span><span class=\"token punctuation\">:</span> #f00<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><p>Here, <code class=\"language-text\">element</code> can be a selector of any element, for example, div, p, .test, etc…</p><p>What we did is that we declared a custom property for this element called <code class=\"language-text\">--background-color</code> . All CSS custom properties must start with <code class=\"language-text\">--</code> .</p><p>Now, we can use this custom property inside <code class=\"language-text\">element</code> using the <code class=\"language-text\">var</code> function.</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">element</span> <span class=\"token punctuation\">{</span>  \n\t<span class=\"token property\">background-color</span><span class=\"token punctuation\">:</span> <span class=\"token function\">var</span><span class=\"token punctuation\">(</span>--background-color<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><p>Here, we assigned the background-color property of <code class=\"language-text\">element</code> to the variable we declared earlier.</p><p>This is nice and all, but usually we have repetition inside different elements, not just one. declaring a custom variable inside one element type is not very convenient.</p><p>In order to use a custom property inside more than one element type, we can declare the custom property inside the <code class=\"language-text\">:root</code> pseudo-class.</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">:root</span> <span class=\"token punctuation\">{</span>  \n\t<span class=\"token property\">--primary-color</span><span class=\"token punctuation\">:</span> #333<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><p>Now, we can use the variable <code class=\"language-text\">--primary-color</code> inside any element in our document:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">div</span> <span class=\"token punctuation\">{</span>  \n\t<span class=\"token property\">color</span><span class=\"token punctuation\">:</span> <span class=\"token function\">var</span><span class=\"token punctuation\">(</span>--primary-color<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token selector\">p</span> <span class=\"token punctuation\">{</span>  \n\t<span class=\"token property\">background-color</span><span class=\"token punctuation\">:</span> <span class=\"token function\">var</span><span class=\"token punctuation\">(</span>--primary-color<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n<span class=\"token selector\">.fancy</span> <span class=\"token punctuation\">{</span>  \n\t<span class=\"token property\">border-color</span><span class=\"token punctuation\">:</span> <span class=\"token function\">var</span><span class=\"token punctuation\">(</span>--primary-color<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><p>By declaring our custom property inside <code class=\"language-text\">:root</code> , we are now able to use it inside <code class=\"language-text\">div</code> to set the text color, <code class=\"language-text\">p</code> to set the background color, and any element having class <code class=\"language-text\">fancy</code> to set the border color. This way, not only did we minimize repetition, but we also made it easier to edit and change our website’s primary color at any given point.</p><hr><h1 id=\"inheritance\">Inheritance</h1><p>Elements can also inherit custom properties. For example, let’s say we have the following HTML:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"html\"><pre class=\"language-html\"><code class=\"language-html\"><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&#x3C;</span>div</span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>parent<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span>\n\t<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&#x3C;</span>div</span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>first-child<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&#x3C;/</span>div</span><span class=\"token punctuation\">></span></span>  \n    <span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&#x3C;</span>div</span> <span class=\"token attr-name\">class</span><span class=\"token attr-value\"><span class=\"token punctuation attr-equals\">=</span><span class=\"token punctuation\">\"</span>second-child<span class=\"token punctuation\">\"</span></span><span class=\"token punctuation\">></span></span><span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&#x3C;</span>div</span><span class=\"token punctuation\">></span></span>\n<span class=\"token tag\"><span class=\"token tag\"><span class=\"token punctuation\">&#x3C;/</span>div</span><span class=\"token punctuation\">></span></span></code></pre></div><p>Then, we declare a variable called <code class=\"language-text\">--text-size</code> on <code class=\"language-text\">.parent</code> :</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.parent</span> <span class=\"token punctuation\">{</span>  \n\t<span class=\"token property\">--text-size</span><span class=\"token punctuation\">:</span> 15px<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><p>Now, we can use <code class=\"language-text\">--text-size</code> not only inside <code class=\"language-text\">.parent</code> , but also inside its children as well:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.first-child</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token property\">font-size</span><span class=\"token punctuation\">:</span> <span class=\"token function\">var</span><span class=\"token punctuation\">(</span>--text-size<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><p>We can also override custom properties. We can do that by redeclaring the custom property inside the child element:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.second-child</span> <span class=\"token punctuation\">{</span>  \n\t<span class=\"token property\">--text-size</span><span class=\"token punctuation\">:</span> 30px<span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><p>Now, if you use <code class=\"language-text\">--text-size</code> inside <code class=\"language-text\">.second-child</code> , it’ll be evaluated to 30px, but if you use it inside <code class=\"language-text\">.first-child</code> or <code class=\"language-text\">.parent</code>, it will still be 15px.</p><hr><h1 id=\"fallback-values\">Fallback Values</h1><p>You can also define a fallback value for a variable by passing a second parameter to <code class=\"language-text\">var</code> . For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"css\"><pre class=\"language-css\"><code class=\"language-css\"><span class=\"token selector\">.second-child</span> <span class=\"token punctuation\">{</span>  \n\t<span class=\"token property\">font-size</span><span class=\"token punctuation\">:</span> <span class=\"token function\">var</span><span class=\"token punctuation\">(</span>--text-size<span class=\"token punctuation\">,</span> 30px<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><p>Fallback values are used when the variable is not defined yet. They are <strong><strong><em><em>not</em></em></strong></strong> used as a fallback to browser incompatibility.</p><hr><h1 id=\"conclusion\">Conclusion</h1><p>And that’s how you can use CSS variables! Keep in mind that some browsers like Internet Explorer don’t support them, so if you need to support all browsers you need to take that into consideration.</p>","htmlAst":{"type":"root","children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"A lot of people don’t know about CSS variables, and you might be one of them! It’s time to learn about CSS variables and how you can use them."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"CSS variables are declared for a specific element as a custom property. Then, you can use that custom property anywhere you use that element."}]},{"type":"element","tagName":"hr","properties":{},"children":[]},{"type":"element","tagName":"h1","properties":{"id":"declaration-and-usage"},"children":[{"type":"text","value":"Declaration and Usage"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Here’s how you declare a custom property:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"css"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","selector"]},"children":[{"type":"text","value":"element"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":" \n\t"},{"type":"element","tagName":"span","properties":{"className":["token","property"]},"children":[{"type":"text","value":"--background-color"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" #f00"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Here, "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"element"}]},{"type":"text","value":" can be a selector of any element, for example, div, p, .test, etc…"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"What we did is that we declared a custom property for this element called "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"--background-color"}]},{"type":"text","value":" . All CSS custom properties must start with "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"--"}]},{"type":"text","value":" ."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Now, we can use this custom property inside "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"element"}]},{"type":"text","value":" using the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"var"}]},{"type":"text","value":" function."}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"css"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","selector"]},"children":[{"type":"text","value":"element"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"  \n\t"},{"type":"element","tagName":"span","properties":{"className":["token","property"]},"children":[{"type":"text","value":"background-color"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"var"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"--background-color"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Here, we assigned the background-color property of "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"element"}]},{"type":"text","value":" to the variable we declared earlier."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This is nice and all, but usually we have repetition inside different elements, not just one. declaring a custom variable inside one element type is not very convenient."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"In order to use a custom property inside more than one element type, we can declare the custom property inside the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":":root"}]},{"type":"text","value":" pseudo-class."}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"css"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","selector"]},"children":[{"type":"text","value":":root"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"  \n\t"},{"type":"element","tagName":"span","properties":{"className":["token","property"]},"children":[{"type":"text","value":"--primary-color"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" #333"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Now, we can use the variable "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"--primary-color"}]},{"type":"text","value":" inside any element in our document:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"css"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","selector"]},"children":[{"type":"text","value":"div"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"  \n\t"},{"type":"element","tagName":"span","properties":{"className":["token","property"]},"children":[{"type":"text","value":"color"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"var"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"--primary-color"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","selector"]},"children":[{"type":"text","value":"p"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"  \n\t"},{"type":"element","tagName":"span","properties":{"className":["token","property"]},"children":[{"type":"text","value":"background-color"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"var"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"--primary-color"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","selector"]},"children":[{"type":"text","value":".fancy"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"  \n\t"},{"type":"element","tagName":"span","properties":{"className":["token","property"]},"children":[{"type":"text","value":"border-color"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"var"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"--primary-color"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"By declaring our custom property inside "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":":root"}]},{"type":"text","value":" , we are now able to use it inside "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"div"}]},{"type":"text","value":" to set the text color, "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"p"}]},{"type":"text","value":" to set the background color, and any element having class "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"fancy"}]},{"type":"text","value":" to set the border color. This way, not only did we minimize repetition, but we also made it easier to edit and change our website’s primary color at any given point."}]},{"type":"element","tagName":"hr","properties":{},"children":[]},{"type":"element","tagName":"h1","properties":{"id":"inheritance"},"children":[{"type":"text","value":"Inheritance"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Elements can also inherit custom properties. For example, let’s say we have the following HTML:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"html"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-html"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-html"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","tag"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","tag"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":"div"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","attr-name"]},"children":[{"type":"text","value":"class"}]},{"type":"element","tagName":"span","properties":{"className":["token","attr-value"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation","attr-equals"]},"children":[{"type":"text","value":"="}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"\""}]},{"type":"text","value":"parent"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":">"}]}]},{"type":"text","value":"\n\t"},{"type":"element","tagName":"span","properties":{"className":["token","tag"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","tag"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":"div"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","attr-name"]},"children":[{"type":"text","value":"class"}]},{"type":"element","tagName":"span","properties":{"className":["token","attr-value"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation","attr-equals"]},"children":[{"type":"text","value":"="}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"\""}]},{"type":"text","value":"first-child"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":">"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","tag"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","tag"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"</"}]},{"type":"text","value":"div"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":">"}]}]},{"type":"text","value":"  \n    "},{"type":"element","tagName":"span","properties":{"className":["token","tag"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","tag"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":"div"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","attr-name"]},"children":[{"type":"text","value":"class"}]},{"type":"element","tagName":"span","properties":{"className":["token","attr-value"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation","attr-equals"]},"children":[{"type":"text","value":"="}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"\""}]},{"type":"text","value":"second-child"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"\""}]}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":">"}]}]},{"type":"element","tagName":"span","properties":{"className":["token","tag"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","tag"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":"div"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":">"}]}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","tag"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","tag"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"</"}]},{"type":"text","value":"div"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":">"}]}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Then, we declare a variable called "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"--text-size"}]},{"type":"text","value":" on "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":".parent"}]},{"type":"text","value":" :"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"css"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","selector"]},"children":[{"type":"text","value":".parent"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"  \n\t"},{"type":"element","tagName":"span","properties":{"className":["token","property"]},"children":[{"type":"text","value":"--text-size"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" 15px"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Now, we can use "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"--text-size"}]},{"type":"text","value":" not only inside "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":".parent"}]},{"type":"text","value":" , but also inside its children as well:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"css"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","selector"]},"children":[{"type":"text","value":".first-child"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","property"]},"children":[{"type":"text","value":"font-size"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"var"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"--text-size"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"We can also override custom properties. We can do that by redeclaring the custom property inside the child element:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"css"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","selector"]},"children":[{"type":"text","value":".second-child"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"  \n\t"},{"type":"element","tagName":"span","properties":{"className":["token","property"]},"children":[{"type":"text","value":"--text-size"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" 30px"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Now, if you use "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"--text-size"}]},{"type":"text","value":" inside "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":".second-child"}]},{"type":"text","value":" , it’ll be evaluated to 30px, but if you use it inside "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":".first-child"}]},{"type":"text","value":" or "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":".parent"}]},{"type":"text","value":", it will still be 15px."}]},{"type":"element","tagName":"hr","properties":{},"children":[]},{"type":"element","tagName":"h1","properties":{"id":"fallback-values"},"children":[{"type":"text","value":"Fallback Values"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can also define a fallback value for a variable by passing a second parameter to "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"var"}]},{"type":"text","value":" . For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"css"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-css"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","selector"]},"children":[{"type":"text","value":".second-child"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"  \n\t"},{"type":"element","tagName":"span","properties":{"className":["token","property"]},"children":[{"type":"text","value":"font-size"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"var"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"--text-size"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" 30px"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Fallback values are used when the variable is not defined yet. They are "},{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"element","tagName":"em","properties":{},"children":[{"type":"element","tagName":"em","properties":{},"children":[{"type":"text","value":"not"}]}]}]}]},{"type":"text","value":" used as a fallback to browser incompatibility."}]},{"type":"element","tagName":"hr","properties":{},"children":[]},{"type":"element","tagName":"h1","properties":{"id":"conclusion"},"children":[{"type":"text","value":"Conclusion"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"And that’s how you can use CSS variables! Keep in mind that some browsers like Internet Explorer don’t support them, so if you need to support all browsers you need to take that into consideration."}]}],"data":{"quirksMode":false}},"tableOfContents":[{"id":"declaration-and-usage","heading":"Declaration and Usage"},{"id":"inheritance","heading":"Inheritance"},{"id":"fallback-values","heading":"Fallback Values"},{"id":"conclusion","heading":"Conclusion"}]},"featureImageSharp":{"base":"carbon--1-.png","publicURL":"/static/ffa580b4a342c60287433e8f82cb8e58/carbon--1-.png","imageMeta":{"width":1080,"height":836},"childImageSharp":{"fluid":{"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAPCAYAAADkmO9VAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB8klEQVQ4y6WUy27aQBSGeZaCTTC2xzeMjT2AjblfWilqVVXpE7RSVlGbRdVdV5SEKH06IqKEVcI7+K9m7HBpXRKpi8//eGbOr3PsM5PrX9xhcHmP3vUDuldrDK/WGP1aY/hC+N7rR+7BvHKDyxW6P5cIP3xH5+QzzJNT6JNT6G9ehjb5BOv9N/RnSzCv3HC+Qnu6gOd10KQSRErwSlJRUFQUZBV5eau7Y6YFhSAvSThyIvSmCwzmqyTD/vQGRTpGXnch+20ofoii5UE0XIhmjVNMEffwIGgVSPUJetObJEP2YC8SHUGqOChaNcheEyTsQqm3EmiIiu3BdCgEw4GoVyEyNVwIxOSxmYalipts2gQ4yVivcn2aF9K1g4al+giyYYNYHkq2v2+6MXA2xsn6MxlKZhXliget1QEJIqgNVnIIhQb8M6g0hOwHIK0uZBpCaUTQ2Fp9vP9TNoZ2DQXdRUGrbsvdyS6LAxmOUTRtELcGxfH/Ki+L7JLniWG58ZpnSGoURtSB7AVQaIu3kNJoQ212UPZDrqoXpC2V1TbccIEjN0LJ0JGXNeQVAkFlaIkSLR1vOdDY93F/toztjz9i4/gstt6dx+bbrylfdvRP2Px5bB6f8VjmwbxyT5cDO+CjnQP/HP+8HPoXdw+c2e3/kfr8BonVY0AbLAheAAAAAElFTkSuQmCC","aspectRatio":1.2962962962962963,"src":"/static/ffa580b4a342c60287433e8f82cb8e58/60290/carbon--1-.png","srcSet":"/static/ffa580b4a342c60287433e8f82cb8e58/847ef/carbon--1-.png 175w,\n/static/ffa580b4a342c60287433e8f82cb8e58/91cba/carbon--1-.png 350w,\n/static/ffa580b4a342c60287433e8f82cb8e58/60290/carbon--1-.png 700w,\n/static/ffa580b4a342c60287433e8f82cb8e58/f5f50/carbon--1-.png 1050w,\n/static/ffa580b4a342c60287433e8f82cb8e58/14010/carbon--1-.png 1080w","srcWebp":"/static/ffa580b4a342c60287433e8f82cb8e58/89afa/carbon--1-.webp","srcSetWebp":"/static/ffa580b4a342c60287433e8f82cb8e58/9fca7/carbon--1-.webp 175w,\n/static/ffa580b4a342c60287433e8f82cb8e58/37a4e/carbon--1-.webp 350w,\n/static/ffa580b4a342c60287433e8f82cb8e58/89afa/carbon--1-.webp 700w,\n/static/ffa580b4a342c60287433e8f82cb8e58/78e7a/carbon--1-.webp 1050w,\n/static/ffa580b4a342c60287433e8f82cb8e58/788b4/carbon--1-.webp 1080w","sizes":"(max-width: 700px) 100vw, 700px"}}}},"allGhostPost":{"edges":[{"node":{"id":"Ghost__Post__631f8eea4e918d05f3537b51","title":"How to Get Elements From the DOM Using JavaScript","slug":"how-to-get-elements-from-the-dom-using-javascript","featured":true,"feature_image":"https://backend.shahednasser.com/content/images/2022/09/js-elm.jpg","excerpt":"This tutorial shows you different ways to get an element from the DOM using JavaScript.","custom_excerpt":"This tutorial shows you different ways to get an element from the DOM using JavaScript.","visibility":"public","created_at_pretty":"12 Sep 2022","published_at_pretty":"19 Sep 2022","updated_at_pretty":"19 Sep 2022","created_at":"2022-09-12T19:56:26.000+00:00","published_at":"2022-09-19T10:58:26.000+00:00","updated_at":"2022-09-19T10:58:26.000+00:00","meta_title":null,"meta_description":null,"og_description":null,"og_image":null,"og_title":null,"twitter_description":null,"twitter_image":null,"twitter_title":null,"authors":[{"slug":"shahed","url":"https://backend.shahednasser.com/author/shahed/","name":"Shahed Nasser","bio":null,"cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/03/IMG_0591.jpg","location":null,"website":null,"twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":null}],"primary_author":{"slug":"shahed","url":"https://backend.shahednasser.com/author/shahed/","name":"Shahed Nasser","bio":null,"cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/03/IMG_0591.jpg","location":null,"website":null,"twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":{"base":"IMG_0591.jpg","publicURL":"/static/ceb49c3c631485453e71e00d7f84b069/IMG_0591.jpg","imageMeta":{"width":1182,"height":1179},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAUABQDASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAMEAQL/xAAWAQEBAQAAAAAAAAAAAAAAAAADBAL/2gAMAwEAAhADEAAAAdXiFM6i0CohUWXoKn//xAAcEAACAgIDAAAAAAAAAAAAAAACAwESBBEhM0H/2gAIAQEAAQUCWySE3WEr7SzbXjAj4iKty+sOQ//EABYRAQEBAAAAAAAAAAAAAAAAAAERIP/aAAgBAwEBPwEhj//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8BH//EAB4QAAIBBAMBAAAAAAAAAAAAAAABIRESMUECECJx/9oACAEBAAY/ApVGWvOjzgtUwLlTZA0sdL4f/8QAHBAAAwACAwEAAAAAAAAAAAAAAAERITFBkbHB/9oACAEBAAE/IahkCy+N2GwZpjQiJHJCspUFY0QrSi+HqiW2rgf/2gAMAwEAAgADAAAAEPw3/wD/xAAYEQEBAAMAAAAAAAAAAAAAAAAAARExQf/aAAgBAwEBPxCtjDqP/8QAFxEBAQEBAAAAAAAAAAAAAAAAAQAxEf/aAAgBAgEBPxBFus6Tt//EAB8QAQEAAgIBBQAAAAAAAAAAAAERACExQWFRcYGR0f/aAAgBAQABPxAuaBPPzkO1wyX7F4wkwXanfZrFQgeqE9JgS14vVOvrERIJomVBKwt2jebAeP0yVa8h1n//2Q==","aspectRatio":1,"src":"/static/ceb49c3c631485453e71e00d7f84b069/31709/IMG_0591.jpg","srcSet":"/static/ceb49c3c631485453e71e00d7f84b069/f340b/IMG_0591.jpg 28w,\n/static/ceb49c3c631485453e71e00d7f84b069/22d64/IMG_0591.jpg 55w,\n/static/ceb49c3c631485453e71e00d7f84b069/31709/IMG_0591.jpg 110w,\n/static/ceb49c3c631485453e71e00d7f84b069/aa249/IMG_0591.jpg 165w,\n/static/ceb49c3c631485453e71e00d7f84b069/0dc33/IMG_0591.jpg 220w,\n/static/ceb49c3c631485453e71e00d7f84b069/d8257/IMG_0591.jpg 1182w","srcWebp":"/static/ceb49c3c631485453e71e00d7f84b069/8678c/IMG_0591.webp","srcSetWebp":"/static/ceb49c3c631485453e71e00d7f84b069/59cda/IMG_0591.webp 28w,\n/static/ceb49c3c631485453e71e00d7f84b069/7da75/IMG_0591.webp 55w,\n/static/ceb49c3c631485453e71e00d7f84b069/8678c/IMG_0591.webp 110w,\n/static/ceb49c3c631485453e71e00d7f84b069/f282e/IMG_0591.webp 165w,\n/static/ceb49c3c631485453e71e00d7f84b069/a7b21/IMG_0591.webp 220w,\n/static/ceb49c3c631485453e71e00d7f84b069/63099/IMG_0591.webp 1182w","sizes":"(max-width: 110px) 100vw, 110px"}}}},"primary_tag":{"slug":"js","url":"https://backend.shahednasser.com/tag/js/","name":"Javascript","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1592609931095-54a2168ae893-2.jpeg","description":"Learn more about Javascript through tutorials, articles, and tips.","meta_title":null,"meta_description":"Learn more about Javascript through tutorials, articles and tips.","featureImageSharp":{"base":"photo-1592609931095-54a2168ae893-2.jpeg","publicURL":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/photo-1592609931095-54a2168ae893-2.jpeg","imageMeta":{"width":2000,"height":1333},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAANABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAwAEBf/EABUBAQEAAAAAAAAAAAAAAAAAAAAB/9oADAMBAAIQAxAAAAHh6QZDjq//xAAaEAEAAwADAAAAAAAAAAAAAAABAAIREiFB/9oACAEBAAEFApQ6eO+VXFWf/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPwE//8QAFREBAQAAAAAAAAAAAAAAAAAAEDH/2gAIAQIBAT8Bp//EABoQAAICAwAAAAAAAAAAAAAAAAABECExMkH/2gAIAQEABj8CwdNXFOP/xAAcEAADAAMAAwAAAAAAAAAAAAAAAREhQVFhcYH/2gAIAQEAAT8heHx6GaR4cOQ+jrqtTQu6lgaVs//aAAwDAQACAAMAAAAQlM//xAAWEQEBAQAAAAAAAAAAAAAAAAAAARH/2gAIAQMBAT8QrH//xAAWEQEBAQAAAAAAAAAAAAAAAAABEBH/2gAIAQIBAT8QdE//xAAcEAEAAgIDAQAAAAAAAAAAAAABABEhMUFhweH/2gAIAQEAAT8QwaQHozIjaNdvYnh0/qNZJwLU36JcXxL2lqf/2Q==","aspectRatio":1.5028901734104045,"src":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/d5c54/photo-1592609931095-54a2168ae893-2.jpg","srcSet":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/65d8c/photo-1592609931095-54a2168ae893-2.jpg 260w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/c5f21/photo-1592609931095-54a2168ae893-2.jpg 520w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/d5c54/photo-1592609931095-54a2168ae893-2.jpg 1040w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/81a53/photo-1592609931095-54a2168ae893-2.jpg 1560w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/4e5f3/photo-1592609931095-54a2168ae893-2.jpg 2000w","srcWebp":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/e4875/photo-1592609931095-54a2168ae893-2.webp","srcSetWebp":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/dc8f3/photo-1592609931095-54a2168ae893-2.webp 260w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/2db4b/photo-1592609931095-54a2168ae893-2.webp 520w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/e4875/photo-1592609931095-54a2168ae893-2.webp 1040w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/f5845/photo-1592609931095-54a2168ae893-2.webp 1560w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/49d6b/photo-1592609931095-54a2168ae893-2.webp 2000w","sizes":"(max-width: 1040px) 100vw, 1040px"}}}},"tags":[{"slug":"js","url":"https://backend.shahednasser.com/tag/js/","name":"Javascript","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1592609931095-54a2168ae893-2.jpeg","description":"Learn more about Javascript through tutorials, articles, and tips.","meta_title":null,"meta_description":"Learn more about Javascript through tutorials, articles and tips.","featureImageSharp":null},{"slug":"beginner","url":"https://backend.shahednasser.com/tag/beginner/","name":"Beginners","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1521185496955-15097b20c5fe-2.jpeg","description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","meta_title":"Beginners","meta_description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","featureImageSharp":null}],"plaintext":"While creating a website and working with JavaScript, you'll often need to get access to elements in the DOM for different purposes.\n\nThis tutorial shows you different ways to get an element from the DOM using JavaScript.\n\n\ngetElementById\n\nThe getElementById() method allows you to retrieve an element from the DOM using the element's ID.\n\nIf no element exists in the DOM with the supplied ID, null will be returned instead.\n\nFor example:\n\nconst mainElement = document.getElementById('main');\n\n\ngetElementsByTagName\n\nThe getElementsByTagName() allows you to retrieve an HTMLCollection of elements that have the tag name you supply to the method. An example of a tag name is div.\n\nItems in an HTMLCollection can be accessed similarly to how you would access items in an array.\n\nFor example:\n\nconst divElements = document.getElementsByTagName('div');\nconsole.log(divElements[0]);\n\nYou can use this method on any element and not just the document. That way, you can retrieve all children of that element that have the supplied tag name.\n\nFor example:\n\nconst divElements = document.getElementsByTagName('div');\nconst pElements = divElements[0].getElementsByTagName('p');\nconsole.log(pElements);\n\n\ngetElementsByClassName()\n\nThe getElementsByClassName() method allows you to retrieve a live HTMLCollection of elements that have the class name you provide as a parameter.\n\nA live HTMLCollection means that the items in the collection are updated with any updates that happen to the DOM. So, for example, if an item was part of the collection because it had the class provided as a parameter, but then its class was removed, the item will be removed from the collection.\n\nFor example:\n\nconst mainElements = document.getElementsByClassName('main');\nconsole.log(mainElements);\n\n\ngetElementsByName()\n\nThe getElementsByName() method allows you to retrieve elements by the value of the name attribute. For example, you can use it to retrieve input elements that have the name attribute set to email.\n\nThis method returns a live NodeList, which is generally similar to an HTMLCollection, but the items in the list can be accessed through the methods it provides.\n\nFor example:\n\nconst emailElements = document.getElementsByName('email');\nconsole.log(emailElements.item(0));\n\n\nquerySelector\n\nThe querySelector() method allows you to retrieve the first element that matches the specified selector. The selector can be any CSS selector.\n\nFor example:\n\nconst elm = document.querySelector('.main > p');\nconsole.log(elm);\n\nThis method can be used on any element, and not just the document. So, you can use it to retrieve a child element of a parent element that matches the specified selector.\n\nFor example:\n\nconst table = document.querySelector('.main > table');\nconst thead = table.querySelector('thead');\n\n\nquerySelectorAll\n\nThe querySelectorAll() method allows you to retrieve all elements that match the specified selector. This method returns a NodeList.\n\nFor example:\n\nconst elms = document.querySelectorAll('.main > p');\nconsole.log(elms.item(0));\n\nThis method can be used on any element, and not just the document. So, you can use it to retrieve all child elements of a parent element that match the specified selector.\n\nFor example:\n\nconst table = document.querySelector('.main > table');\nconst rows = table.querySelectorAll('tr');\nfor (const row of rows) {\n    console.log(row);\n}\n\n\nchildren\n\nThe children property allows you to retrieve all immediate child elements of the document or any element. This property's type is a live HTMLCollection.\n\nFor example:\n\nconst rows = document.querySelectorAll('table tr');\nfor (const row of rows) {\n    console.log(row.children);\n}\n\n\nfirstElementChild\n\nThe firstElementChild property allows you to retrieve the first child element of the document or any element.\n\nIf the element does not have children, the value of firstElementChild is null.\n\nFor example:\n\nconst rows = document.querySelectorAll('table tr');\nfor (const row of rows) {\n    console.log(row.firstElementChild);\n}\n\n\nlastElementChild\n\nThe lastElementChild property allows you to retrieve the last child element of the document or any element.\n\nIf the element does not have children, the value of lastElementChild is null:\n\nconst rows = document.querySelectorAll('table tr');\nfor (const row of rows) {\n    console.log(row.lastElementChild);\n}\n\n\nscripts\n\nThe scripts property allows you to retrieve all <script> elements in the document. It returns an HTMLCollection of elements.\n\nFor example:\n\nconsole.log(document.scripts);\n\n\nelementFromPoint\n\nThe elementFromPoint() method allows you to retrieve the top element starting from a specified point. It accepts x and y coordinates to locate the point to look for the element.\n\nFor example:\n\nconst elm = document.elemetFromPoint(100, 20);\nconsole.log(elm);\n\n\nelementsFromPoint\n\nThe elementsFromPoint() method allows you to retrieve an array of Elements starting from a specified point until the end of the viewport.\n\nFor example:\n\nconst elms = document.elementsFromPoint(100, 20);\nconsole.log(elm[0]);\n\n\nclosest\n\nThe closest() method available on elements (not on the document) allows you to retrieve the closest ancestor (which are the parents) of the element that matches the specified selector. If no elements are found, the method returns null.\n\nFor example:\n\nconst closestElm = table.closest('div');\nconsole.log(closestElm);\n\n\nnextElementSibling\n\nThe nextElementSibling property on elements (not on the document) allows you to retrieve the element that follows the current element among its parent's child elements.\n\nIf there are no elements after this element, the value of the property will be null.\n\nFor example:\n\nconsole.log(table.nextElementSibling);\n\n\npreviousElementSibling\n\nThe previousElementSibling property on elements (not on the document) allows you to retrieve the element that proceeds the current element among its parent's child elements.\n\nIf there are no elements before this element, the value of the property will be null.\n\nFor example:\n\nconsole.log(table.previousElementSibling);\n\n\nConclusion\n\nThis tutorial explores a list of methods and properties that you can use to retrieve elements in JavaScript. Each have different purposes and can be used differently based on your use case.","html":"<p>While creating a website and working with JavaScript, you'll often need to get access to elements in the DOM for different purposes.</p><p>This tutorial shows you different ways to get an element from the DOM using JavaScript.</p><h2 id=\"getelementbyid\">getElementById</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById\">getElementById()</a> method allows you to retrieve an element from the DOM using the element's ID.</p><p>If no element exists in the DOM with the supplied ID, <code>null</code> will be returned instead.</p><p>For example:</p><pre><code class=\"language-js\">const mainElement = document.getElementById('main');</code></pre><h2 id=\"getelementsbytagname\">getElementsByTagName</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByTagName\">getElementsByTagName()</a> allows you to retrieve an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection\">HTMLCollection</a> of elements that have the tag name you supply to the method. An example of a tag name is <code>div</code>.</p><p>Items in an <code>HTMLCollection</code> can be accessed similarly to how you would access items in an array.</p><p>For example:</p><pre><code class=\"language-js\">const divElements = document.getElementsByTagName('div');\nconsole.log(divElements[0]);</code></pre><p>You can use this method on any element and not just the <code>document</code>. That way, you can retrieve all children of that element that have the supplied tag name.</p><p>For example:</p><pre><code class=\"language-js\">const divElements = document.getElementsByTagName('div');\nconst pElements = divElements[0].getElementsByTagName('p');\nconsole.log(pElements);</code></pre><h2 id=\"getelementsbyclassname\">getElementsByClassName()</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName\">getElementsByClassName()</a> method allows you to retrieve a live <code>HTMLCollection</code> of elements that have the class name you provide as a parameter.</p><p>A live <code>HTMLCollection</code> means that the items in the collection are updated with any updates that happen to the DOM. So, for example, if an item was part of the collection because it had the class provided as a parameter, but then its class was removed, the item will be removed from the collection.</p><p>For example:</p><pre><code class=\"language-js\">const mainElements = document.getElementsByClassName('main');\nconsole.log(mainElements);</code></pre><h2 id=\"getelementsbyname\">getElementsByName()</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByName\">getElementsByName()</a> method allows you to retrieve elements by the value of the <code>name</code> attribute. For example, you can use it to retrieve <code>input</code> elements that have the <code>name</code> attribute set to <code>email</code>.</p><p>This method returns a live <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NodeList\">NodeList</a>, which is generally similar to an <code>HTMLCollection</code>, but the items in the list can be accessed through the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NodeList#methods\">methods</a> it provides.</p><p>For example:</p><pre><code class=\"language-js\">const emailElements = document.getElementsByName('email');\nconsole.log(emailElements.item(0));</code></pre><h2 id=\"queryselector\">querySelector</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector\">querySelector()</a> method allows you to retrieve the first element that matches the specified selector. The selector can be any <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors\">CSS selector</a>.</p><p>For example:</p><pre><code class=\"language-js\">const elm = document.querySelector('.main &gt; p');\nconsole.log(elm);</code></pre><p>This method can be used on any element, and not just the <code>document</code>. So, you can use it to retrieve a child element of a parent element that matches the specified selector.</p><p>For example:</p><pre><code class=\"language-js\">const table = document.querySelector('.main &gt; table');\nconst thead = table.querySelector('thead');</code></pre><h2 id=\"queryselectorall\">querySelectorAll</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll\">querySelectorAll()</a> method allows you to retrieve all elements that match the specified selector. This method returns a <code>NodeList</code>.</p><p>For example:</p><pre><code class=\"language-js\">const elms = document.querySelectorAll('.main &gt; p');\nconsole.log(elms.item(0));</code></pre><p>This method can be used on any element, and not just the <code>document</code>. So, you can use it to retrieve all child elements of a parent element that match the specified selector.</p><p>For example:</p><pre><code class=\"language-js\">const table = document.querySelector('.main &gt; table');\nconst rows = table.querySelectorAll('tr');\nfor (const row of rows) {\n    console.log(row);\n}</code></pre><h2 id=\"children\">children</h2><p>The <code>children</code> property allows you to retrieve all immediate child elements of the <code>document</code> or any element. This property's type is a live <code>HTMLCollection</code>.</p><p>For example:</p><pre><code class=\"language-js\">const rows = document.querySelectorAll('table tr');\nfor (const row of rows) {\n    console.log(row.children);\n}</code></pre><h2 id=\"firstelementchild\">firstElementChild</h2><p>The <code>firstElementChild</code> property allows you to retrieve the first child element of the <code>document</code> or any element.</p><p>If the element does not have children, the value of <code>firstElementChild</code> is <code>null</code>.</p><p>For example:</p><pre><code class=\"language-js\">const rows = document.querySelectorAll('table tr');\nfor (const row of rows) {\n    console.log(row.firstElementChild);\n}</code></pre><h2 id=\"lastelementchild\">lastElementChild</h2><p>The <code>lastElementChild</code> property allows you to retrieve the last child element of the <code>document</code> or any element.</p><p>If the element does not have children, the value of <code>lastElementChild</code> is <code>null</code>:</p><pre><code class=\"language-js\">const rows = document.querySelectorAll('table tr');\nfor (const row of rows) {\n    console.log(row.lastElementChild);\n}</code></pre><h2 id=\"scripts\">scripts</h2><p>The <code>scripts</code> property allows you to retrieve all <code>&lt;script&gt;</code> elements in the document. It returns an <code>HTMLCollection</code> of elements.</p><p>For example:</p><pre><code class=\"language-js\">console.log(document.scripts);</code></pre><h2 id=\"elementfrompoint\">elementFromPoint</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint\">elementFromPoint()</a> method allows you to retrieve the top element starting from a specified point. It accepts x and y coordinates to locate the point to look for the element.</p><p>For example:</p><pre><code class=\"language-js\">const elm = document.elemetFromPoint(100, 20);\nconsole.log(elm);</code></pre><h2 id=\"elementsfrompoint\">elementsFromPoint</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/elementsFromPoint\">elementsFromPoint()</a> method allows you to retrieve an array of Elements starting from a specified point until the end of the viewport.</p><p>For example:</p><pre><code class=\"language-js\">const elms = document.elementsFromPoint(100, 20);\nconsole.log(elm[0]);</code></pre><h2 id=\"closest\">closest</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Element/closest\">closest()</a> method available on elements (not on the <code>document</code>) allows you to retrieve the closest ancestor (which are the parents) of the element that matches the specified selector. If no elements are found, the method returns <code>null</code>.</p><p>For example:</p><pre><code class=\"language-js\">const closestElm = table.closest('div');\nconsole.log(closestElm);</code></pre><h2 id=\"nextelementsibling\">nextElementSibling</h2><p>The <code>nextElementSibling</code> property on elements (not on the <code>document</code>) allows you to retrieve the element that follows the current element among its parent's child elements.</p><p>If there are no elements after this element, the value of the property will be <code>null</code>.</p><p>For example:</p><pre><code class=\"language-js\">console.log(table.nextElementSibling);</code></pre><h2 id=\"previouselementsibling\">previousElementSibling</h2><p>The <code>previousElementSibling</code> property on elements (not on the <code>document</code>) allows you to retrieve the element that proceeds the current element among its parent's child elements.</p><p>If there are no elements before this element, the value of the property will be <code>null</code>.</p><p>For example:</p><pre><code class=\"language-js\">console.log(table.previousElementSibling);</code></pre><h2 id=\"conclusion\">Conclusion</h2><p>This tutorial explores a list of methods and properties that you can use to retrieve elements in JavaScript. Each have different purposes and can be used differently based on your use case.</p>","url":"https://backend.shahednasser.com/how-to-get-elements-from-the-dom-using-javascript/","canonical_url":null,"uuid":"059a970c-e25a-42bc-9c72-002c52914f7b","codeinjection_foot":null,"codeinjection_head":null,"codeinjection_styles":null,"comment_id":"631f8eea4e918d05f3537b51","reading_time":4,"send_email_when_published":null,"email_subject":null,"childHtmlRehype":{"html":"<p>While creating a website and working with JavaScript, you'll often need to get access to elements in the DOM for different purposes.</p><p>This tutorial shows you different ways to get an element from the DOM using JavaScript.</p><h2 id=\"getelementbyid\">getElementById</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById\">getElementById()</a> method allows you to retrieve an element from the DOM using the element's ID.</p><p>If no element exists in the DOM with the supplied ID, <code class=\"language-text\">null</code> will be returned instead.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> mainElement <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementById</span><span class=\"token punctuation\">(</span><span class=\"token string\">'main'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><h2 id=\"getelementsbytagname\">getElementsByTagName</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByTagName\">getElementsByTagName()</a> allows you to retrieve an <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection\">HTMLCollection</a> of elements that have the tag name you supply to the method. An example of a tag name is <code class=\"language-text\">div</code>.</p><p>Items in an <code class=\"language-text\">HTMLCollection</code> can be accessed similarly to how you would access items in an array.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> divElements <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementsByTagName</span><span class=\"token punctuation\">(</span><span class=\"token string\">'div'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>divElements<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><p>You can use this method on any element and not just the <code class=\"language-text\">document</code>. That way, you can retrieve all children of that element that have the supplied tag name.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> divElements <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementsByTagName</span><span class=\"token punctuation\">(</span><span class=\"token string\">'div'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> pElements <span class=\"token operator\">=</span> divElements<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">.</span><span class=\"token function\">getElementsByTagName</span><span class=\"token punctuation\">(</span><span class=\"token string\">'p'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>pElements<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><h2 id=\"getelementsbyclassname\">getElementsByClassName()</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName\">getElementsByClassName()</a> method allows you to retrieve a live <code class=\"language-text\">HTMLCollection</code> of elements that have the class name you provide as a parameter.</p><p>A live <code class=\"language-text\">HTMLCollection</code> means that the items in the collection are updated with any updates that happen to the DOM. So, for example, if an item was part of the collection because it had the class provided as a parameter, but then its class was removed, the item will be removed from the collection.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> mainElements <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementsByClassName</span><span class=\"token punctuation\">(</span><span class=\"token string\">'main'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>mainElements<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><h2 id=\"getelementsbyname\">getElementsByName()</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByName\">getElementsByName()</a> method allows you to retrieve elements by the value of the <code class=\"language-text\">name</code> attribute. For example, you can use it to retrieve <code class=\"language-text\">input</code> elements that have the <code class=\"language-text\">name</code> attribute set to <code class=\"language-text\">email</code>.</p><p>This method returns a live <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NodeList\">NodeList</a>, which is generally similar to an <code class=\"language-text\">HTMLCollection</code>, but the items in the list can be accessed through the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/NodeList#methods\">methods</a> it provides.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> emailElements <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">getElementsByName</span><span class=\"token punctuation\">(</span><span class=\"token string\">'email'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>emailElements<span class=\"token punctuation\">.</span><span class=\"token function\">item</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><h2 id=\"queryselector\">querySelector</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector\">querySelector()</a> method allows you to retrieve the first element that matches the specified selector. The selector can be any <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors\">CSS selector</a>.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> elm <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.main > p'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>elm<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><p>This method can be used on any element, and not just the <code class=\"language-text\">document</code>. So, you can use it to retrieve a child element of a parent element that matches the specified selector.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> table <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.main > table'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> thead <span class=\"token operator\">=</span> table<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'thead'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><h2 id=\"queryselectorall\">querySelectorAll</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll\">querySelectorAll()</a> method allows you to retrieve all elements that match the specified selector. This method returns a <code class=\"language-text\">NodeList</code>.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> elms <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.main > p'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>elms<span class=\"token punctuation\">.</span><span class=\"token function\">item</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><p>This method can be used on any element, and not just the <code class=\"language-text\">document</code>. So, you can use it to retrieve all child elements of a parent element that match the specified selector.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> table <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelector</span><span class=\"token punctuation\">(</span><span class=\"token string\">'.main > table'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">const</span> rows <span class=\"token operator\">=</span> table<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'tr'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> row <span class=\"token keyword\">of</span> rows<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><h2 id=\"children\">children</h2><p>The <code class=\"language-text\">children</code> property allows you to retrieve all immediate child elements of the <code class=\"language-text\">document</code> or any element. This property's type is a live <code class=\"language-text\">HTMLCollection</code>.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> rows <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'table tr'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> row <span class=\"token keyword\">of</span> rows<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">.</span>children<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><h2 id=\"firstelementchild\">firstElementChild</h2><p>The <code class=\"language-text\">firstElementChild</code> property allows you to retrieve the first child element of the <code class=\"language-text\">document</code> or any element.</p><p>If the element does not have children, the value of <code class=\"language-text\">firstElementChild</code> is <code class=\"language-text\">null</code>.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> rows <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'table tr'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> row <span class=\"token keyword\">of</span> rows<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">.</span>firstElementChild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><h2 id=\"lastelementchild\">lastElementChild</h2><p>The <code class=\"language-text\">lastElementChild</code> property allows you to retrieve the last child element of the <code class=\"language-text\">document</code> or any element.</p><p>If the element does not have children, the value of <code class=\"language-text\">lastElementChild</code> is <code class=\"language-text\">null</code>:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> rows <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">querySelectorAll</span><span class=\"token punctuation\">(</span><span class=\"token string\">'table tr'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token keyword\">for</span> <span class=\"token punctuation\">(</span><span class=\"token keyword\">const</span> row <span class=\"token keyword\">of</span> rows<span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>row<span class=\"token punctuation\">.</span>lastElementChild<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><h2 id=\"scripts\">scripts</h2><p>The <code class=\"language-text\">scripts</code> property allows you to retrieve all <code class=\"language-text\">&#x3C;script></code> elements in the document. It returns an <code class=\"language-text\">HTMLCollection</code> of elements.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span>scripts<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><h2 id=\"elementfrompoint\">elementFromPoint</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint\">elementFromPoint()</a> method allows you to retrieve the top element starting from a specified point. It accepts x and y coordinates to locate the point to look for the element.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> elm <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">elemetFromPoint</span><span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>elm<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><h2 id=\"elementsfrompoint\">elementsFromPoint</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/elementsFromPoint\">elementsFromPoint()</a> method allows you to retrieve an array of Elements starting from a specified point until the end of the viewport.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> elms <span class=\"token operator\">=</span> document<span class=\"token punctuation\">.</span><span class=\"token function\">elementsFromPoint</span><span class=\"token punctuation\">(</span><span class=\"token number\">100</span><span class=\"token punctuation\">,</span> <span class=\"token number\">20</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>elm<span class=\"token punctuation\">[</span><span class=\"token number\">0</span><span class=\"token punctuation\">]</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><h2 id=\"closest\">closest</h2><p>The <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Element/closest\">closest()</a> method available on elements (not on the <code class=\"language-text\">document</code>) allows you to retrieve the closest ancestor (which are the parents) of the element that matches the specified selector. If no elements are found, the method returns <code class=\"language-text\">null</code>.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">const</span> closestElm <span class=\"token operator\">=</span> table<span class=\"token punctuation\">.</span><span class=\"token function\">closest</span><span class=\"token punctuation\">(</span><span class=\"token string\">'div'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\nconsole<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>closestElm<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><h2 id=\"nextelementsibling\">nextElementSibling</h2><p>The <code class=\"language-text\">nextElementSibling</code> property on elements (not on the <code class=\"language-text\">document</code>) allows you to retrieve the element that follows the current element among its parent's child elements.</p><p>If there are no elements after this element, the value of the property will be <code class=\"language-text\">null</code>.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">.</span>nextElementSibling<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><h2 id=\"previouselementsibling\">previousElementSibling</h2><p>The <code class=\"language-text\">previousElementSibling</code> property on elements (not on the <code class=\"language-text\">document</code>) allows you to retrieve the element that proceeds the current element among its parent's child elements.</p><p>If there are no elements before this element, the value of the property will be <code class=\"language-text\">null</code>.</p><p>For example:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>table<span class=\"token punctuation\">.</span>previousElementSibling<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span></code></pre></div><h2 id=\"conclusion\">Conclusion</h2><p>This tutorial explores a list of methods and properties that you can use to retrieve elements in JavaScript. Each have different purposes and can be used differently based on your use case.</p>","htmlAst":{"type":"root","children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"While creating a website and working with JavaScript, you'll often need to get access to elements in the DOM for different purposes."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This tutorial shows you different ways to get an element from the DOM using JavaScript."}]},{"type":"element","tagName":"h2","properties":{"id":"getelementbyid"},"children":[{"type":"text","value":"getElementById"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById"},"children":[{"type":"text","value":"getElementById()"}]},{"type":"text","value":" method allows you to retrieve an element from the DOM using the element's ID."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If no element exists in the DOM with the supplied ID, "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"null"}]},{"type":"text","value":" will be returned instead."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" mainElement "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"getElementById"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'main'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"getelementsbytagname"},"children":[{"type":"text","value":"getElementsByTagName"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByTagName"},"children":[{"type":"text","value":"getElementsByTagName()"}]},{"type":"text","value":" allows you to retrieve an "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection"},"children":[{"type":"text","value":"HTMLCollection"}]},{"type":"text","value":" of elements that have the tag name you supply to the method. An example of a tag name is "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"div"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Items in an "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"HTMLCollection"}]},{"type":"text","value":" can be accessed similarly to how you would access items in an array."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" divElements "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"getElementsByTagName"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'div'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\nconsole"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"divElements"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"You can use this method on any element and not just the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"document"}]},{"type":"text","value":". That way, you can retrieve all children of that element that have the supplied tag name."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" divElements "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"getElementsByTagName"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'div'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" pElements "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" divElements"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"getElementsByTagName"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'p'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\nconsole"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"pElements"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"getelementsbyclassname"},"children":[{"type":"text","value":"getElementsByClassName()"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName"},"children":[{"type":"text","value":"getElementsByClassName()"}]},{"type":"text","value":" method allows you to retrieve a live "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"HTMLCollection"}]},{"type":"text","value":" of elements that have the class name you provide as a parameter."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"A live "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"HTMLCollection"}]},{"type":"text","value":" means that the items in the collection are updated with any updates that happen to the DOM. So, for example, if an item was part of the collection because it had the class provided as a parameter, but then its class was removed, the item will be removed from the collection."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" mainElements "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"getElementsByClassName"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'main'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\nconsole"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"mainElements"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"getelementsbyname"},"children":[{"type":"text","value":"getElementsByName()"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByName"},"children":[{"type":"text","value":"getElementsByName()"}]},{"type":"text","value":" method allows you to retrieve elements by the value of the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"name"}]},{"type":"text","value":" attribute. For example, you can use it to retrieve "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"input"}]},{"type":"text","value":" elements that have the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"name"}]},{"type":"text","value":" attribute set to "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"email"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This method returns a live "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/NodeList"},"children":[{"type":"text","value":"NodeList"}]},{"type":"text","value":", which is generally similar to an "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"HTMLCollection"}]},{"type":"text","value":", but the items in the list can be accessed through the "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/NodeList#methods"},"children":[{"type":"text","value":"methods"}]},{"type":"text","value":" it provides."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" emailElements "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"getElementsByName"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'email'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\nconsole"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"emailElements"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"item"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"queryselector"},"children":[{"type":"text","value":"querySelector"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector"},"children":[{"type":"text","value":"querySelector()"}]},{"type":"text","value":" method allows you to retrieve the first element that matches the specified selector. The selector can be any "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors"},"children":[{"type":"text","value":"CSS selector"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" elm "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"querySelector"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'.main > p'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\nconsole"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"elm"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This method can be used on any element, and not just the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"document"}]},{"type":"text","value":". So, you can use it to retrieve a child element of a parent element that matches the specified selector."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" table "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"querySelector"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'.main > table'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" thead "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" table"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"querySelector"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'thead'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"queryselectorall"},"children":[{"type":"text","value":"querySelectorAll"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll"},"children":[{"type":"text","value":"querySelectorAll()"}]},{"type":"text","value":" method allows you to retrieve all elements that match the specified selector. This method returns a "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"NodeList"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" elms "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"querySelectorAll"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'.main > p'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\nconsole"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"elms"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"item"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This method can be used on any element, and not just the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"document"}]},{"type":"text","value":". So, you can use it to retrieve all child elements of a parent element that match the specified selector."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" table "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"querySelector"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'.main > table'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" rows "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" table"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"querySelectorAll"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'tr'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" row "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"of"}]},{"type":"text","value":" rows"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n    console"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"row"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"children"},"children":[{"type":"text","value":"children"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"children"}]},{"type":"text","value":" property allows you to retrieve all immediate child elements of the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"document"}]},{"type":"text","value":" or any element. This property's type is a live "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"HTMLCollection"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" rows "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"querySelectorAll"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'table tr'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" row "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"of"}]},{"type":"text","value":" rows"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n    console"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"row"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"children"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"firstelementchild"},"children":[{"type":"text","value":"firstElementChild"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"firstElementChild"}]},{"type":"text","value":" property allows you to retrieve the first child element of the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"document"}]},{"type":"text","value":" or any element."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If the element does not have children, the value of "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"firstElementChild"}]},{"type":"text","value":" is "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"null"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" rows "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"querySelectorAll"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'table tr'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" row "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"of"}]},{"type":"text","value":" rows"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n    console"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"row"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"firstElementChild"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"lastelementchild"},"children":[{"type":"text","value":"lastElementChild"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"lastElementChild"}]},{"type":"text","value":" property allows you to retrieve the last child element of the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"document"}]},{"type":"text","value":" or any element."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If the element does not have children, the value of "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"lastElementChild"}]},{"type":"text","value":" is "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"null"}]},{"type":"text","value":":"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" rows "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"querySelectorAll"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'table tr'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" row "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"of"}]},{"type":"text","value":" rows"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n    console"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"row"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"lastElementChild"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"scripts"},"children":[{"type":"text","value":"scripts"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"scripts"}]},{"type":"text","value":" property allows you to retrieve all "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"<script>"}]},{"type":"text","value":" elements in the document. It returns an "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"HTMLCollection"}]},{"type":"text","value":" of elements."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"console"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"scripts"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"elementfrompoint"},"children":[{"type":"text","value":"elementFromPoint"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint"},"children":[{"type":"text","value":"elementFromPoint()"}]},{"type":"text","value":" method allows you to retrieve the top element starting from a specified point. It accepts x and y coordinates to locate the point to look for the element."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" elm "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"elemetFromPoint"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"20"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\nconsole"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"elm"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"elementsfrompoint"},"children":[{"type":"text","value":"elementsFromPoint"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Document/elementsFromPoint"},"children":[{"type":"text","value":"elementsFromPoint()"}]},{"type":"text","value":" method allows you to retrieve an array of Elements starting from a specified point until the end of the viewport."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" elms "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"elementsFromPoint"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"100"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"20"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\nconsole"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"elm"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"closest"},"children":[{"type":"text","value":"closest"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Element/closest"},"children":[{"type":"text","value":"closest()"}]},{"type":"text","value":" method available on elements (not on the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"document"}]},{"type":"text","value":") allows you to retrieve the closest ancestor (which are the parents) of the element that matches the specified selector. If no elements are found, the method returns "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"null"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" closestElm "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" table"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"closest"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'div'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\nconsole"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"closestElm"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"nextelementsibling"},"children":[{"type":"text","value":"nextElementSibling"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"nextElementSibling"}]},{"type":"text","value":" property on elements (not on the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"document"}]},{"type":"text","value":") allows you to retrieve the element that follows the current element among its parent's child elements."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If there are no elements after this element, the value of the property will be "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"null"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"console"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"table"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"nextElementSibling"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"previouselementsibling"},"children":[{"type":"text","value":"previousElementSibling"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"previousElementSibling"}]},{"type":"text","value":" property on elements (not on the "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"document"}]},{"type":"text","value":") allows you to retrieve the element that proceeds the current element among its parent's child elements."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If there are no elements before this element, the value of the property will be "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"null"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"console"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"table"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"previousElementSibling"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"conclusion"},"children":[{"type":"text","value":"Conclusion"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"This tutorial explores a list of methods and properties that you can use to retrieve elements in JavaScript. Each have different purposes and can be used differently based on your use case."}]}],"data":{"quirksMode":false}},"tableOfContents":[{"id":"getelementbyid","heading":"getElementById"},{"id":"getelementsbytagname","heading":"getElementsByTagName"},{"id":"getelementsbyclassname","heading":"getElementsByClassName()"},{"id":"getelementsbyname","heading":"getElementsByName()"},{"id":"queryselector","heading":"querySelector"},{"id":"queryselectorall","heading":"querySelectorAll"},{"id":"children","heading":"children"},{"id":"firstelementchild","heading":"firstElementChild"},{"id":"lastelementchild","heading":"lastElementChild"},{"id":"scripts","heading":"scripts"},{"id":"elementfrompoint","heading":"elementFromPoint"},{"id":"elementsfrompoint","heading":"elementsFromPoint"},{"id":"closest","heading":"closest"},{"id":"nextelementsibling","heading":"nextElementSibling"},{"id":"previouselementsibling","heading":"previousElementSibling"},{"id":"conclusion","heading":"Conclusion"}]},"featureImageSharp":{"base":"js-elm.jpg","publicURL":"/static/e1e7a4c25e44c189d9cf97060890c67b/js-elm.jpg","imageMeta":{"width":1560,"height":876},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAALABQDASIAAhEBAxEB/8QAGAAAAgMAAAAAAAAAAAAAAAAAAAECAwX/xAAUAQEAAAAAAAAAAAAAAAAAAAAA/9oADAMBAAIQAxAAAAHbjcCGH//EABgQAAIDAAAAAAAAAAAAAAAAAAERAAIg/9oACAEBAAEFAmXZwY//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/AT//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/AT//xAAVEAEBAAAAAAAAAAAAAAAAAAAgMf/aAAgBAQAGPwKL/8QAGRABAQADAQAAAAAAAAAAAAAAAREAITEg/9oACAEBAAE/ISo4zfphcS9J4//aAAwDAQACAAMAAAAQ48//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/ED//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/ED//xAAcEAEAAwACAwAAAAAAAAAAAAABABExECFBcZH/2gAIAQEAAT8QZWodVOvkb7ZDNYCtoUC7vhB08wKv3P/Z","aspectRatio":1.7857142857142858,"src":"/static/e1e7a4c25e44c189d9cf97060890c67b/ea4ab/js-elm.jpg","srcSet":"/static/e1e7a4c25e44c189d9cf97060890c67b/477ba/js-elm.jpg 175w,\n/static/e1e7a4c25e44c189d9cf97060890c67b/06776/js-elm.jpg 350w,\n/static/e1e7a4c25e44c189d9cf97060890c67b/ea4ab/js-elm.jpg 700w,\n/static/e1e7a4c25e44c189d9cf97060890c67b/3055e/js-elm.jpg 1050w,\n/static/e1e7a4c25e44c189d9cf97060890c67b/eff08/js-elm.jpg 1400w,\n/static/e1e7a4c25e44c189d9cf97060890c67b/81a53/js-elm.jpg 1560w","srcWebp":"/static/e1e7a4c25e44c189d9cf97060890c67b/89afa/js-elm.webp","srcSetWebp":"/static/e1e7a4c25e44c189d9cf97060890c67b/9fca7/js-elm.webp 175w,\n/static/e1e7a4c25e44c189d9cf97060890c67b/37a4e/js-elm.webp 350w,\n/static/e1e7a4c25e44c189d9cf97060890c67b/89afa/js-elm.webp 700w,\n/static/e1e7a4c25e44c189d9cf97060890c67b/78e7a/js-elm.webp 1050w,\n/static/e1e7a4c25e44c189d9cf97060890c67b/03d34/js-elm.webp 1400w,\n/static/e1e7a4c25e44c189d9cf97060890c67b/f5845/js-elm.webp 1560w","sizes":"(max-width: 700px) 100vw, 700px"}}}}},{"node":{"id":"Ghost__Post__626e658e39840e1ac2875199","title":"Local Storage vs Cookies: What's the Difference?","slug":"localstorage-vs-cookies-whats-the-difference","featured":true,"feature_image":"https://backend.shahednasser.com/content/images/2022/05/Local-Storage-vs-Cookies-What-s-the-Difference.jpg","excerpt":"In this article, you'll learn about some of the main differences between local storage and cookies and which you should choose for your websites.","custom_excerpt":"In this article, you'll learn about some of the main differences between local storage and cookies and which you should choose for your websites.","visibility":"public","created_at_pretty":"1 May 2022","published_at_pretty":"5 May 2022","updated_at_pretty":"5 May 2022","created_at":"2022-05-01T10:48:46.000+00:00","published_at":"2022-05-05T08:57:19.000+00:00","updated_at":"2022-05-05T08:57:19.000+00:00","meta_title":null,"meta_description":null,"og_description":null,"og_image":null,"og_title":null,"twitter_description":null,"twitter_image":null,"twitter_title":null,"authors":[{"slug":"shahed","url":"https://backend.shahednasser.com/author/shahed/","name":"Shahed Nasser","bio":null,"cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/03/IMG_0591.jpg","location":null,"website":null,"twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":null}],"primary_author":{"slug":"shahed","url":"https://backend.shahednasser.com/author/shahed/","name":"Shahed Nasser","bio":null,"cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/03/IMG_0591.jpg","location":null,"website":null,"twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":{"base":"IMG_0591.jpg","publicURL":"/static/ceb49c3c631485453e71e00d7f84b069/IMG_0591.jpg","imageMeta":{"width":1182,"height":1179},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAUABQDASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAMEAQL/xAAWAQEBAQAAAAAAAAAAAAAAAAADBAL/2gAMAwEAAhADEAAAAdXiFM6i0CohUWXoKn//xAAcEAACAgIDAAAAAAAAAAAAAAACAwESBBEhM0H/2gAIAQEAAQUCWySE3WEr7SzbXjAj4iKty+sOQ//EABYRAQEBAAAAAAAAAAAAAAAAAAERIP/aAAgBAwEBPwEhj//EABQRAQAAAAAAAAAAAAAAAAAAACD/2gAIAQIBAT8BH//EAB4QAAIBBAMBAAAAAAAAAAAAAAABIRESMUECECJx/9oACAEBAAY/ApVGWvOjzgtUwLlTZA0sdL4f/8QAHBAAAwACAwEAAAAAAAAAAAAAAAERITFBkbHB/9oACAEBAAE/IahkCy+N2GwZpjQiJHJCspUFY0QrSi+HqiW2rgf/2gAMAwEAAgADAAAAEPw3/wD/xAAYEQEBAAMAAAAAAAAAAAAAAAAAARExQf/aAAgBAwEBPxCtjDqP/8QAFxEBAQEBAAAAAAAAAAAAAAAAAQAxEf/aAAgBAgEBPxBFus6Tt//EAB8QAQEAAgIBBQAAAAAAAAAAAAERACExQWFRcYGR0f/aAAgBAQABPxAuaBPPzkO1wyX7F4wkwXanfZrFQgeqE9JgS14vVOvrERIJomVBKwt2jebAeP0yVa8h1n//2Q==","aspectRatio":1,"src":"/static/ceb49c3c631485453e71e00d7f84b069/31709/IMG_0591.jpg","srcSet":"/static/ceb49c3c631485453e71e00d7f84b069/f340b/IMG_0591.jpg 28w,\n/static/ceb49c3c631485453e71e00d7f84b069/22d64/IMG_0591.jpg 55w,\n/static/ceb49c3c631485453e71e00d7f84b069/31709/IMG_0591.jpg 110w,\n/static/ceb49c3c631485453e71e00d7f84b069/aa249/IMG_0591.jpg 165w,\n/static/ceb49c3c631485453e71e00d7f84b069/0dc33/IMG_0591.jpg 220w,\n/static/ceb49c3c631485453e71e00d7f84b069/d8257/IMG_0591.jpg 1182w","srcWebp":"/static/ceb49c3c631485453e71e00d7f84b069/8678c/IMG_0591.webp","srcSetWebp":"/static/ceb49c3c631485453e71e00d7f84b069/59cda/IMG_0591.webp 28w,\n/static/ceb49c3c631485453e71e00d7f84b069/7da75/IMG_0591.webp 55w,\n/static/ceb49c3c631485453e71e00d7f84b069/8678c/IMG_0591.webp 110w,\n/static/ceb49c3c631485453e71e00d7f84b069/f282e/IMG_0591.webp 165w,\n/static/ceb49c3c631485453e71e00d7f84b069/a7b21/IMG_0591.webp 220w,\n/static/ceb49c3c631485453e71e00d7f84b069/63099/IMG_0591.webp 1182w","sizes":"(max-width: 110px) 100vw, 110px"}}}},"primary_tag":{"slug":"js","url":"https://backend.shahednasser.com/tag/js/","name":"Javascript","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1592609931095-54a2168ae893-2.jpeg","description":"Learn more about Javascript through tutorials, articles, and tips.","meta_title":null,"meta_description":"Learn more about Javascript through tutorials, articles and tips.","featureImageSharp":{"base":"photo-1592609931095-54a2168ae893-2.jpeg","publicURL":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/photo-1592609931095-54a2168ae893-2.jpeg","imageMeta":{"width":2000,"height":1333},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAANABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAwAEBf/EABUBAQEAAAAAAAAAAAAAAAAAAAAB/9oADAMBAAIQAxAAAAHh6QZDjq//xAAaEAEAAwADAAAAAAAAAAAAAAABAAIREiFB/9oACAEBAAEFApQ6eO+VXFWf/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPwE//8QAFREBAQAAAAAAAAAAAAAAAAAAEDH/2gAIAQIBAT8Bp//EABoQAAICAwAAAAAAAAAAAAAAAAABECExMkH/2gAIAQEABj8CwdNXFOP/xAAcEAADAAMAAwAAAAAAAAAAAAAAAREhQVFhcYH/2gAIAQEAAT8heHx6GaR4cOQ+jrqtTQu6lgaVs//aAAwDAQACAAMAAAAQlM//xAAWEQEBAQAAAAAAAAAAAAAAAAAAARH/2gAIAQMBAT8QrH//xAAWEQEBAQAAAAAAAAAAAAAAAAABEBH/2gAIAQIBAT8QdE//xAAcEAEAAgIDAQAAAAAAAAAAAAABABEhMUFhweH/2gAIAQEAAT8QwaQHozIjaNdvYnh0/qNZJwLU36JcXxL2lqf/2Q==","aspectRatio":1.5028901734104045,"src":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/d5c54/photo-1592609931095-54a2168ae893-2.jpg","srcSet":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/65d8c/photo-1592609931095-54a2168ae893-2.jpg 260w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/c5f21/photo-1592609931095-54a2168ae893-2.jpg 520w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/d5c54/photo-1592609931095-54a2168ae893-2.jpg 1040w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/81a53/photo-1592609931095-54a2168ae893-2.jpg 1560w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/4e5f3/photo-1592609931095-54a2168ae893-2.jpg 2000w","srcWebp":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/e4875/photo-1592609931095-54a2168ae893-2.webp","srcSetWebp":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/dc8f3/photo-1592609931095-54a2168ae893-2.webp 260w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/2db4b/photo-1592609931095-54a2168ae893-2.webp 520w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/e4875/photo-1592609931095-54a2168ae893-2.webp 1040w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/f5845/photo-1592609931095-54a2168ae893-2.webp 1560w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/49d6b/photo-1592609931095-54a2168ae893-2.webp 2000w","sizes":"(max-width: 1040px) 100vw, 1040px"}}}},"tags":[{"slug":"js","url":"https://backend.shahednasser.com/tag/js/","name":"Javascript","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1592609931095-54a2168ae893-2.jpeg","description":"Learn more about Javascript through tutorials, articles, and tips.","meta_title":null,"meta_description":"Learn more about Javascript through tutorials, articles and tips.","featureImageSharp":null},{"slug":"beginner","url":"https://backend.shahednasser.com/tag/beginner/","name":"Beginners","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1521185496955-15097b20c5fe-2.jpeg","description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","meta_title":"Beginners","meta_description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","featureImageSharp":null}],"plaintext":"Cookies in JavaScript are used to read from and store small data related to the\nuser on the browser.\n\nLocal Storage allows you to also read from and store data related to the user on\nthe browser using JavaScript's Storage API\n[https://developer.mozilla.org/en-US/docs/Web/API/Storage].\n\nIn this article, you'll learn about some of the main differences between local\nstorage and cookies and which you should choose for your websites.\n\nWhat are Cookies?\nCookies are pieces of data that are communicated between the server and the\nbrowser in the header of requests. This allows the server to learn more\ninformation about the user accessing the website but also gives you access in\nthe browser to interact with that data.\n\nAn example of using cookies is storing the user's authentication token when they\nare logged in. The server needs to have access to that cookie to authenticate\nthe user in later requests and retrieve data or process actions based on who the\nuser is.\n\nSimilarly, as a developer, you'll probably need access to that token to use it\nfor future requests to send to your server. \n\nCookies on the client-side (the browser) are natively accessed with \ndocument.cookies. When you store cookies on the browser, you can make them\nspecific to a path in a domain name and you can add an expiry date for them.\n\nWhat is the Local Storage?\nLocal Storage is used to read and write data in the browser's storage. The data\nis persistent and has no expiry date. The data is stored in key-value pairs. The\nserver has no access to the client's local storage.\n\nAn example of using local storage is storing the user's color mode preference\n(light or dark mode). This piece of information is generally not necessary for\nthe server to know, and is used to ensure that the user's preference is\nreflected on the website.\n\nLocal storage is specific to the protocol of a domain. So, the information\nreturned for a website with HTTP protocol is different than the information\nreturned for that same website with HTTPS protocol.\n\nLocal storage is accessed using window.localStorage. It's a read-only property\nwith methods like getItem and setItem to access and modify or add data to the\nlocal storage.\n\nWhat are the Differences Between Cookies and Local Storage\nAccess on the Server\nAs mentioned in the previous sections, the server can access the client's\ncookies but not the data stored in the client's storage.\n\nSo, in use cases where it's important for the server to have access to a set of\ndata, you should use cookies.\n\nData Size\nThere's a big difference between the size of data that cookies can hold and that\nof the local storage. For cookies, the maximum size is 4096 bytes, whereas for\nlocal storage it's 5MB.\n\nFor that reason, cookies should not be used to store large pieces of data. For\nexample, if you want to store the user's details in the browser then it's best\nto store them in the local storage.\n\nData Expiry\nCookies have an expiry date. You can set it to a very far away date, but it\nstill expires. On the other hand, data in the local storage does not expire and\nwill be available any time the user opens your website. The only way to clear\nlocal storage is either manually with code or if the user clears their browser\nstorage manually.\n\nBetter API\nUnless you're using a JavaScript library to facilitate this, it can be a hassle\nto read or write cookies using document.cookies as there is no straight way to\ndo it. Here's an example from W3Schools\n[https://www.w3schools.com/js/js_cookies.asp] of the code you'd need to use to\nget and set a cookie by name:\n\nfunction setCookie(cname, cvalue, exdays) {\n  const d = new Date();\n  d.setTime(d.getTime() + (exdays*24*60*60*1000));\n  let expires = \"expires=\"+ d.toUTCString();\n  document.cookie = cname + \"=\" + cvalue + \";\" + expires + \";path=/\";\n}\n\nfunction getCookie(cname) {\n  let name = cname + \"=\";\n  let decodedCookie = decodeURIComponent(document.cookie);\n  let ca = decodedCookie.split(';');\n  for(let i = 0; i <ca.length; i++) {\n    let c = ca[i];\n    while (c.charAt(0) == ' ') {\n      c = c.substring(1);\n    }\n    if (c.indexOf(name) == 0) {\n      return c.substring(name.length, c.length);\n    }\n  }\n  return \"\";\n}\n\nAs for local storage, it implements the Web Storage API\n[https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API] \nwhich contains easy-to-use methods to read and write data. Here's an example of\nsetting data in the storage and reading them:\n\nlocalStorage.setItem('name', 'Shahed');\n\n//later\nconst name = localStorage.getItem('name');\n\n\nWhich Should You Choose?\nFrom reading the differences and definitions this should be clear. However, to\nsummarize it and make it even clearer:\n\n 1. If you need to store data that is accessible for both the server and the\n    client, use cookies. Otherwise, use local storage.\n 2. If you need to store larger data, use local storage.\n 3. If you need to store data that does not expire, use local storage.\n 4. If you need easy-to-use methods to access and modify the data stored on the\n    client, use local storage.\n\nConclusion\nIf you're interested to learn more about cookies and local storage, check out\nMDN's documentation for cookies\n[https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie] and \nlocalStorage\n[https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage] for a\nmore thorough explanation of each.","html":"<p>Cookies in JavaScript are used to read from and store small data related to the user on the browser.</p><p>Local Storage allows you to also read from and store data related to the user on the browser using JavaScript's <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Storage\">Storage API</a>.</p><p>In this article, you'll learn about some of the main differences between local storage and cookies and which you should choose for your websites.</p><h2 id=\"what-are-cookies\">What are Cookies?</h2><p>Cookies are pieces of data that are communicated between the server and the browser in the header of requests. This allows the server to learn more information about the user accessing the website but also gives you access in the browser to interact with that data.</p><p>An example of using cookies is storing the user's authentication token when they are logged in. The server needs to have access to that cookie to authenticate the user in later requests and retrieve data or process actions based on who the user is.</p><p>Similarly, as a developer, you'll probably need access to that token to use it for future requests to send to your server. </p><p>Cookies on the client-side (the browser) are natively accessed with <code>document.cookies</code>. When you store cookies on the browser, you can make them specific to a path in a domain name and you can add an expiry date for them.</p><h2 id=\"what-is-the-local-storage\">What is the Local Storage?</h2><p>Local Storage is used to read and write data in the browser's storage. The data is persistent and has no expiry date. The data is stored in key-value pairs. The server has no access to the client's local storage.</p><p>An example of using local storage is storing the user's color mode preference (light or dark mode). This piece of information is generally not necessary for the server to know, and is used to ensure that the user's preference is reflected on the website.</p><p>Local storage is specific to the protocol of a domain. So, the information returned for a website with HTTP protocol is different than the information returned for that same website with HTTPS protocol.</p><p>Local storage is accessed using <code>window.localStorage</code>. It's a read-only property with methods like <code>getItem</code> and <code>setItem</code> to access and modify or add data to the local storage.</p><h2 id=\"what-are-the-differences-between-cookies-and-local-storage\">What are the Differences Between Cookies and Local Storage</h2><h3 id=\"access-on-the-server\">Access on the Server</h3><p>As mentioned in the previous sections, the server can access the client's cookies but not the data stored in the client's storage.</p><p>So, in use cases where it's important for the server to have access to a set of data, you should use cookies.</p><h3 id=\"data-size\">Data Size</h3><p>There's a big difference between the size of data that cookies can hold and that of the local storage. For cookies, the maximum size is 4096 bytes, whereas for local storage it's 5MB.</p><p>For that reason, cookies should not be used to store large pieces of data. For example, if you want to store the user's details in the browser then it's best to store them in the local storage.</p><h3 id=\"data-expiry\">Data Expiry</h3><p>Cookies have an expiry date. You can set it to a very far away date, but it still expires. On the other hand, data in the local storage does not expire and will be available any time the user opens your website. The only way to clear local storage is either manually with code or if the user clears their browser storage manually.</p><h3 id=\"better-api\">Better API</h3><p>Unless you're using a JavaScript library to facilitate this, it can be a hassle to read or write cookies using <code>document.cookies</code> as there is no straight way to do it. Here's an example from <a href=\"https://www.w3schools.com/js/js_cookies.asp\">W3Schools</a> of the code you'd need to use to get and set a cookie by name:</p><pre><code class=\"language-js\">function setCookie(cname, cvalue, exdays) {\n  const d = new Date();\n  d.setTime(d.getTime() + (exdays*24*60*60*1000));\n  let expires = \"expires=\"+ d.toUTCString();\n  document.cookie = cname + \"=\" + cvalue + \";\" + expires + \";path=/\";\n}\n\nfunction getCookie(cname) {\n  let name = cname + \"=\";\n  let decodedCookie = decodeURIComponent(document.cookie);\n  let ca = decodedCookie.split(';');\n  for(let i = 0; i &lt;ca.length; i++) {\n    let c = ca[i];\n    while (c.charAt(0) == ' ') {\n      c = c.substring(1);\n    }\n    if (c.indexOf(name) == 0) {\n      return c.substring(name.length, c.length);\n    }\n  }\n  return \"\";\n}</code></pre><p>As for local storage, it implements the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API\">Web Storage API</a> which contains easy-to-use methods to read and write data. Here's an example of setting data in the storage and reading them:</p><pre><code class=\"language-js\">localStorage.setItem('name', 'Shahed');\n\n//later\nconst name = localStorage.getItem('name');\n</code></pre><h2 id=\"which-should-you-choose\">Which Should You Choose?</h2><p>From reading the differences and definitions this should be clear. However, to summarize it and make it even clearer:</p><ol><li>If you need to store data that is accessible for both the server and the client, use cookies. Otherwise, use local storage.</li><li>If you need to store larger data, use local storage.</li><li>If you need to store data that does not expire, use local storage.</li><li>If you need easy-to-use methods to access and modify the data stored on the client, use local storage.</li></ol><h2 id=\"conclusion\">Conclusion</h2><p>If you're interested to learn more about cookies and local storage, check out MDN's documentation for <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie\">cookies</a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage\">localStorage</a> for a more thorough explanation of each. </p>","url":"https://backend.shahednasser.com/localstorage-vs-cookies-whats-the-difference/","canonical_url":null,"uuid":"47fde12d-6a2c-497f-8a8c-e66899a86bfd","codeinjection_foot":null,"codeinjection_head":null,"codeinjection_styles":null,"comment_id":"626e658e39840e1ac2875199","reading_time":3,"send_email_when_published":null,"email_subject":null,"childHtmlRehype":{"html":"<p>Cookies in JavaScript are used to read from and store small data related to the user on the browser.</p><p>Local Storage allows you to also read from and store data related to the user on the browser using JavaScript's <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Storage\">Storage API</a>.</p><p>In this article, you'll learn about some of the main differences between local storage and cookies and which you should choose for your websites.</p><h2 id=\"what-are-cookies\">What are Cookies?</h2><p>Cookies are pieces of data that are communicated between the server and the browser in the header of requests. This allows the server to learn more information about the user accessing the website but also gives you access in the browser to interact with that data.</p><p>An example of using cookies is storing the user's authentication token when they are logged in. The server needs to have access to that cookie to authenticate the user in later requests and retrieve data or process actions based on who the user is.</p><p>Similarly, as a developer, you'll probably need access to that token to use it for future requests to send to your server. </p><p>Cookies on the client-side (the browser) are natively accessed with <code class=\"language-text\">document.cookies</code>. When you store cookies on the browser, you can make them specific to a path in a domain name and you can add an expiry date for them.</p><h2 id=\"what-is-the-local-storage\">What is the Local Storage?</h2><p>Local Storage is used to read and write data in the browser's storage. The data is persistent and has no expiry date. The data is stored in key-value pairs. The server has no access to the client's local storage.</p><p>An example of using local storage is storing the user's color mode preference (light or dark mode). This piece of information is generally not necessary for the server to know, and is used to ensure that the user's preference is reflected on the website.</p><p>Local storage is specific to the protocol of a domain. So, the information returned for a website with HTTP protocol is different than the information returned for that same website with HTTPS protocol.</p><p>Local storage is accessed using <code class=\"language-text\">window.localStorage</code>. It's a read-only property with methods like <code class=\"language-text\">getItem</code> and <code class=\"language-text\">setItem</code> to access and modify or add data to the local storage.</p><h2 id=\"what-are-the-differences-between-cookies-and-local-storage\">What are the Differences Between Cookies and Local Storage</h2><h3 id=\"access-on-the-server\">Access on the Server</h3><p>As mentioned in the previous sections, the server can access the client's cookies but not the data stored in the client's storage.</p><p>So, in use cases where it's important for the server to have access to a set of data, you should use cookies.</p><h3 id=\"data-size\">Data Size</h3><p>There's a big difference between the size of data that cookies can hold and that of the local storage. For cookies, the maximum size is 4096 bytes, whereas for local storage it's 5MB.</p><p>For that reason, cookies should not be used to store large pieces of data. For example, if you want to store the user's details in the browser then it's best to store them in the local storage.</p><h3 id=\"data-expiry\">Data Expiry</h3><p>Cookies have an expiry date. You can set it to a very far away date, but it still expires. On the other hand, data in the local storage does not expire and will be available any time the user opens your website. The only way to clear local storage is either manually with code or if the user clears their browser storage manually.</p><h3 id=\"better-api\">Better API</h3><p>Unless you're using a JavaScript library to facilitate this, it can be a hassle to read or write cookies using <code class=\"language-text\">document.cookies</code> as there is no straight way to do it. Here's an example from <a href=\"https://www.w3schools.com/js/js_cookies.asp\">W3Schools</a> of the code you'd need to use to get and set a cookie by name:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">function</span> <span class=\"token function\">setCookie</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">cname<span class=\"token punctuation\">,</span> cvalue<span class=\"token punctuation\">,</span> exdays</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">const</span> d <span class=\"token operator\">=</span> <span class=\"token keyword\">new</span> <span class=\"token class-name\">Date</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  d<span class=\"token punctuation\">.</span><span class=\"token function\">setTime</span><span class=\"token punctuation\">(</span>d<span class=\"token punctuation\">.</span><span class=\"token function\">getTime</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">+</span> <span class=\"token punctuation\">(</span>exdays<span class=\"token operator\">*</span><span class=\"token number\">24</span><span class=\"token operator\">*</span><span class=\"token number\">60</span><span class=\"token operator\">*</span><span class=\"token number\">60</span><span class=\"token operator\">*</span><span class=\"token number\">1000</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> expires <span class=\"token operator\">=</span> <span class=\"token string\">\"expires=\"</span><span class=\"token operator\">+</span> d<span class=\"token punctuation\">.</span><span class=\"token function\">toUTCString</span><span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  document<span class=\"token punctuation\">.</span>cookie <span class=\"token operator\">=</span> cname <span class=\"token operator\">+</span> <span class=\"token string\">\"=\"</span> <span class=\"token operator\">+</span> cvalue <span class=\"token operator\">+</span> <span class=\"token string\">\";\"</span> <span class=\"token operator\">+</span> expires <span class=\"token operator\">+</span> <span class=\"token string\">\";path=/\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span>\n\n<span class=\"token keyword\">function</span> <span class=\"token function\">getCookie</span><span class=\"token punctuation\">(</span><span class=\"token parameter\">cname</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n  <span class=\"token keyword\">let</span> name <span class=\"token operator\">=</span> cname <span class=\"token operator\">+</span> <span class=\"token string\">\"=\"</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> decodedCookie <span class=\"token operator\">=</span> <span class=\"token function\">decodeURIComponent</span><span class=\"token punctuation\">(</span>document<span class=\"token punctuation\">.</span>cookie<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">let</span> ca <span class=\"token operator\">=</span> decodedCookie<span class=\"token punctuation\">.</span><span class=\"token function\">split</span><span class=\"token punctuation\">(</span><span class=\"token string\">';'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n  <span class=\"token keyword\">for</span><span class=\"token punctuation\">(</span><span class=\"token keyword\">let</span> i <span class=\"token operator\">=</span> <span class=\"token number\">0</span><span class=\"token punctuation\">;</span> i <span class=\"token operator\">&#x3C;</span>ca<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">;</span> i<span class=\"token operator\">++</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token keyword\">let</span> c <span class=\"token operator\">=</span> ca<span class=\"token punctuation\">[</span>i<span class=\"token punctuation\">]</span><span class=\"token punctuation\">;</span>\n    <span class=\"token keyword\">while</span> <span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">.</span><span class=\"token function\">charAt</span><span class=\"token punctuation\">(</span><span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">==</span> <span class=\"token string\">' '</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      c <span class=\"token operator\">=</span> c<span class=\"token punctuation\">.</span><span class=\"token function\">substring</span><span class=\"token punctuation\">(</span><span class=\"token number\">1</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n    <span class=\"token keyword\">if</span> <span class=\"token punctuation\">(</span>c<span class=\"token punctuation\">.</span><span class=\"token function\">indexOf</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">)</span> <span class=\"token operator\">==</span> <span class=\"token number\">0</span><span class=\"token punctuation\">)</span> <span class=\"token punctuation\">{</span>\n      <span class=\"token keyword\">return</span> c<span class=\"token punctuation\">.</span><span class=\"token function\">substring</span><span class=\"token punctuation\">(</span>name<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">,</span> c<span class=\"token punctuation\">.</span>length<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n    <span class=\"token punctuation\">}</span>\n  <span class=\"token punctuation\">}</span>\n  <span class=\"token keyword\">return</span> <span class=\"token string\">\"\"</span><span class=\"token punctuation\">;</span>\n<span class=\"token punctuation\">}</span></code></pre></div><p>As for local storage, it implements the <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API\">Web Storage API</a> which contains easy-to-use methods to read and write data. Here's an example of setting data in the storage and reading them:</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">localStorage<span class=\"token punctuation\">.</span><span class=\"token function\">setItem</span><span class=\"token punctuation\">(</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">,</span> <span class=\"token string\">'Shahed'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n\n<span class=\"token comment\">//later</span>\n<span class=\"token keyword\">const</span> name <span class=\"token operator\">=</span> localStorage<span class=\"token punctuation\">.</span><span class=\"token function\">getItem</span><span class=\"token punctuation\">(</span><span class=\"token string\">'name'</span><span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span>\n</code></pre></div><h2 id=\"which-should-you-choose\">Which Should You Choose?</h2><p>From reading the differences and definitions this should be clear. However, to summarize it and make it even clearer:</p><ol><li>If you need to store data that is accessible for both the server and the client, use cookies. Otherwise, use local storage.</li><li>If you need to store larger data, use local storage.</li><li>If you need to store data that does not expire, use local storage.</li><li>If you need easy-to-use methods to access and modify the data stored on the client, use local storage.</li></ol><h2 id=\"conclusion\">Conclusion</h2><p>If you're interested to learn more about cookies and local storage, check out MDN's documentation for <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie\">cookies</a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage\">localStorage</a> for a more thorough explanation of each. </p>","htmlAst":{"type":"root","children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Cookies in JavaScript are used to read from and store small data related to the user on the browser."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Local Storage allows you to also read from and store data related to the user on the browser using JavaScript's "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Storage"},"children":[{"type":"text","value":"Storage API"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"In this article, you'll learn about some of the main differences between local storage and cookies and which you should choose for your websites."}]},{"type":"element","tagName":"h2","properties":{"id":"what-are-cookies"},"children":[{"type":"text","value":"What are Cookies?"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Cookies are pieces of data that are communicated between the server and the browser in the header of requests. This allows the server to learn more information about the user accessing the website but also gives you access in the browser to interact with that data."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"An example of using cookies is storing the user's authentication token when they are logged in. The server needs to have access to that cookie to authenticate the user in later requests and retrieve data or process actions based on who the user is."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Similarly, as a developer, you'll probably need access to that token to use it for future requests to send to your server. "}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Cookies on the client-side (the browser) are natively accessed with "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"document.cookies"}]},{"type":"text","value":". When you store cookies on the browser, you can make them specific to a path in a domain name and you can add an expiry date for them."}]},{"type":"element","tagName":"h2","properties":{"id":"what-is-the-local-storage"},"children":[{"type":"text","value":"What is the Local Storage?"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Local Storage is used to read and write data in the browser's storage. The data is persistent and has no expiry date. The data is stored in key-value pairs. The server has no access to the client's local storage."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"An example of using local storage is storing the user's color mode preference (light or dark mode). This piece of information is generally not necessary for the server to know, and is used to ensure that the user's preference is reflected on the website."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Local storage is specific to the protocol of a domain. So, the information returned for a website with HTTP protocol is different than the information returned for that same website with HTTPS protocol."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Local storage is accessed using "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"window.localStorage"}]},{"type":"text","value":". It's a read-only property with methods like "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"getItem"}]},{"type":"text","value":" and "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"setItem"}]},{"type":"text","value":" to access and modify or add data to the local storage."}]},{"type":"element","tagName":"h2","properties":{"id":"what-are-the-differences-between-cookies-and-local-storage"},"children":[{"type":"text","value":"What are the Differences Between Cookies and Local Storage"}]},{"type":"element","tagName":"h3","properties":{"id":"access-on-the-server"},"children":[{"type":"text","value":"Access on the Server"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"As mentioned in the previous sections, the server can access the client's cookies but not the data stored in the client's storage."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"So, in use cases where it's important for the server to have access to a set of data, you should use cookies."}]},{"type":"element","tagName":"h3","properties":{"id":"data-size"},"children":[{"type":"text","value":"Data Size"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"There's a big difference between the size of data that cookies can hold and that of the local storage. For cookies, the maximum size is 4096 bytes, whereas for local storage it's 5MB."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For that reason, cookies should not be used to store large pieces of data. For example, if you want to store the user's details in the browser then it's best to store them in the local storage."}]},{"type":"element","tagName":"h3","properties":{"id":"data-expiry"},"children":[{"type":"text","value":"Data Expiry"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Cookies have an expiry date. You can set it to a very far away date, but it still expires. On the other hand, data in the local storage does not expire and will be available any time the user opens your website. The only way to clear local storage is either manually with code or if the user clears their browser storage manually."}]},{"type":"element","tagName":"h3","properties":{"id":"better-api"},"children":[{"type":"text","value":"Better API"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Unless you're using a JavaScript library to facilitate this, it can be a hassle to read or write cookies using "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"document.cookies"}]},{"type":"text","value":" as there is no straight way to do it. Here's an example from "},{"type":"element","tagName":"a","properties":{"href":"https://www.w3schools.com/js/js_cookies.asp"},"children":[{"type":"text","value":"W3Schools"}]},{"type":"text","value":" of the code you'd need to use to get and set a cookie by name:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"function"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"setCookie"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","parameter"]},"children":[{"type":"text","value":"cname"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" cvalue"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" exdays"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" d "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"new"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","class-name"]},"children":[{"type":"text","value":"Date"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n  d"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"setTime"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"d"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"getTime"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"exdays"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"24"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"60"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"60"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"*"}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1000"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"let"}]},{"type":"text","value":" expires "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"expires=\""}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" d"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"toUTCString"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n  document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"cookie "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" cname "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"=\""}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" cvalue "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\";\""}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" expires "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\";path=/\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"function"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"getCookie"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","parameter"]},"children":[{"type":"text","value":"cname"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"let"}]},{"type":"text","value":" name "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" cname "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"+"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"=\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"let"}]},{"type":"text","value":" decodedCookie "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"decodeURIComponent"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"document"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"cookie"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"let"}]},{"type":"text","value":" ca "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" decodedCookie"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"split"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"';'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"for"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"let"}]},{"type":"text","value":" i "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":" i "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"<"}]},{"type":"text","value":"ca"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"length"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":" i"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"++"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"let"}]},{"type":"text","value":" c "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" ca"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"text","value":"i"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"while"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"c"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"charAt"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"' '"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n      c "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" c"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"substring"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"1"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"if"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"c"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"indexOf"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"name"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","number"]},"children":[{"type":"text","value":"0"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n      "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" c"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"substring"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"name"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"length"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" c"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"length"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n  "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"As for local storage, it implements the "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Web_Storage_API/Using_the_Web_Storage_API"},"children":[{"type":"text","value":"Web Storage API"}]},{"type":"text","value":" which contains easy-to-use methods to read and write data. Here's an example of setting data in the storage and reading them:"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"localStorage"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"setItem"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'name'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'Shahed'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"//later"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"const"}]},{"type":"text","value":" name "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" localStorage"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"getItem"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'name'"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":"\n"}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"which-should-you-choose"},"children":[{"type":"text","value":"Which Should You Choose?"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"From reading the differences and definitions this should be clear. However, to summarize it and make it even clearer:"}]},{"type":"element","tagName":"ol","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"If you need to store data that is accessible for both the server and the client, use cookies. Otherwise, use local storage."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"If you need to store larger data, use local storage."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"If you need to store data that does not expire, use local storage."}]},{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"If you need easy-to-use methods to access and modify the data stored on the client, use local storage."}]}]},{"type":"element","tagName":"h2","properties":{"id":"conclusion"},"children":[{"type":"text","value":"Conclusion"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If you're interested to learn more about cookies and local storage, check out MDN's documentation for "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Document/cookie"},"children":[{"type":"text","value":"cookies"}]},{"type":"text","value":" and "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage"},"children":[{"type":"text","value":"localStorage"}]},{"type":"text","value":" for a more thorough explanation of each. "}]}],"data":{"quirksMode":false}},"tableOfContents":[{"id":"what-are-cookies","heading":"What are Cookies?"},{"id":"what-is-the-local-storage","heading":"What is the Local Storage?"},{"id":"what-are-the-differences-between-cookies-and-local-storage","heading":"What are the Differences Between Cookies and Local Storage","items":[{"id":"access-on-the-server","heading":"Access on the Server"},{"id":"data-size","heading":"Data Size"},{"id":"data-expiry","heading":"Data Expiry"},{"id":"better-api","heading":"Better API"}]},{"id":"which-should-you-choose","heading":"Which Should You Choose?"},{"id":"conclusion","heading":"Conclusion"}]},"featureImageSharp":{"base":"Local-Storage-vs-Cookies-What-s-the-Difference.jpg","publicURL":"/static/28f50e0a23d8f16f69da75473f01187c/Local-Storage-vs-Cookies-What-s-the-Difference.jpg","imageMeta":{"width":1560,"height":876},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAALABQDASIAAhEBAxEB/8QAFwABAAMAAAAAAAAAAAAAAAAAAAECBf/EABQBAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhADEAAAAdubgD//xAAYEAACAwAAAAAAAAAAAAAAAAAAARESIP/aAAgBAQABBQKzJef/xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAEDAQE/AT//xAAUEQEAAAAAAAAAAAAAAAAAAAAQ/9oACAECAQE/AT//xAAXEAADAQAAAAAAAAAAAAAAAAAAATIg/9oACAEBAAY/ApZOf//EABkQAQACAwAAAAAAAAAAAAAAAAEAESAxcf/aAAgBAQABPyFsaSDOx3H/2gAMAwEAAgADAAAAEIPP/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPxA//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPxA//8QAGRABAAMBAQAAAAAAAAAAAAAAAREhMQAg/9oACAEBAAE/ECAIOyXxIhOqK8//2Q==","aspectRatio":1.7857142857142858,"src":"/static/28f50e0a23d8f16f69da75473f01187c/ea4ab/Local-Storage-vs-Cookies-What-s-the-Difference.jpg","srcSet":"/static/28f50e0a23d8f16f69da75473f01187c/477ba/Local-Storage-vs-Cookies-What-s-the-Difference.jpg 175w,\n/static/28f50e0a23d8f16f69da75473f01187c/06776/Local-Storage-vs-Cookies-What-s-the-Difference.jpg 350w,\n/static/28f50e0a23d8f16f69da75473f01187c/ea4ab/Local-Storage-vs-Cookies-What-s-the-Difference.jpg 700w,\n/static/28f50e0a23d8f16f69da75473f01187c/3055e/Local-Storage-vs-Cookies-What-s-the-Difference.jpg 1050w,\n/static/28f50e0a23d8f16f69da75473f01187c/eff08/Local-Storage-vs-Cookies-What-s-the-Difference.jpg 1400w,\n/static/28f50e0a23d8f16f69da75473f01187c/81a53/Local-Storage-vs-Cookies-What-s-the-Difference.jpg 1560w","srcWebp":"/static/28f50e0a23d8f16f69da75473f01187c/89afa/Local-Storage-vs-Cookies-What-s-the-Difference.webp","srcSetWebp":"/static/28f50e0a23d8f16f69da75473f01187c/9fca7/Local-Storage-vs-Cookies-What-s-the-Difference.webp 175w,\n/static/28f50e0a23d8f16f69da75473f01187c/37a4e/Local-Storage-vs-Cookies-What-s-the-Difference.webp 350w,\n/static/28f50e0a23d8f16f69da75473f01187c/89afa/Local-Storage-vs-Cookies-What-s-the-Difference.webp 700w,\n/static/28f50e0a23d8f16f69da75473f01187c/78e7a/Local-Storage-vs-Cookies-What-s-the-Difference.webp 1050w,\n/static/28f50e0a23d8f16f69da75473f01187c/03d34/Local-Storage-vs-Cookies-What-s-the-Difference.webp 1400w,\n/static/28f50e0a23d8f16f69da75473f01187c/f5845/Local-Storage-vs-Cookies-What-s-the-Difference.webp 1560w","sizes":"(max-width: 700px) 100vw, 700px"}}}}},{"node":{"id":"Ghost__Post__6248411d39840e1ac2874da6","title":"Optional Chaining in JavaScript","slug":"optional-chaining-in-javascript","featured":true,"feature_image":"https://backend.shahednasser.com/content/images/2022/04/Optional-Chaining-in-JavaScript.jpg","excerpt":"In this article, you’ll learn how and when to use Optional Chaining.","custom_excerpt":"In this article, you’ll learn how and when to use Optional Chaining.","visibility":"public","created_at_pretty":"2 Apr 2022","published_at_pretty":"4 Apr 2022","updated_at_pretty":"4 Apr 2022","created_at":"2022-04-02T12:27:09.000+00:00","published_at":"2022-04-04T09:03:21.000+00:00","updated_at":"2022-04-04T09:03:21.000+00:00","meta_title":null,"meta_description":null,"og_description":null,"og_image":null,"og_title":null,"twitter_description":null,"twitter_image":null,"twitter_title":null,"authors":[{"slug":"murtuzaali","url":"https://backend.shahednasser.com/author/murtuzaali/","name":"Murtuzaali Surti","bio":"Front-end Web Developer, Aspiring Full Stack Developer and a Blogger","cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/04/277600836_682640706379781_1485924985509613504_n.jpg","location":null,"website":"https://murtuzaalisurti.github.io","twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":null}],"primary_author":{"slug":"murtuzaali","url":"https://backend.shahednasser.com/author/murtuzaali/","name":"Murtuzaali Surti","bio":"Front-end Web Developer, Aspiring Full Stack Developer and a Blogger","cover_image":null,"profile_image":"https://backend.shahednasser.com/content/images/2022/04/277600836_682640706379781_1485924985509613504_n.jpg","location":null,"website":"https://murtuzaalisurti.github.io","twitter":null,"facebook":null,"meta_title":null,"meta_description":null,"coverImageSharp":null,"profileImageSharp":{"base":"277600836_682640706379781_1485924985509613504_n.jpg","publicURL":"/static/ed3da967db374710d628636a2659c3e0/277600836_682640706379781_1485924985509613504_n.jpg","imageMeta":{"width":600,"height":629},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAAVABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAQDBf/EABUBAQEAAAAAAAAAAAAAAAAAAAAB/9oADAMBAAIQAxAAAAHh05Wy8oWaUBGD/8QAGRAAAwEBAQAAAAAAAAAAAAAAAQIDABIE/9oACAEBAAEFAkTtq+dpjQIFLAKmRuWe3Q3/xAAVEQEBAAAAAAAAAAAAAAAAAAABIP/aAAgBAwEBPwEI/8QAFBEBAAAAAAAAAAAAAAAAAAAAIP/aAAgBAgEBPwEf/8QAHRAAAQQCAwAAAAAAAAAAAAAAAQAQESEiMnGRsf/aAAgBAQAGPwKFfrZI0O2mLWgHDf/EABkQAQEAAwEAAAAAAAAAAAAAAAERABAhQf/aAAgBAQABPyFoMsiHLytFfDzEWFAJWpQCGlwGG5r1r//aAAwDAQACAAMAAAAQpAgA/8QAFxEBAQEBAAAAAAAAAAAAAAAAARARIf/aAAgBAwEBPxAEWanJ/8QAFxEBAQEBAAAAAAAAAAAAAAAAARARIf/aAAgBAgEBPxBUcmD2f//EAB8QAQABAwUBAQAAAAAAAAAAAAERABAxIUFRYYGRof/aAAgBAQABPxAtn45cB6pQhAwQFjJgh3+2E5Rvrb9qYQVtMfem0JulmgnW9R/aVCXk10t//9k=","aspectRatio":0.9655172413793104,"src":"/static/ed3da967db374710d628636a2659c3e0/31709/277600836_682640706379781_1485924985509613504_n.jpg","srcSet":"/static/ed3da967db374710d628636a2659c3e0/f340b/277600836_682640706379781_1485924985509613504_n.jpg 28w,\n/static/ed3da967db374710d628636a2659c3e0/22d64/277600836_682640706379781_1485924985509613504_n.jpg 55w,\n/static/ed3da967db374710d628636a2659c3e0/31709/277600836_682640706379781_1485924985509613504_n.jpg 110w,\n/static/ed3da967db374710d628636a2659c3e0/aa249/277600836_682640706379781_1485924985509613504_n.jpg 165w,\n/static/ed3da967db374710d628636a2659c3e0/0dc33/277600836_682640706379781_1485924985509613504_n.jpg 220w,\n/static/ed3da967db374710d628636a2659c3e0/c3638/277600836_682640706379781_1485924985509613504_n.jpg 600w","srcWebp":"/static/ed3da967db374710d628636a2659c3e0/8678c/277600836_682640706379781_1485924985509613504_n.webp","srcSetWebp":"/static/ed3da967db374710d628636a2659c3e0/59cda/277600836_682640706379781_1485924985509613504_n.webp 28w,\n/static/ed3da967db374710d628636a2659c3e0/7da75/277600836_682640706379781_1485924985509613504_n.webp 55w,\n/static/ed3da967db374710d628636a2659c3e0/8678c/277600836_682640706379781_1485924985509613504_n.webp 110w,\n/static/ed3da967db374710d628636a2659c3e0/f282e/277600836_682640706379781_1485924985509613504_n.webp 165w,\n/static/ed3da967db374710d628636a2659c3e0/a7b21/277600836_682640706379781_1485924985509613504_n.webp 220w,\n/static/ed3da967db374710d628636a2659c3e0/fc91b/277600836_682640706379781_1485924985509613504_n.webp 600w","sizes":"(max-width: 110px) 100vw, 110px"}}}},"primary_tag":{"slug":"js","url":"https://backend.shahednasser.com/tag/js/","name":"Javascript","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1592609931095-54a2168ae893-2.jpeg","description":"Learn more about Javascript through tutorials, articles, and tips.","meta_title":null,"meta_description":"Learn more about Javascript through tutorials, articles and tips.","featureImageSharp":{"base":"photo-1592609931095-54a2168ae893-2.jpeg","publicURL":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/photo-1592609931095-54a2168ae893-2.jpeg","imageMeta":{"width":2000,"height":1333},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAANABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAwAEBf/EABUBAQEAAAAAAAAAAAAAAAAAAAAB/9oADAMBAAIQAxAAAAHh6QZDjq//xAAaEAEAAwADAAAAAAAAAAAAAAABAAIREiFB/9oACAEBAAEFApQ6eO+VXFWf/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPwE//8QAFREBAQAAAAAAAAAAAAAAAAAAEDH/2gAIAQIBAT8Bp//EABoQAAICAwAAAAAAAAAAAAAAAAABECExMkH/2gAIAQEABj8CwdNXFOP/xAAcEAADAAMAAwAAAAAAAAAAAAAAAREhQVFhcYH/2gAIAQEAAT8heHx6GaR4cOQ+jrqtTQu6lgaVs//aAAwDAQACAAMAAAAQlM//xAAWEQEBAQAAAAAAAAAAAAAAAAAAARH/2gAIAQMBAT8QrH//xAAWEQEBAQAAAAAAAAAAAAAAAAABEBH/2gAIAQIBAT8QdE//xAAcEAEAAgIDAQAAAAAAAAAAAAABABEhMUFhweH/2gAIAQEAAT8QwaQHozIjaNdvYnh0/qNZJwLU36JcXxL2lqf/2Q==","aspectRatio":1.5028901734104045,"src":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/d5c54/photo-1592609931095-54a2168ae893-2.jpg","srcSet":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/65d8c/photo-1592609931095-54a2168ae893-2.jpg 260w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/c5f21/photo-1592609931095-54a2168ae893-2.jpg 520w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/d5c54/photo-1592609931095-54a2168ae893-2.jpg 1040w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/81a53/photo-1592609931095-54a2168ae893-2.jpg 1560w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/4e5f3/photo-1592609931095-54a2168ae893-2.jpg 2000w","srcWebp":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/e4875/photo-1592609931095-54a2168ae893-2.webp","srcSetWebp":"/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/dc8f3/photo-1592609931095-54a2168ae893-2.webp 260w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/2db4b/photo-1592609931095-54a2168ae893-2.webp 520w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/e4875/photo-1592609931095-54a2168ae893-2.webp 1040w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/f5845/photo-1592609931095-54a2168ae893-2.webp 1560w,\n/static/d0b2a96dbeaa1da6e72d54edc3ccc8e2/49d6b/photo-1592609931095-54a2168ae893-2.webp 2000w","sizes":"(max-width: 1040px) 100vw, 1040px"}}}},"tags":[{"slug":"js","url":"https://backend.shahednasser.com/tag/js/","name":"Javascript","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1592609931095-54a2168ae893-2.jpeg","description":"Learn more about Javascript through tutorials, articles, and tips.","meta_title":null,"meta_description":"Learn more about Javascript through tutorials, articles and tips.","featureImageSharp":null},{"slug":"beginner","url":"https://backend.shahednasser.com/tag/beginner/","name":"Beginners","visibility":"public","feature_image":"https://backend.shahednasser.com/content/images/2022/01/photo-1521185496955-15097b20c5fe-2.jpeg","description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","meta_title":"Beginners","meta_description":"Tutorials, articles, and tips to help beginners accelerate their journey in programming.","featureImageSharp":null}],"plaintext":"Optional Chaining in JavaScript is used to return undefined for accessing an\nobject property that doesn't exist and whose parent property is nullish (null or\nundefined).\n\nIf you are unaware that property exists or not and you want to avoid the error\nthat's being thrown, you may want to use optional chaining to get around with\nit.\n\nIn this article, you’ll learn how and when to use Optional Chaining. You’ll also\nlearn when not to use Optional Chaining in JavaScript.\n\nHow it Works\nFirst, let's explore what can go wrong when accessing a property in a nested\nobject.\n\nlet person = {\n    name: \"Murtuza\",\n    work: () => {\n        return \"Software Developer\"\n    },\n    socials: {\n        github: {\n            username: \"murtuzaalisurti\",\n            link: \"https://github.com/murtuzaalisurti\",\n            proUser: {\n                is: 'no'\n            }\n        },\n        linkedin: {\n            username: \"murtuzaali-surti\",\n            link: \"https://linkedin.com/in/murtuzaali-surti\"\n        },\n        twitter: {\n            username: \"murtuza_surti\",\n            link: \"https://twitter.com/murtuza_surti\"\n        }\n    }\n}\n\nIn the above object, let's try to access the property link nested within the\nproperty website. Can we?\n\nconsole.log(person.website.link); //an error will be thrown\n\nWe get an error,\n\nCannot read property 'link' of undefined\n\nThe property website doesn't exist in the object!\n\nBut, let's add the property website to the root object and set the value of it\nas null.\n\nwebsite: null\n\nLet's check if this works,\n\nconsole.log(person.website.link); //an error will be thrown\n\nWe get a similar error,\n\nCannot read property 'link' of null\n\nAs mentioned in the above definition, we can use optional chaining to handle\nthese types of errors! Here's how we can do that.\n\nSyntax\n// website: property to validate\n// link: property to access\nwebsite?.link\n\nThe operator ?. will check if the property on its left-hand side is null or\nundefined and if that's the case, then it will simply return undefined without\nthrowing any errors. In other words, this is also known as short-circuiting.\nOtherwise, it will return the value of the property on its right-hand side.\n\nNot just that, you can also invoke a function if it exists using optional\nchaining.\n\nperson.work?.(args)\n\nAlso, you can access properties using [] brackets.\n\nperson.socials.github?.[\"username\"]\n\nWhat You Can’t Do\n * You cannot apply optional chaining to the objects that are not declared yet.\n   For example:\n\nobject?.prop // object is not defined\n\nWe haven't declared object, thus it will throw an error.\n\n * You cannot assign a value to this expression. In other words, the optional\n   chaining expression can't be on the left-hand side.\n\nThe below code is not valid.\n\nperson.socials.github?.[\"username\"] = \"name\" // not valid\n\nWhen to Use Optional Chaining?\nIt's important to note that optional chaining should not be used when it's not\nnecessary to do so. Only use optional chaining when you know that the property\nthat you want to access is optional and not mandatory.\n\nFor example, in our object person, we can keep the social media platforms\noptional, so we are not sure if a user has a social media account or not on a\nparticular platform. For that, we can use optional chaining to check if a user\nhas a social media account on a particular platform and if it exists, get the\nusername.\n\nperson.socials.github?.[\"username\"]\n\nBut, if we place the optional chaining operator at the root object, then it\ndoesn't make any sense because the root object i.e. person must exist and if it\ndoesn't exist, we should get an error!\n\nConclusion\nIn this article, you learned what Optional Chaining in JavaScript is, how it\nworks when to use it, and when not to use it.\n\nTo learn more about how Optional Chaining works, make sure to check out the MDN\ndocumentation\n[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#specifications] \non it for more details.","html":"<p>Optional Chaining in JavaScript is used to return <code>undefined</code> for accessing an object property that doesn't exist and whose parent property is <em><strong>nullish (null or undefined).</strong></em></p><p>If you are unaware that property exists or not and you want to avoid the error that's being thrown, you may want to use optional chaining to get around with it.</p><p>In this article, you’ll learn how and when to use Optional Chaining. You’ll also learn when not to use Optional Chaining in JavaScript.</p><h2 id=\"how-it-works\">How it Works</h2><p>First, let's explore what can go wrong when accessing a property in a nested object.</p><pre><code class=\"language-js\">let person = {\n    name: \"Murtuza\",\n    work: () =&gt; {\n        return \"Software Developer\"\n    },\n    socials: {\n        github: {\n            username: \"murtuzaalisurti\",\n            link: \"https://github.com/murtuzaalisurti\",\n            proUser: {\n                is: 'no'\n            }\n        },\n        linkedin: {\n            username: \"murtuzaali-surti\",\n            link: \"https://linkedin.com/in/murtuzaali-surti\"\n        },\n        twitter: {\n            username: \"murtuza_surti\",\n            link: \"https://twitter.com/murtuza_surti\"\n        }\n    }\n}</code></pre><p>In the above object, let's try to access the property link nested within the property website. Can we?</p><pre><code class=\"language-js\">console.log(person.website.link); //an error will be thrown</code></pre><p>We get an error,</p><pre><code class=\"language-js\">Cannot read property 'link' of undefined</code></pre><p>The property website doesn't exist in the object!</p><p>But, let's add the property <code>website</code> to the root object and set the value of it as <code>null</code>.</p><pre><code class=\"language-js\">website: null</code></pre><p>Let's check if this works,</p><pre><code class=\"language-js\">console.log(person.website.link); //an error will be thrown</code></pre><p>We get a similar error,</p><pre><code class=\"language-js\">Cannot read property 'link' of null</code></pre><p>As mentioned in the above definition, we can use optional chaining to handle these types of errors! Here's how we can do that.</p><h2 id=\"syntax\">Syntax</h2><pre><code class=\"language-js\">// website: property to validate\n// link: property to access\nwebsite?.link</code></pre><p>The operator ?. will check if the property on its left-hand side is null or undefined and if that's the case, then it will simply return undefined without throwing any errors. In other words, this is also known as short-circuiting. Otherwise, it will return the value of the property on its right-hand side.</p><figure class=\"kg-card kg-image-card\"><img src=\"https://backend.shahednasser.com/content/images/2022/04/rUOx6qB.gif\" class=\"kg-image\" alt loading=\"lazy\" width=\"1141\" height=\"139\"></figure><p>Not just that, you can also invoke a function if it exists using optional chaining.</p><pre><code class=\"language-js\">person.work?.(args)</code></pre><p>Also, you can access properties using [] brackets.</p><pre><code class=\"language-js\">person.socials.github?.[\"username\"]</code></pre><h2 id=\"what-you-can%E2%80%99t-do\">What You Can’t Do</h2><ul><li>You cannot apply optional chaining to the objects that are not declared yet. For example:</li></ul><pre><code class=\"language-js\">object?.prop // object is not defined</code></pre><p>We haven't declared <code>object</code>, thus it will throw an error.</p><ul><li>You cannot assign a value to this expression. In other words, the optional chaining expression can't be on the left-hand side.</li></ul><p>The below code is not valid.</p><pre><code class=\"language-js\">person.socials.github?.[\"username\"] = \"name\" // not valid</code></pre><h2 id=\"when-to-use-optional-chaining\">When to Use Optional Chaining?</h2><p>It's important to note that optional chaining should not be used when it's not necessary to do so. Only use optional chaining when you know that the property that you want to access is optional and not mandatory.</p><p>For example, in our object <code>person</code>, we can keep the social media platforms optional, so we are not sure if a user has a social media account or not on a particular platform. For that, we can use optional chaining to check if a user has a social media account on a particular platform and if it exists, get the username.</p><pre><code class=\"language-js\">person.socials.github?.[\"username\"]</code></pre><p>But, if we place the optional chaining operator at the root object, then it doesn't make any sense because the root object i.e. person must exist and if it doesn't exist, we should get an error!</p><h2 id=\"conclusion\">Conclusion</h2><p>In this article, you learned what Optional Chaining in JavaScript is, how it works when to use it, and when not to use it.</p><p>To learn more about how Optional Chaining works, make sure to check out the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#specifications\">MDN documentation</a> on it for more details.</p>","url":"https://backend.shahednasser.com/optional-chaining-in-javascript/","canonical_url":"https://syntackle.live/blog/optional-chaining-in-javascript-D6SuXGtu0-K5hhtZUqqc/","uuid":"8880895a-5b7b-4f7d-9923-ef9d1b51dbb8","codeinjection_foot":null,"codeinjection_head":null,"codeinjection_styles":null,"comment_id":"6248411d39840e1ac2874da6","reading_time":3,"send_email_when_published":null,"email_subject":null,"childHtmlRehype":{"html":"<p>Optional Chaining in JavaScript is used to return <code class=\"language-text\">undefined</code> for accessing an object property that doesn't exist and whose parent property is <em><strong>nullish (null or undefined).</strong></em></p><p>If you are unaware that property exists or not and you want to avoid the error that's being thrown, you may want to use optional chaining to get around with it.</p><p>In this article, you’ll learn how and when to use Optional Chaining. You’ll also learn when not to use Optional Chaining in JavaScript.</p><h2 id=\"how-it-works\">How it Works</h2><p>First, let's explore what can go wrong when accessing a property in a nested object.</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token keyword\">let</span> person <span class=\"token operator\">=</span> <span class=\"token punctuation\">{</span>\n    <span class=\"token literal-property property\">name</span><span class=\"token operator\">:</span> <span class=\"token string\">\"Murtuza\"</span><span class=\"token punctuation\">,</span>\n    <span class=\"token function-variable function\">work</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">(</span><span class=\"token punctuation\">)</span> <span class=\"token operator\">=></span> <span class=\"token punctuation\">{</span>\n        <span class=\"token keyword\">return</span> <span class=\"token string\">\"Software Developer\"</span>\n    <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n    <span class=\"token literal-property property\">socials</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n        <span class=\"token literal-property property\">github</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">username</span><span class=\"token operator\">:</span> <span class=\"token string\">\"murtuzaalisurti\"</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">link</span><span class=\"token operator\">:</span> <span class=\"token string\">\"https://github.com/murtuzaalisurti\"</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">proUser</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n                <span class=\"token literal-property property\">is</span><span class=\"token operator\">:</span> <span class=\"token string\">'no'</span>\n            <span class=\"token punctuation\">}</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">linkedin</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">username</span><span class=\"token operator\">:</span> <span class=\"token string\">\"murtuzaali-surti\"</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">link</span><span class=\"token operator\">:</span> <span class=\"token string\">\"https://linkedin.com/in/murtuzaali-surti\"</span>\n        <span class=\"token punctuation\">}</span><span class=\"token punctuation\">,</span>\n        <span class=\"token literal-property property\">twitter</span><span class=\"token operator\">:</span> <span class=\"token punctuation\">{</span>\n            <span class=\"token literal-property property\">username</span><span class=\"token operator\">:</span> <span class=\"token string\">\"murtuza_surti\"</span><span class=\"token punctuation\">,</span>\n            <span class=\"token literal-property property\">link</span><span class=\"token operator\">:</span> <span class=\"token string\">\"https://twitter.com/murtuza_surti\"</span>\n        <span class=\"token punctuation\">}</span>\n    <span class=\"token punctuation\">}</span>\n<span class=\"token punctuation\">}</span></code></pre></div><p>In the above object, let's try to access the property link nested within the property website. Can we?</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>person<span class=\"token punctuation\">.</span>website<span class=\"token punctuation\">.</span>link<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//an error will be thrown</span></code></pre></div><p>We get an error,</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">Cannot read property <span class=\"token string\">'link'</span> <span class=\"token keyword\">of</span> <span class=\"token keyword\">undefined</span></code></pre></div><p>The property website doesn't exist in the object!</p><p>But, let's add the property <code class=\"language-text\">website</code> to the root object and set the value of it as <code class=\"language-text\">null</code>.</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token literal-property property\">website</span><span class=\"token operator\">:</span> <span class=\"token keyword\">null</span></code></pre></div><p>Let's check if this works,</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">console<span class=\"token punctuation\">.</span><span class=\"token function\">log</span><span class=\"token punctuation\">(</span>person<span class=\"token punctuation\">.</span>website<span class=\"token punctuation\">.</span>link<span class=\"token punctuation\">)</span><span class=\"token punctuation\">;</span> <span class=\"token comment\">//an error will be thrown</span></code></pre></div><p>We get a similar error,</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">Cannot read property <span class=\"token string\">'link'</span> <span class=\"token keyword\">of</span> <span class=\"token keyword\">null</span></code></pre></div><p>As mentioned in the above definition, we can use optional chaining to handle these types of errors! Here's how we can do that.</p><h2 id=\"syntax\">Syntax</h2><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\"><span class=\"token comment\">// website: property to validate</span>\n<span class=\"token comment\">// link: property to access</span>\nwebsite<span class=\"token operator\">?.</span>link</code></pre></div><p>The operator ?. will check if the property on its left-hand side is null or undefined and if that's the case, then it will simply return undefined without throwing any errors. In other words, this is also known as short-circuiting. Otherwise, it will return the value of the property on its right-hand side.</p><figure class=\"kg-card kg-image-card\"><img src=\"https://backend.shahednasser.com/content/images/2022/04/rUOx6qB.gif\" class=\"kg-image\" alt=\"\" loading=\"lazy\" width=\"1141\" height=\"139\"></figure><p>Not just that, you can also invoke a function if it exists using optional chaining.</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">person<span class=\"token punctuation\">.</span>work<span class=\"token operator\">?.</span><span class=\"token punctuation\">(</span>args<span class=\"token punctuation\">)</span></code></pre></div><p>Also, you can access properties using [] brackets.</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">person<span class=\"token punctuation\">.</span>socials<span class=\"token punctuation\">.</span>github<span class=\"token operator\">?.</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"username\"</span><span class=\"token punctuation\">]</span></code></pre></div><h2 id=\"what-you-can%E2%80%99t-do\">What You Can’t Do</h2><ul><li>You cannot apply optional chaining to the objects that are not declared yet. For example:</li></ul><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">object<span class=\"token operator\">?.</span>prop <span class=\"token comment\">// object is not defined</span></code></pre></div><p>We haven't declared <code class=\"language-text\">object</code>, thus it will throw an error.</p><ul><li>You cannot assign a value to this expression. In other words, the optional chaining expression can't be on the left-hand side.</li></ul><p>The below code is not valid.</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">person<span class=\"token punctuation\">.</span>socials<span class=\"token punctuation\">.</span>github<span class=\"token operator\">?.</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"username\"</span><span class=\"token punctuation\">]</span> <span class=\"token operator\">=</span> <span class=\"token string\">\"name\"</span> <span class=\"token comment\">// not valid</span></code></pre></div><h2 id=\"when-to-use-optional-chaining\">When to Use Optional Chaining?</h2><p>It's important to note that optional chaining should not be used when it's not necessary to do so. Only use optional chaining when you know that the property that you want to access is optional and not mandatory.</p><p>For example, in our object <code class=\"language-text\">person</code>, we can keep the social media platforms optional, so we are not sure if a user has a social media account or not on a particular platform. For that, we can use optional chaining to check if a user has a social media account on a particular platform and if it exists, get the username.</p><div class=\"kg-card kg-code-card gatsby-highlight\" data-language=\"js\"><pre class=\"language-js\"><code class=\"language-js\">person<span class=\"token punctuation\">.</span>socials<span class=\"token punctuation\">.</span>github<span class=\"token operator\">?.</span><span class=\"token punctuation\">[</span><span class=\"token string\">\"username\"</span><span class=\"token punctuation\">]</span></code></pre></div><p>But, if we place the optional chaining operator at the root object, then it doesn't make any sense because the root object i.e. person must exist and if it doesn't exist, we should get an error!</p><h2 id=\"conclusion\">Conclusion</h2><p>In this article, you learned what Optional Chaining in JavaScript is, how it works when to use it, and when not to use it.</p><p>To learn more about how Optional Chaining works, make sure to check out the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#specifications\">MDN documentation</a> on it for more details.</p>","htmlAst":{"type":"root","children":[{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Optional Chaining in JavaScript is used to return "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"undefined"}]},{"type":"text","value":" for accessing an object property that doesn't exist and whose parent property is "},{"type":"element","tagName":"em","properties":{},"children":[{"type":"element","tagName":"strong","properties":{},"children":[{"type":"text","value":"nullish (null or undefined)."}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"If you are unaware that property exists or not and you want to avoid the error that's being thrown, you may want to use optional chaining to get around with it."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"In this article, you’ll learn how and when to use Optional Chaining. You’ll also learn when not to use Optional Chaining in JavaScript."}]},{"type":"element","tagName":"h2","properties":{"id":"how-it-works"},"children":[{"type":"text","value":"How it Works"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"First, let's explore what can go wrong when accessing a property in a nested object."}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"let"}]},{"type":"text","value":" person "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"name"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Murtuza\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","function-variable","function"]},"children":[{"type":"text","value":"work"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"=>"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"return"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"Software Developer\""}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"socials"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"github"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n            "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"username"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"murtuzaalisurti\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n            "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"link"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"https://github.com/murtuzaalisurti\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n            "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"proUser"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n                "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"is"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'no'"}]},{"type":"text","value":"\n            "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"linkedin"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n            "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"username"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"murtuzaali-surti\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n            "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"link"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"https://linkedin.com/in/murtuzaali-surti\""}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"twitter"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"{"}]},{"type":"text","value":"\n            "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"username"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"murtuza_surti\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":","}]},{"type":"text","value":"\n            "},{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"link"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"https://twitter.com/murtuza_surti\""}]},{"type":"text","value":"\n        "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n    "},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"}"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"In the above object, let's try to access the property link nested within the property website. Can we?"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"console"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"website"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"link"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"//an error will be thrown"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"We get an error,"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"Cannot read property "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'link'"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"of"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"undefined"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The property website doesn't exist in the object!"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"But, let's add the property "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"website"}]},{"type":"text","value":" to the root object and set the value of it as "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"null"}]},{"type":"text","value":"."}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","literal-property","property"]},"children":[{"type":"text","value":"website"}]},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":":"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"null"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Let's check if this works,"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"console"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"element","tagName":"span","properties":{"className":["token","function"]},"children":[{"type":"text","value":"log"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"website"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"link"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":";"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"//an error will be thrown"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"We get a similar error,"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"Cannot read property "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"'link'"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"of"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","keyword"]},"children":[{"type":"text","value":"null"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"As mentioned in the above definition, we can use optional chaining to handle these types of errors! Here's how we can do that."}]},{"type":"element","tagName":"h2","properties":{"id":"syntax"},"children":[{"type":"text","value":"Syntax"}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"// website: property to validate"}]},{"type":"text","value":"\n"},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"// link: property to access"}]},{"type":"text","value":"\nwebsite"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"?."}]},{"type":"text","value":"link"}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The operator ?. will check if the property on its left-hand side is null or undefined and if that's the case, then it will simply return undefined without throwing any errors. In other words, this is also known as short-circuiting. Otherwise, it will return the value of the property on its right-hand side."}]},{"type":"element","tagName":"figure","properties":{"className":["kg-card","kg-image-card"]},"children":[{"type":"element","tagName":"img","properties":{"src":"https://backend.shahednasser.com/content/images/2022/04/rUOx6qB.gif","className":["kg-image"],"alt":"","loading":"lazy","width":1141,"height":139},"children":[]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Not just that, you can also invoke a function if it exists using optional chaining."}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"work"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"?."}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"("}]},{"type":"text","value":"args"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":")"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"Also, you can access properties using [] brackets."}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"socials"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"github"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"?."}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"username\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"what-you-can%E2%80%99t-do"},"children":[{"type":"text","value":"What You Can’t Do"}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"You cannot apply optional chaining to the objects that are not declared yet. For example:"}]}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"object"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"?."}]},{"type":"text","value":"prop "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"// object is not defined"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"We haven't declared "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"object"}]},{"type":"text","value":", thus it will throw an error."}]},{"type":"element","tagName":"ul","properties":{},"children":[{"type":"element","tagName":"li","properties":{},"children":[{"type":"text","value":"You cannot assign a value to this expression. In other words, the optional chaining expression can't be on the left-hand side."}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"The below code is not valid."}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"socials"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"github"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"?."}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"username\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"="}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"name\""}]},{"type":"text","value":" "},{"type":"element","tagName":"span","properties":{"className":["token","comment"]},"children":[{"type":"text","value":"// not valid"}]}]}]}]},{"type":"element","tagName":"h2","properties":{"id":"when-to-use-optional-chaining"},"children":[{"type":"text","value":"When to Use Optional Chaining?"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"It's important to note that optional chaining should not be used when it's not necessary to do so. Only use optional chaining when you know that the property that you want to access is optional and not mandatory."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"For example, in our object "},{"type":"element","tagName":"code","properties":{"className":["language-text"]},"children":[{"type":"text","value":"person"}]},{"type":"text","value":", we can keep the social media platforms optional, so we are not sure if a user has a social media account or not on a particular platform. For that, we can use optional chaining to check if a user has a social media account on a particular platform and if it exists, get the username."}]},{"type":"element","tagName":"div","properties":{"className":["kg-card","kg-code-card","gatsby-highlight"],"dataLanguage":"js"},"children":[{"type":"element","tagName":"pre","properties":{"className":["language-js"]},"children":[{"type":"element","tagName":"code","properties":{"className":["language-js"]},"children":[{"type":"text","value":"person"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"socials"},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"."}]},{"type":"text","value":"github"},{"type":"element","tagName":"span","properties":{"className":["token","operator"]},"children":[{"type":"text","value":"?."}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"["}]},{"type":"element","tagName":"span","properties":{"className":["token","string"]},"children":[{"type":"text","value":"\"username\""}]},{"type":"element","tagName":"span","properties":{"className":["token","punctuation"]},"children":[{"type":"text","value":"]"}]}]}]}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"But, if we place the optional chaining operator at the root object, then it doesn't make any sense because the root object i.e. person must exist and if it doesn't exist, we should get an error!"}]},{"type":"element","tagName":"h2","properties":{"id":"conclusion"},"children":[{"type":"text","value":"Conclusion"}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"In this article, you learned what Optional Chaining in JavaScript is, how it works when to use it, and when not to use it."}]},{"type":"element","tagName":"p","properties":{},"children":[{"type":"text","value":"To learn more about how Optional Chaining works, make sure to check out the "},{"type":"element","tagName":"a","properties":{"href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#specifications"},"children":[{"type":"text","value":"MDN documentation"}]},{"type":"text","value":" on it for more details."}]}],"data":{"quirksMode":false}},"tableOfContents":[{"id":"how-it-works","heading":"How it Works"},{"id":"syntax","heading":"Syntax"},{"id":"what-you-can%E2%80%99t-do","heading":"What You Can’t Do"},{"id":"when-to-use-optional-chaining","heading":"When to Use Optional Chaining?"},{"id":"conclusion","heading":"Conclusion"}]},"featureImageSharp":{"base":"Optional-Chaining-in-JavaScript.jpg","publicURL":"/static/d9ed2e7558824339cb9d44e26a029146/Optional-Chaining-in-JavaScript.jpg","imageMeta":{"width":1560,"height":876},"childImageSharp":{"fluid":{"base64":"data:image/jpeg;base64,/9j/2wBDABALDA4MChAODQ4SERATGCgaGBYWGDEjJR0oOjM9PDkzODdASFxOQERXRTc4UG1RV19iZ2hnPk1xeXBkeFxlZ2P/2wBDARESEhgVGC8aGi9jQjhCY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2NjY2P/wgARCAALABQDASIAAhEBAxEB/8QAFgABAQEAAAAAAAAAAAAAAAAAAAIF/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQACEAMQAAAB3VAD/8QAFhABAQEAAAAAAAAAAAAAAAAAEQAg/9oACAEBAAEFAmc//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPwE//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPwE//8QAFhABAQEAAAAAAAAAAAAAAAAAMQAg/9oACAEBAAY/AiM//8QAGhAAAgIDAAAAAAAAAAAAAAAAABEBUSAhQf/aAAgBAQABPyFrjXI3xYf/2gAMAwEAAgADAAAAEODP/8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAwEBPxA//8QAFBEBAAAAAAAAAAAAAAAAAAAAEP/aAAgBAgEBPxA//8QAHRABAAEDBQAAAAAAAAAAAAAAAREAICFBYaHB0f/aAAgBAQABPxBkQWNZM81h7T2kiVbGz//Z","aspectRatio":1.7857142857142858,"src":"/static/d9ed2e7558824339cb9d44e26a029146/ea4ab/Optional-Chaining-in-JavaScript.jpg","srcSet":"/static/d9ed2e7558824339cb9d44e26a029146/477ba/Optional-Chaining-in-JavaScript.jpg 175w,\n/static/d9ed2e7558824339cb9d44e26a029146/06776/Optional-Chaining-in-JavaScript.jpg 350w,\n/static/d9ed2e7558824339cb9d44e26a029146/ea4ab/Optional-Chaining-in-JavaScript.jpg 700w,\n/static/d9ed2e7558824339cb9d44e26a029146/3055e/Optional-Chaining-in-JavaScript.jpg 1050w,\n/static/d9ed2e7558824339cb9d44e26a029146/eff08/Optional-Chaining-in-JavaScript.jpg 1400w,\n/static/d9ed2e7558824339cb9d44e26a029146/81a53/Optional-Chaining-in-JavaScript.jpg 1560w","srcWebp":"/static/d9ed2e7558824339cb9d44e26a029146/89afa/Optional-Chaining-in-JavaScript.webp","srcSetWebp":"/static/d9ed2e7558824339cb9d44e26a029146/9fca7/Optional-Chaining-in-JavaScript.webp 175w,\n/static/d9ed2e7558824339cb9d44e26a029146/37a4e/Optional-Chaining-in-JavaScript.webp 350w,\n/static/d9ed2e7558824339cb9d44e26a029146/89afa/Optional-Chaining-in-JavaScript.webp 700w,\n/static/d9ed2e7558824339cb9d44e26a029146/78e7a/Optional-Chaining-in-JavaScript.webp 1050w,\n/static/d9ed2e7558824339cb9d44e26a029146/03d34/Optional-Chaining-in-JavaScript.webp 1400w,\n/static/d9ed2e7558824339cb9d44e26a029146/f5845/Optional-Chaining-in-JavaScript.webp 1560w","sizes":"(max-width: 700px) 100vw, 700px"}}}}}]}},"pageContext":{"slug":"best-websites-to-find-free-resources-for-frontend-web-developers-and-designers","prev":"quran-in-new-tab-chrome-extension","next":"css-variables-and-how-to-use-them","tag":"beginner","limit":3,"skip":0,"primaryTagCount":62,"collectionPaths":{}}},"staticQueryHashes":["1272700106","1676991999","2138873178","2546165603","2681841279","2938721187","293880488","3052966952","4156497161"]}