The error is telling you that the element you are trying to change the properties of is null. The reason for this is that your JavaScript code executes before your HTML element loads in.
Wrap your code in a window.onload function and it should work as intended.
window.onload = function(){ // rest of code }; Alternatively, you can also try adding the "defer" attribute to your script tag in HTML.
<script src="script.js" defer></script>