javascript修改样式问题

学习js时,通过element.style.样式的方法修改样式。但是谷歌报错,请教能人可以看一眼,感谢!

window.onload=function(){
var box1=document.getElementById("box1");
var btn01=document.getElementById("btn01");
btn01.onclick=function(){
box1.style.width="200px"; 
};
};

Uncaught TypeError: Cannot read properties of null (reading 'style')
at HTMLButtonElement.<anonymous>  

鞠躬致敬!

我想要达到的结果

`

var box1 是个空?

是不是不存在一个id为box1的元素。提供下你的 body标签部分的代码