Export html to docx format and maintain all styles in javascript

How to export html which contains multiple inline styles to word file(docx) ?
I tried below code

const header = "<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'><head><meta charset='utf-8'><title>Export</title></head><body>";
  const footer = '</body></html>';
  const html = header + htmlString + footer;
  const url = `data:application/vnd.ms-word;charset=utf-8,${encodeURIComponent(html)}`;
  const downloadLink = document.createElement('a');
  document.body.appendChild(downloadLink);
  downloadLink.href = url;
  const savedFileName = `${filename}.docx`;
  downloadLink.download = savedFileName;
  downloadLink.click();
  document.body.removeChild(downloadLink);

but it fails with docx(as expected since it requires to map each element to respective .docx format).