If I understand you right, the closest thing to this natively is probably web components. They have really good support across browsers now, and they would accomplish what you want without adding extra javascript to weigh your site down.
You could also learn and use a javascript framework like Astro, Svelte, Vue, React, etc. which are all industry-standard frameworks built to break your website down into a ton of reusable components and keep things organized. I like Svelte or Astro because they feel closer to vanilla HTML/CSS/JS to me. Here's the official interactive tutorial for Svelte if you want to mess around with it: learn.svelte.dev
PHP does have "includes" too if you want to go that route