This isn’t about how your website is designed — as you note, the HTML doesn’t change. It’s about how your site is hosted.
When you use https, the connection requested by your browser is different. Behind the scenes, https is a completely different protocol than http. Your web server needs to understand and support that for your site.
How you make that happen isn’t standard, but it is getting easier.