There are a lot of ways to do this, depending on what you are trying to do and what your setup is. For example, do you want to password protect your entire site or just one page? Also, are you using a CMS, HTML pages, or some other setup?
Here are a few methods:
If you are running a CMS, there usually are plugins that can do this.
If you want to protect the entire site or directory: See
this guide about using .htaccess to do this.
If you want to protect just one page: You could use javascript.
Here is some different ways to do it. I would recommend using the
gatekeeper method or the
encrypted password generator method, as most of the other ones are easy to crack by just viewing the source code.