{"id":3635,"date":"2022-10-07T22:10:07","date_gmt":"2022-10-07T17:10:07","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=3635"},"modified":"2022-10-07T22:10:09","modified_gmt":"2022-10-07T17:10:09","slug":"how-to-save-text-as-file-using-html5-css3-javascript","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/","title":{"rendered":"How to Save Text as File using HTML5, CSS3 &#038; JavaScript"},"content":{"rendered":"\n<p>In this tutorial, I will teach you <strong>how to save the text as a file<\/strong> using HTML5, CSS3 &amp; JavaScript. The complete source code of this <strong>JavaScript save text as file<\/strong> project is given below.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">index.html<\/h3>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;htmlmixed&quot;,&quot;mime&quot;:&quot;text\/html&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;HTML&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;html&quot;}\">&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;\n  &lt;head&gt;\n    &lt;meta charset=&quot;utf-8&quot;&gt;\n    &lt;title&gt;Save Text As File using JavaScript&lt;\/title&gt;\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;style.css&quot;&gt;\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n    &lt;script src=&quot;script.js&quot; defer&gt;&lt;\/script&gt;\n  &lt;\/head&gt;\n  &lt;body&gt;\n    &lt;div class=&quot;wrapper&quot;&gt;\n      &lt;textarea spellcheck=&quot;false&quot; placeholder=&quot;Enter something to save&quot; required&gt;Lorem Ipsum is simply dummy text of the printing and type setting industry. Lorem Ipsuam has been the industries standard dummy texts ever since this 1500s, when an unknown printer took a galley of type and scrambled it to make a type of dollar specimen book. It have survived not only five centuries, but also from the leap into electronic typesetting.&lt;\/textarea&gt;\n      &lt;div class=&quot;file-options&quot;&gt;\n        &lt;div class=&quot;option file-name&quot;&gt;\n          &lt;label&gt;File name&lt;\/label&gt;\n          &lt;input type=&quot;text&quot; spellcheck=&quot;false&quot; placeholder=&quot;Enter file name&quot;&gt;\n        &lt;\/div&gt;\n        &lt;div class=&quot;option save-as&quot;&gt;\n          &lt;label&gt;Save as&lt;\/label&gt;\n          &lt;div class=&quot;select-menu&quot;&gt;\n            &lt;select&gt;\n              &lt;option value=&quot;text\/plain&quot;&gt;Text File (.txt)&lt;\/option&gt;\n              &lt;option value=&quot;text\/javascript&quot;&gt;JS File (.js)&lt;\/option&gt;\n              &lt;option value=&quot;text\/html&quot;&gt;HTML File (.html)&lt;\/option&gt;\n              &lt;option value=&quot;image\/svg+xml&quot;&gt;SVG File (.svg)&lt;\/option&gt;\n              &lt;option value=&quot;application\/msword&quot;&gt;Doc File (.doc)&lt;\/option&gt;\n              &lt;option value=&quot;application\/vnd.ms-powerpoint&quot;&gt;PPT File (.ppt)&lt;\/option&gt;\n            &lt;\/select&gt;\n          &lt;\/div&gt;\n        &lt;\/div&gt;\n      &lt;\/div&gt;\n      &lt;button class=&quot;save-btn&quot; type=&quot;button&quot;&gt;Save As Text File&lt;\/button&gt;\n    &lt;\/div&gt;\n    \n  &lt;\/body&gt;\n&lt;\/html&gt;<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">script.js<\/h3>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">const textarea = document.querySelector(&quot;textarea&quot;),\nfileNameInput = document.querySelector(&quot;.file-name input&quot;),\nselectMenu = document.querySelector(&quot;.save-as select&quot;),\nsaveBtn = document.querySelector(&quot;.save-btn&quot;);\n\nselectMenu.addEventListener(&quot;change&quot;, () =&gt; {\n    const selectedFormat = selectMenu.options[selectMenu.selectedIndex].text;\n    saveBtn.innerText = `Save As ${selectedFormat.split(&quot; &quot;)[0]} File`;\n});\n\nsaveBtn.addEventListener(&quot;click&quot;, () =&gt; {\n    const blob = new Blob([textarea.value], {type: selectMenu.value});\n    const fileUrl = URL.createObjectURL(blob);\n    const link = document.createElement(&quot;a&quot;);\n    link.download = fileNameInput.value;\n    link.href = fileUrl;\n    link.click();\n});<\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">style.css<\/h3>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;css&quot;,&quot;mime&quot;:&quot;text\/css&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;CSS&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;css&quot;}\">\/* Import Google font - Poppins *\/\n@import url('https:\/\/fonts.googleapis.com\/css2?family=Poppins:wght@400;500;600&amp;display=swap');\n*{\n  margin: 0;\n  padding: 0;\n  box-sizing: border-box;\n  font-family: 'Poppins', sans-serif;\n}\nbody{\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  min-height: 100vh;\n  padding: 10px;\n  background: #17A2B8;\n}\n.wrapper{\n  width: 443px;\n  border-radius: 7px;\n  background: #fff;\n  padding: 30px 25px 40px;\n  box-shadow: 0 10px 15px rgba(0,0,0,0.05);\n}\n.wrapper :where(textarea, input, select, button){\n  width: 100%;\n  outline: none;\n  border: none;\n  font-size: 17px;\n  border-radius: 5px;\n}\n.wrapper :where(textarea, input)::placeholder{\n  color: #aaa;\n}\n.wrapper :where(textarea, input):focus{\n  box-shadow: 0px 2px 4px rgba(0,0,0,0.08);\n}\n.wrapper textarea{\n  height: 270px;\n  resize: none;\n  padding: 8px 13px;\n  font-size: 17.6px;\n  border: 1px solid #ccc;\n}\n.wrapper .file-options{\n  display: flex;\n  margin-top: 10px;\n  align-items: center;\n  justify-content: space-between;\n}\n.file-options .option{\n  width: calc(100% \/ 2 - 8px);\n}\n.option label{\n  font-size: 17px;\n}\n.option :where(input, .select-menu){\n  height: 50px;\n  padding: 0 13px;\n  margin-top: 6px;\n  border-radius: 5px;\n  border: 1px solid #bfbfbf;\n}\n.option .select-menu select{\n  height: 50px;\n  background: none;\n}\n.wrapper .save-btn{\n  color: #fff;\n  cursor: pointer;\n  opacity: 0.6;\n  padding: 16px 0;\n  margin-top: 20px;\n  pointer-events: none;\n  background: #17A2B8;\n}\n.save-btn:hover{\n  background: #148c9f;\n}\ntextarea:valid ~ .save-btn{\n  opacity: 1;\n  pointer-events: auto;\n  transition: all 0.3s ease;\n}\n\n@media screen and (max-width: 475px) {\n  .wrapper{\n    padding: 25px 18px 30px;\n  }\n  .wrapper :where(textarea, input, select, button, label){\n    font-size: 16px!important;\n  }\n  .file-options .option{\n    width: calc(100% \/ 2 - 5px);\n  }\n  .option :where(input, .select-menu){\n    padding: 0 10px;\n  }\n  .wrapper .save-btn{\n    padding: 15px 0;\n  }\n}<\/pre><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, I will teach you how to save the text as a file using HTML5, CSS3 &amp; JavaScript. The complete source code of this JavaScript save text as file project is given below. index.html script.js style.css<\/p>\n","protected":false},"author":1,"featured_media":3637,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-3635","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Save Text as File using HTML5, CSS3 &amp; JavaScript<\/title>\n<meta name=\"description\" content=\"In this tutorial, I will teach you how to save the text as a file using HTML5, CSS3 &amp; JavaScript. The complete source code of this JavaScript save\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Save Text as File using HTML5, CSS3 &amp; JavaScript\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, I will teach you how to save the text as a file using HTML5, CSS3 &amp; JavaScript. The complete source code of this JavaScript save\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-10-07T17:10:07+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-10-07T17:10:09+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/10\/How-to-Save-Text-As-File-in-HTML-CSS-JavaScript-Convert-Text-to-File-in-JavaScript.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Save Text as File using HTML5, CSS3 & JavaScript","description":"In this tutorial, I will teach you how to save the text as a file using HTML5, CSS3 &amp; JavaScript. The complete source code of this JavaScript save","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/","og_locale":"en_US","og_type":"article","og_title":"How to Save Text as File using HTML5, CSS3 & JavaScript","og_description":"In this tutorial, I will teach you how to save the text as a file using HTML5, CSS3 &amp; JavaScript. The complete source code of this JavaScript save","og_url":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-10-07T17:10:07+00:00","article_modified_time":"2022-10-07T17:10:09+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/10\/How-to-Save-Text-As-File-in-HTML-CSS-JavaScript-Convert-Text-to-File-in-JavaScript.jpg","type":"image\/jpeg"}],"author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"How to Save Text as File using HTML5, CSS3 &#038; JavaScript","datePublished":"2022-10-07T17:10:07+00:00","dateModified":"2022-10-07T17:10:09+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/"},"wordCount":51,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/10\/How-to-Save-Text-As-File-in-HTML-CSS-JavaScript-Convert-Text-to-File-in-JavaScript.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/","url":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/","name":"How to Save Text as File using HTML5, CSS3 & JavaScript","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/10\/How-to-Save-Text-As-File-in-HTML-CSS-JavaScript-Convert-Text-to-File-in-JavaScript.jpg","datePublished":"2022-10-07T17:10:07+00:00","dateModified":"2022-10-07T17:10:09+00:00","description":"In this tutorial, I will teach you how to save the text as a file using HTML5, CSS3 &amp; JavaScript. The complete source code of this JavaScript save","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/10\/How-to-Save-Text-As-File-in-HTML-CSS-JavaScript-Convert-Text-to-File-in-JavaScript.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/10\/How-to-Save-Text-As-File-in-HTML-CSS-JavaScript-Convert-Text-to-File-in-JavaScript.jpg","width":1280,"height":720,"caption":"How to Save Text as File using HTML5, CSS3 & JavaScript"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/how-to-save-text-as-file-using-html5-css3-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Save Text as File using HTML5, CSS3 &#038; JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/3635","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=3635"}],"version-history":[{"count":1,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/3635\/revisions"}],"predecessor-version":[{"id":3636,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/3635\/revisions\/3636"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/3637"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=3635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=3635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=3635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}