PDF download Download Article
Learn how to prevent your browser from accessing specific sites
PDF download Download Article

Do you not want your browser going to a site that might be malicious? The website cannot only have bad coding, but it can also negatively affect productivity, offer inappropriate content, or steal data. You'll definitely want to block anything like that from your browsers. Read on to learn more about blocking websites on Mac, Windows, iPad, iPhone, and Android.

Block Websites in All Web Browsers

Block websites from all web browsers by editing the "Hosts" files on Windows and Mac. Editing the "Hosts" file takes a little work, but this wikiHow article guides you through the process so it's easier to block websites in all your web browsers. For iPad, iPhone, and Mac, use Screen Time to block websites.

Method 1
Method 1 of 4:

Windows

PDF download Download Article
  1. Press the Win key and enter Notepad. Right-click on the app and select Run as administrator. This option will open Notepad using your administrator privileges. If you don't open Notepad in administrator mode, you won't be able to edit the "hosts" file.
    • On a laptop with a trackpad instead of a traditional mouse, use two fingers to tap the trackpad instead of right-clicking.
  2. Doing so will confirm your decision and open Notepad.
    Advertisement
  3. You'll find Open in the File drop-down menu.
  4. In the window that opens after clicking Open..., do the following:
    • Click the This PC tab on the left side of the window.
    • Double-click your computer's hard drive (e.g., OS (C:)).
    • Double-click the Windows folder.
    • Scroll down and double-click the System32 folder.
    • Scroll down and double-click the drivers folder.
    • Double-click the etc folder.
  5. Click the "Text Documents" drop-down box near the bottom of the window, then click All Files in the drop-down menu. You should see several files appear in the window.
  6. Right-click the "hosts" file, then do the following:
    • Click Properties
    • Click Security
    • Click Edit
    • Check the "Full Control" box.
    • Click OK, then click Yes when prompted.
    • Click OK to exit the Properties window.
  7. This will open the "hosts" file in Notepad, allowing you to view and edit its contents.
  8. You'll see two "localhost" lines of text here.
  9. It will say either "::1 localhost" or "127.0.0.1 localhost" at the bottom of the page. Your cursor must be directly below the last line of text on this page.
    • Be careful not to delete anything that is already in the hosts file.
  10. This is the loopback address to your own computer, which is what will return an error page in your web browser when someone tries to visit the blocked site.
  11. For example, if you wanted to block Google, you would type www.google.com.
    • If you're blocking sites on Google Chrome, you'll need to place a space and then the "www.[site].com" version of the website's address after the "[site].com" version. To block Facebook, for example, you would type in 127.0.0.1 facebook.com www.facebook.com.
  12. This moves your cursor to a new line. The code you entered will tell your computer to redirect the website to your loopback address instead.
    • You can add as many sites as you want to block, one per line, using the same number (127.0.0.1) as before.
    • If you want to be as thorough as possible, enter different variations of the address (e.g., "google.com" and "https://www.google.com/") as well.
  13. Your changes won't be saved if you simply save using File > Save, so do the following to confirm your changes:
    • Click File
    • Click Save As...
    • Click Text Documents, then click All Files in the drop-down menu.
    • Click the "hosts" file.
    • Click Save
    • Click Yes when prompted.
  14. Advertisement
Method 2
Method 2 of 4:

Mac

PDF download Download Article
  1. This will prompt Terminal to appear at the top of the search results.
  2. Type the following code into Terminal and press Return:

    sudo nano /etc/hosts

  3. Type in the password that you use to log into your Mac, then press Return.
    • Terminal won't display the password characters as you type them.
  4. To do so, press the key until the cursor is below the last line of text on the page.
  5. Type 127.0.0.1 into the blank line. This is the loopback address to your own computer.[1]
  6. The cursor will move to the right.
    • Don't press Return yet.
  7. For example, if you wanted to block Google, you would type www.google.com.
    • This line would then read 127.0.0.1 www.google.com.
    • If you want to be as thorough as possible, enter different variations of the address (e.g., "google.com" and "https://www.google.com/") as well.
    • If you're blocking sites on Google Chrome, you'll need to place a space and then the "www.[site].com" version of the website's address after the "[site].com" version. To block Facebook, for example, you would type in 127.0.0.1 facebook.com www.facebook.com.
  8. This will tell your computer to redirect the website to your loopback address instead.
    • You can add as many sites as you want to block, one per line, using the same number (127.0.0.1) as before.
  9. This is the command to exit the hosts file in the text editor. It will prompt you if you'd like to save your changes.
  10. It will then ask you what filename you'd like to save it as. You want to overwrite the original hosts file, so don't change the filename.
  11. This will save your changes to the original hosts file. Doing so exits the text editor and returns you to the main Terminal window. The website you added will now be unreachable in any web browser on the computer.
  12. Advertisement
Method 3
Method 3 of 4:

