{"id":333428,"date":"2021-01-28T12:23:15","date_gmt":"2021-01-28T20:23:15","guid":{"rendered":"https:\/\/css-tricks.com\/?p=333428"},"modified":"2021-01-28T12:23:25","modified_gmt":"2021-01-28T20:23:25","slug":"a-whole-website-in-a-single-html-file","status":"publish","type":"post","link":"https:\/\/css-tricks.com\/a-whole-website-in-a-single-html-file\/","title":{"rendered":"A Whole Website in a Single HTML File"},"content":{"rendered":"\n

I can\u2019t stop thinking about this site<\/a>. It looks like a pretty standard fare; a website with links to different pages. Nothing to write home about except that… the whole website is contained within a single HTML file<\/strong>.<\/p>\n\n\n\n

What about clicking the navigation links, you ask? Each link merely shows and hides certain parts of the HTML.<\/p>\n\n\n\n\n\n\n\n

<section id=\"home\">\n  <!-- home content goes here -->\n<\/section>\n<section id=\"about\">\n  <!-- about page goes here -->\n<\/section><\/code><\/pre>\n\n\n\n

Each <section><\/code> is hidden with CSS:<\/p>\n\n\n\n

section { display: none; }<\/code><\/pre>\n\n\n\n

Each link in the main navigation points to an anchor on the page:<\/p>\n\n\n\n

<a href=\"#home\">Home<\/a>\n<a href=\"#about\">About<\/a><\/code><\/pre>\n\n\n\n

And once you click a link, the <section><\/code> for that particular link is displayed via:<\/p>\n\n\n\n

section:target { display: block; }<\/code><\/pre>\n\n\n\n

See that :target<\/a><\/code> pseudo selector? That’s the magic! Sure, it’s been around for years, but this is a clever way to use it for sure. Most times, it’s used to highlight the anchor on the page once an anchor link to it has been clicked. That’s a handy way to help the user know where they’ve just jumped to.<\/p>\n\n\n\n