To achieve this, you can utilize CSS by including the css file in a boilerplate setup and having all your html files reference that boilerplate, which is considered best practice.
In your file.css:
body {
font-family: monospace, Times, serif;
}
In the head section of your html file:
<link rel="stylesheet" href=":pathToCssFile">
Replace :pathToCssFile with the relative path to your css file, such as ./css/file.css
.
If you prefer to change the font style by clicking a button, you can do so using JavaScript:
const btn = document.querySelector(".btnClass");
btn.addEventListener("click", e =>{
document.body.style.fontFamily = "monospace, Times, serif"
});
Alternatively, you can set the font style using JavaScript when the page loads by adding this script directly in the html (although using CSS is recommended):
<script>
document.body.style.fontFamily = "monospace, Times, serif"
</script>