Guides / Static Hosting
How to Password Protect an HTML Page or Website
To password protect an HTML page, the password has to be checked by the server before it sends the page. A password prompt written in the page's own JavaScript does not protect anything, because the page and the password are already in the visitor's browser. On a static website that leaves three methods that work: your host's built-in password protection, HTTP basic auth on a server you run, or encrypting the page.
Why a JavaScript password does not protect a page
A JavaScript password check runs after the whole page has been downloaded. The usual snippet asks for a password with prompt(), compares it to a value written in the script, and hides or shows the content. Anyone who opens the page source, or turns JavaScript off, sees the content and the password itself.
It is fine for keeping a page out of sight of a casual visitor. It is not fine for anything private: client work before launch, a price list, internal notes or personal documents.
Three methods that do protect a page
1. Your host's built-in password protection
The simplest method is a password your host checks for you. The visitor sees a password screen, and the server sends the page only after the right password is entered. Nothing changes in your HTML.
Hosts differ a lot here, as of mid 2026:
- Static.app: a password for the whole website or for single pages, on any paid plan.
- Netlify: managed password protection on the Pro plan ($20/mo).
- Vercel: on Enterprise, or as a $150/mo add-on on Pro.
- Tiiny Host: from the Solo tier ($18/mo).
- GitHub Pages: no password option.
- Cloudflare Pages: no one-click option; it needs Cloudflare Access (Zero Trust).
2. HTTP basic auth on a server you run
If you run your own Apache or nginx server, basic auth makes the browser ask for a username and password before the server sends anything. On Apache you add an .htaccess file that points to an .htpasswd file with the hashed password. On nginx you use the auth_basic and auth_basic_user_file directives.
# .htaccess (Apache)
AuthType Basic
AuthName "Private"
AuthUserFile /full/path/to/.htpasswd
Require valid-user
This only works where you control the server. Most static hosts, Static.app included, do not read .htaccess files, so on those use the host's own password setting instead.
3. Encrypt the page itself
Tools such as the open-source StatiCrypt encrypt your HTML with a password, so the file a visitor downloads is unreadable until the right password decrypts it in the browser. It works on any host, including free ones. The protection is only as good as the password, because anyone can download the encrypted file and try passwords offline, so use a long one. Changing the password means encrypting and uploading the page again.
How to password protect a website on Static.app
Static.app checks the password on the server, so the page is never sent until the visitor enters it. It takes one setting and works on a free subdomain or your own domain.
Protect the whole website
- Open your website in the dashboard and go to its Settings.
- Open Password Protection and turn it on.
- Enter the password visitors will need and save.
Protect one page
- Open your website's pages and choose the page.
- In the page settings, turn on Locked with a password and enter a password.
- Save. The rest of the website stays public.
A website password takes priority: while it is on, page passwords are ignored, because every page already asks for the website password. Password protection needs a paid plan, from $6 a month after the 7-day free trial.
What visitors see
A visitor who opens the link gets a password screen at the same address. After the right password the page loads as normal. Send the link and the password separately, for example the link by email and the password by message. To stop someone's access, change the password.
Common questions
Is a JavaScript password prompt safe?
No. The page and the password are both in the files the browser downloads, so anyone can read them in the page source. Use a password your host or server checks, or encrypt the page.
Can I protect one page and keep the rest public?
Yes. On Static.app you set a password on a single page in its page settings, and every other page stays public.
Does password protection work with a custom domain?
Yes. On Static.app the password screen appears on your own domain as well as on the free staticdomains.app address.
Can search engines see a password protected page?
No. A page behind a server-side password is not sent until someone enters the password, so search engines cannot read or index it. A page hidden with JavaScript is in the HTML and can still be indexed.
Ready to try it?
Protect your website