If you just want to run your code to test site functionality...etc. You can do that by simply opening the html pages locally on your computer using a browser. I suggest Google Chrome or Firefox. You typically need to pay to register your domain name which is not expensive at all.
Hosting fees are what is costly and dependent upon how much backend support you need or want from the host. However if your looking to launch a simple portfolio or some other static site check out Netlify. They have paid hosting services but offer free static hosting as well.
I am currently looking into the free version to launch my flagship portfolio with Netlify hopefully by February. I have already registered my domain name through HostGator. I would purchase services with them but I am not yet employed and its hard to find web dev work when you dont have a website lol
Hope this helped. Good luck!
You should look at free hosting websites and see what they have to offer. Mostly ones that are well known and respected and have paid plans and a free limited plan are the safest IMO.
If they ask for too much personal info, dont even bother.
If they ask for credit card or similar, dont bother.
The only unsafe thing, other than asking for personal info., is getting your website hacked, but the host is the one that gets in trouble not you ;)