JSFiddle - React, Tailwind, and code Playground

HTML

<a href ="#" id="donwload-link" onClick="myFunction()">download html content</a>

<script>
function myFunction() {
  var content = document.documentElement.innerHTML;
  download(content, "index", "txt")
  
}
function download(content, fileName, fileType) {
  var link = document.getElementById("donwload-link");
  var file = new Blob([content], {type: "txt"});
  var donwloadFile = fileName + "." + fileType;
  link.href = URL.createObjectURL(file);
  link.download = donwloadFile
}
</script>