How to Add Password Protection to Your Website
Learn how to add password protection to your website or specific pages. Compare methods from simple .htpasswd to built-in builder features.
Sometimes you need to keep parts of your website private. Maybe you are building a portfolio that is only for potential clients. Maybe you have a staging site you are not ready to share publicly. Or maybe you are creating a members-only resource area. Whatever the reason, password protection lets you control who sees your content.
This guide covers multiple approaches to adding password protection, from the simplest no-code options to more technical server-level solutions. Choose the method that matches your skill level and needs.
When to Use Password Protection
Before adding a password to your site, make sure it is the right solution for your situation. Password protection is appropriate for:
- Client preview sites: Sharing work-in-progress designs with specific clients before public launch.
- Staging and development sites: Keeping test versions of your site hidden from search engines and the public.
- Private portfolios: Showcasing sensitive or NDA-protected work that cannot be publicly visible.
- Members-only content: Offering exclusive resources to a community, course students, or paying customers.
- Internal company pages: Sharing documents, guides, or tools within an organization.
Password protection is not a substitute for proper authentication if you are handling sensitive data like health records, financial information, or personal user data. For those use cases, you need a full authentication system with encrypted credentials, session management, and access logging.
Method 1: Website Builder Built-In Protection
The simplest approach is to use password protection that is built into your website platform. This requires zero technical knowledge and usually takes under a minute to set up.
Most modern website builders offer this feature. Typically, you go to your site's settings, find a "Password Protection" or "Access Control" option, set a password, and save. Visitors will see a password prompt before they can view your site. When you are ready to go public, you simply remove the password.
Advantages of built-in protection:
- No technical setup required.
- Works immediately with no server configuration.
- Usually includes a clean, branded password page that matches your site.
- Easy to toggle on and off as needed.
The limitation is that most builder-level protection applies to the entire site, not individual pages. If you need page-level access control, you may need a different approach.
Method 2: Server-Level Protection with .htpasswd
If you manage your own server or use traditional hosting (Apache or Nginx), you can add password protection at the server level using .htpasswd files. This method works before your website code even runs, making it very secure.
For Apache Servers
Create two files in the directory you want to protect:
First, create a .htpasswd file with your username and password. You can use an online htpasswd generator to create the encrypted password hash, then save it in a file outside your web root for security. The format is username:encrypted_password.
Second, create or edit the .htaccess file in the directory to protect with directives that set the AuthType to Basic, provide an AuthName prompt message, point AuthUserFile to your .htpasswd file path, and require a valid user.
For Nginx Servers
Nginx uses the same .htpasswd file format but configures protection in the server configuration block. You add an auth_basic directive with your prompt message and an auth_basic_user_file directive pointing to your .htpasswd file within the relevant location block.
Server-level protection is reliable and widely supported, but it has a plain browser-native login prompt that you cannot style, and managing users requires editing text files on the server.
Method 3: JavaScript-Based Protection
For static sites hosted on platforms where you cannot configure server settings, a JavaScript-based approach is an option. The idea is to encrypt your page content and only decrypt it when the correct password is entered.
Important caveats about this approach:
- Not truly secure: Anyone with browser developer tools can potentially bypass client-side protection. The encrypted HTML is downloaded to the browser, and a determined person could extract it.
- Acceptable for low-stakes privacy: If you just want to prevent casual access (like hiding a surprise birthday page or a draft portfolio), this approach is fine.
- Not acceptable for sensitive data: Never use client-side-only protection for anything confidential.
Tools like PageCrypt and StatiCrypt make this approach simple. You provide your HTML file and a password, and they output an encrypted version with a built-in password prompt.
Method 4: Middleware or Edge-Level Protection
If your site is deployed on a modern platform like Vercel, Netlify, or Cloudflare Pages, you can add password protection through middleware or edge functions. This runs server-side at the edge, so it is genuinely secure while being easy to set up.
The general approach involves creating a middleware function that checks for a valid session cookie, redirecting to a login page if the cookie is missing, and setting the cookie when the correct password is submitted. This is more work than a built-in toggle, but it gives you complete control over the login experience, including custom-designed login pages and page-level protection.
Best Practices for Password-Protected Sites
Regardless of which method you choose, follow these guidelines:
Use Strong Passwords
Even for a simple staging site, avoid obvious passwords like "password," "123456," or your company name. Use a random passphrase of at least 12 characters. If you are sharing the password with clients, use a password manager or secure messaging app rather than plain email.
Communicate Access Clearly
When sending someone a password-protected link, include clear instructions: the URL, the password, and how to enter it. It is frustrating for a client or collaborator to receive a link with no context about the password prompt they will see.
Set Expectations for Removal
If your site is temporarily password-protected (like a pre-launch site), set a reminder to remove the protection at launch. Forgotten passwords on live sites can block search engines and visitors indefinitely.
Do Not Rely on Security Through Obscurity
An unlinked page is not a protected page. If you think "nobody will find this URL," you are wrong. Search engine crawlers, shared links, and browser history can expose any page. If it needs to be private, add real protection.
Consider SEO Implications
Password-protected pages cannot be crawled by search engines. This is fine for staging sites and private content, but make sure you are not accidentally blocking pages that should be indexed. When you remove password protection, verify that search engines can crawl the site by checking your robots.txt and submitting the URL in Google Search Console.
Choosing the Right Approach
Here is a quick decision framework:
- Non-technical, whole-site protection: Use your website builder's built-in feature. This is the fastest and easiest option.
- Traditional hosting, server access: Use .htpasswd with Apache or Nginx configuration. It is battle-tested and truly secure.
- Static site, casual privacy: Use a JavaScript encryption tool like StatiCrypt. Good enough for non-sensitive content.
- Modern platform, custom login experience: Use middleware or edge functions. The most flexible option for developers.
Password protection does not have to be complicated. For most personal sites and portfolios, a built-in toggle or simple server configuration is all you need. Platforms like mnml.page let you password-protect your entire site with a single setting. Pick the method that matches your situation, set it up in a few minutes, and get back to building.
Ready to build your site?
Create a beautiful portfolio or personal website in minutes. No code, no complexity.
Start for free