iPhone, iPad & Mac

PDF download Download Article
  1. This option is usually in the second grouping of menu items next to an icon of an hourglass.
    • To access this menu on a Mac, go to System Settings > Screen Time.[2]
    • Select Turn on Screen Time if you're prompted and select if the phone is yours or a child's. If your phone belongs to a child, you'll be prompted to enter the passcode.
  2. This is near the bottom of the screen next to a red icon with a circle that has a line through it.
    • If you haven't yet enabled restrictions, first tap Enable Restrictions, then enter your desired passcode twice when prompted.
  3. This is usually the third listing in the menu.
  4. It's the last entry beneath the "Web Content" heading.
  5. You'll see a blue checkmark appear to the right of this option.
  6. If you want to block a specific site, like Facebook, tap Add a Website below the "NEVER ALLOW" heading and type in the web address of the website you wish to block. The address must start with "www" and end with a domain tag (e.g., ".com" or ".net"), but you can leave the "https://" section out if applicable.
    • For example, if you wanted to block Facebook on your iPhone or iPad, you would type in www.facebook.com.
    • This setting also applies to other popular iPhone browsers such as Chrome and Firefox.[3]
  7. Advertisement
Method 4
Method 4 of 4:

Android

PDF download Download Article
  1. It's a highly rated and popular site and app blocking apps that you can download for free from the Google Play Store.
    • If you don't like Freedom, you can use other similar apps.
    • You can pay to unlock more features with Freedom, but you can use the free version without a credit card.
  2. It's at the top of the screen.
    • If you already have a Freedom account, tap Log In.
    • Follow the on-screen instructions to create an account with your email and password.
  3. Choose any of these reasons to continue.
    • Continue making selections through the "Getting started" pages and tap Continue when prompted.
  4. You'll need to allow blocking permissions for Freedom to be able to block websites and applications. Tap Enable to open "Settings", then go to Installed Apps > Freedom and tap the toggle to enable it.
    • Tap Allow and then close the window and return to the app.
  5. It's your tab for "Blocklists" and is centered at the bottom of your screen.
  6. These are the sites that your Android will block when you're running a Freedom session. Here's what you need to do to create a blocklist:
    • Enter a blocklist name.
    • Select any apps to block.
    • Add domains to block and tap Add Block.
      • If you have a long list of domains to block, you can simply block by category. For example, enabling the toggle next to "Social" will block 41 websites and apps including facebook.com, instagram.com, and swarmapp.com.
  7. Tap the flag icon at the bottom of your screen and tap Start Session. Here's what you need to do to use the blocklist you just created:
    • Select your blocklist from the blocklist section.
    • Select a duration for the session. For example, you can create a session for 3hrs and 25 minutes that blocks all the apps and websites on your blocklist during that time.
    • Unlocking Premium will allow you to schedule sessions ahead of time.
  8. Once you start the session and the app has all the accessibility permissions it requires, you can't access blocked websites or open blocked apps.
    • Tap the session in Freedom and select End Session to stop blocking sites and apps.
    • You can also use this app on other platforms, including Windows.
  9. Advertisement

Community Q&A

Search
Add New Question
  • Question
    How can I block a website on the iPad?
    Community Answer
    Community Answer
    Parental controls in the Settings app allows you to block websites with a passcode.
  • Question
    How do I force the host file to open in a text editor?
    Community Answer
    Community Answer
    It can't be forced to open in a text editor, because it doesn't have the extension. To open, double-click the file and select the proper program to open it.
  • Question
    Can this be reversible?
    Community Answer
    Community Answer
    Yes, it is a reversible process. Just remove the extra lines you added. Alternatively, you can restore the hosts file from a backup.
See more answers
Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
Advertisement

Tips

Show More Tips
Submit a Tip
All tip submissions are carefully reviewed before being published
Name
Please provide your name and last initial
Thanks for submitting a tip for review!
Advertisement

Warnings

Advertisement

About This Article

Darlene Antonelli, MA
Written by:
wikiHow Technology Writer
This article was co-authored by wikiHow staff writer, Darlene Antonelli, MA. Darlene has been writing and editing tech content at wikiHow since 2019. She previously worked for AppleCare, served as a writing tutor, volunteered in IT at an animal rescue, and taught as an adjunct professor for EN101 and EN102. Darlene has completed Coursera courses on technology, writing, and language. She holds both a BA (2011) and an MA (2012) from Rowan University in Writing, with a focus on workplace communication. With her extensive experience, academic background, and ongoing learning, Darlene has become the go-to grammar expert for her friends and family, as well as a skilled wordsmith for anyone in need. This article has been viewed 2,017,836 times.
How helpful is this?
Co-authors: 64
Updated: January 16, 2025
Views: 2,017,836
Categories: Internet Browsers
Thanks to all authors for creating a page that has been read 2,017,836 times.

Is this article up to date?

Advertisement