Remove the default browser header and footer when printing HTML

javascript

You can remove the default browser header and footer when printing HTML by using the @media print CSS rule. Here’s an example of how to do it:

@media print {
  /* Hide the default header and footer */
  @page {
    size: auto;
    margin: 0;
  }

  /* Show only the content to be printed */
  body {
    margin: 0;
    padding: 0;
  }
}

In this example, we use the @media print rule to specify the styles to be applied when the content is printed.

We use the @page rule to hide the default header and footer by setting the page size to auto and the margin to 0. This removes any default margins or headers/footers that may be added by the browser.

We use the body element to show only the content to be printed by setting the margin and padding to 0. This removes any extra space around the content and ensures that only the content is printed.

You can add this CSS to your HTML file using a