DEV Community

Gaurav Singh
Gaurav Singh

Posted on

You can write whole website in just single web page.

I'm using :target for creating this repo

CSS

section {
  display: none;
}

section:target {
  display: block;
}
Enter fullscreen mode Exit fullscreen mode

HTML

<a href="#home">Home</a>
<a href="#about">About</a>

<section id="home">
You can create whole website just in single page.
</section>

<section id="about">
This is my tiny project. I'm love create code. I'm intersting for making code, program, websites.
</section>
Enter fullscreen mode Exit fullscreen mode

Every time you click on those links #home, #about.
Adding on your current URL.
:target is responding on any # value. You see section:target all section visible.

Top comments (2)

Collapse
 
ravavyr profile image
Ravavyr

Yes, but this is

  • Terrible for SEO [More pages is better, each one with custom urls]
  • Terrible for performance, If you have a 10 page site with images, you'd be loading all of it at once.

Still a neat trick though :)
The "target" bit might be useful in other situations, for example for "tab" navigation within content.

Collapse
 
gauravnumber profile image
Gaurav Singh

This idea may be best suitable for small, concise portfolio website.