How to Password Protect a Website or a Single Page
A real password check happens on the server before the page is sent. Use your host's or site builder's page password setting, HTTP Basic authentication in Apache or Nginx, or proper member accounts. A password box written in JavaScript only hides the page in the browser; the content still arrives and anyone can read the source.
| Option | Protects content? | Best for |
|---|---|---|
| Builder or CMS page password | Yes, checked by the platform | One private page for a client or event |
| HTTP Basic auth (Apache, Nginx) | Yes, over HTTPS | A staging site or a whole folder |
| Member accounts | Yes, per person | Paid or long-running private areas |
| JavaScript prompt or hidden div | No | Nothing that matters |
Updated
Type a username and password to see the exact Authorization header a browser sends under Basic authentication, and how easily it turns back into plain text. It shows why Basic auth must only run over HTTPS. The encoding happens on your device; nothing is sent.
What Basic auth sends
Username: client
Password: spring-preview
The username cannot contain a colon, because the colon separates it from the password.
Header the browser sends with every request
Authorization: Basic Y2xpZW50OnNwcmluZy1wcmV2aWV3Decoded by anyone who sees the request
client:spring-previewBase64 is not encryption. Without HTTPS, this header gives the password away.
Server setups that really protect a folder
Create the password file with the htpasswd tool that ships with Apache (for example htpasswd -c /etc/apache2/.htpasswd client), and keep it outside the public web folder.
Apache: .htaccess in the folder to protect
Require valid-user lets in anyone listed in the password file.
AuthType Basic
AuthName "Private preview"
AuthUserFile /etc/apache2/.htpasswd
Require valid-userNginx: protect one location
Nginx reads the same htpasswd file format. Reload Nginx after editing.
location /preview/ {
auth_basic "Private preview";
auth_basic_user_file /etc/apache2/.htpasswd;
}What not to do: a JavaScript gate
Shown so you can recognise it. The password and the content are both in the file every visitor downloads.
<div id="secret" hidden>Client price list ...</div>
<script>
if (prompt("Password?") === "spring-preview") {
document.getElementById("secret").hidden = false;
}
</script>
Why script-only gates fail
A common tutorial adds a prompt() and compares the answer with a password written in the same script. The browser has already downloaded the full page, and the password sits in the source for anyone who presses view source. Turning off JavaScript skips the check altogether.
The same goes for content hidden with CSS. If the words are in the HTML, they are public.
Choosing between the real options
For one page you share with a client, the page password in your builder or CMS is the quickest safe choice. For a staging copy of a site, Basic auth on the server keeps the whole thing private, including from search engine crawlers.
When different people need different access, or you need to remove one person later, use accounts. A single shared password cannot be taken back from one person without changing it for everyone.
How it works
- Decide whether one shared password is enough or each person needs their own login.
- On a site builder or WordPress, look for a page visibility or password setting first.
- On your own server, add Basic authentication to the folder or location, with the password file kept outside the public web folder.
- Check that the site forces HTTPS, then test in a private browser window.
Tips
- Give Basic auth a long password that you use nowhere else, and change it when the project or preview ends.
- In WordPress, editors and administrators can see password protected posts in the Edit screen without the password.
- A protected page can still show its title. Do not put private details in the page title.
- Ask search engines not to show a private page with a noindex tag as well, but never rely on that as protection.
Frequently asked questions
Can I password protect a page with just HTML?
No. HTML has no way to check a password. Anything you put in the file is downloaded by every visitor, so the check has to happen on the server or platform.
Is HTTP Basic authentication secure?
Only over HTTPS. RFC 7617 points out that the password crosses the network in cleartext, because Base64 is an encoding, not encryption, and says the scheme should not protect sensitive information without something like HTTPS.
How do I password protect a page in WordPress?
Open the page or post, set Visibility to Password protected, enter a password and update. Visitors see the title and a password prompt instead of the content.
Can I protect a whole WordPress site?
WordPress's own documentation says hiding the entire site is not part of core, and points to plugins or server rules such as .htaccess.
What does the browser show for Basic auth?
The server answers with 401 and a WWW-Authenticate header. The browser then asks for a username and password and repeats the request with an Authorization header.
Related: 401 vs 403, Next.js authentication guide, Make a membership website, HTTP status codes.
Build your site free or see all free tools. On We.Inc you can build your site free, with no card and no trial needed to start. AI building is on paid plans from $19 a month.
More in Guides
- How to Price a Product: Cost-Plus, Keystone, Margin vs Markup (Worked Examples) | How-to Guide
- How to Price Your Services for Maximum Profit | How-to Guide
- How to Publish a Website: Domain, Hosting and Launch Checks | How-to Guide
- How to Qualify Leads: Focus on the Right Prospects
- How to Rank in the Google Map Pack | How-to Guide
- How to Reduce Customer Churn and Increase Retention
- How to Remove a Google Review: Report, Track, Appeal
- How to Reply to Google Reviews (Good and Bad) | How-to Guide
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App