Webbrowser module in Python

Last Updated : 4 Oct 2026

In Python, the webbrowser module provides a high-level interface for displaying web-based documents in the user's default browser.

In this chapter, we will learn the webbrowser module, its syntax, parameters, examples, built-in functions, and members.

What is the Webbrowser Module?

The webbrowser module provides a high-level interface for opening web documents in the user's default web browser. We can use it to open URLs, launch new browser tabs or windows, and access specific browsers installed on the system. It can also be used as a command-line (CLI) tool. It accepts a URL as an argument along with some optional parameters.

Note: The webbrowser module is part of Python's Standard Library, so there is no need to install any separate package to use it.

Syntax

It has the following syntax:

For executable code:

webbrowser.open(url, new=0, autoraise=True)

OR

For command-line interface (CLI):

python -m webbrowser [-n | -t] URL

Parameters

The following parameters are used with the webbrowser module:

  • URL: The URL parameter accepts the web address that needs to be opened in the default browser.
  • -n (optional): The -n parameter allows us to open a URL in a new browser window. It is used only with the CLI.
  • -t (optional): The -t parameter allows us to open a URL in a new tab of the default web browser. It is used only with the CLI.

Examples of Webbrowser Module

Here, we are going to take several examples that demonstrate the working of the webbrowser module.

Example 1: Using executable program code

The following example demonstrates how to use the webbrowser module to open a specific URL in a new web browser window.

Python

import webbrowser

webbrowser.open('https://www.tpointtech.com/chainmap-in-python')
print('Browser opened!')
Execute Now

Output:

Webbrowser module in Python

Browser opened!

Explanation

In the given example, we imported the webbrowser module. After that, we called the open() function from the module and passed the URL to open it in a new browser window. Finally, we printed a message after successfully opening the browser.

Example 2: Using the –t parameter with the webbrowser in CLI (command-line interface)

The following example demonstrates how to use the webbrowser module from the CLI with the -t parameter to open a URL in a new browser tab.

Python

python -m webbrowser -t "https://www.tpointtech.com/arithmeticerror-in-python"
Execute Now

Output:

Webbrowser module in Python

Explanation

In the given example, we used the webbrowser module with the -t parameter followed by a URL in the command-line interface (CLI) of a code editor or terminal. When we run the command, the URL opens in a new tab of the default web browser.

Example 3: Using the –n parameter with the webbrowser in CLI (command-line interface)

The following example demonstrates how to use the webbrowser module from the CLI with the -n parameter to open a URL in a new browser window, if possible.

Python

python -m webbrowser -n "https://www.tpointtech.com/python-statistics-correlation-method"
Execute Now

Output:

Webbrowser module in Python

Explanation

In the given example, we used the webbrowser module with the -n parameter followed by a URL in the command-line interface (CLI) of a code editor or terminal. When we run the command, the URL opens in a new browser window, if possible.

Built-in functions of the webbrowser module

The following table lists some important functions that are provided by the webbrowser module to open URLs in the web browser.

FunctionDescriptions
open()It opens a specified URL in the system's default web browser.
open_new()It opens a specified URL in a new browser window, if possible.
open_new_tab()It opens a specified URL in a new tab of the default web browser.
get()It is used to obtain a browser controller object for a specific browser type. After that, it can be used to open URLs using that browser.
register()It is used to register a browser type so that it can be accessed and controlled through the webbrowser module.

Members of the webbrowser module

The following table shows some important members of the webbrowser module to open URLs in the web browser.

MemberDescriptions
ChromeGoogle Chrome can be specified as a browser type when using functions such as get() or register() to open URLs through the Chrome browser.
BackgroundBrowserThe BackgroundBrowser is a browser controller class in Python's webbrowser module that is used to launch a browser in the background without requiring it to become the active window.
BaseBrowserThe BaseBrowser is a base class in Python's webbrowser module that provides the basic structure for browser controller classes. Other browser controller classes can inherit from it to implement browser-specific behavior.
OperaOpera is a browser controller in Python's webbrowser module that can be used to open URLs in the Opera browser.
UnixBrowserThe UnixBrowser is a browser controller class in Python's webbrowser module that is used to open URLs in web browsers on Unix-based operating systems.
ErrorAn error in Python's webbrowser module occurs when the requested browser cannot be found, opened, or used to perform the specified operation.
MacOSXThe MacOSX is a browser controller class in Python's webbrowser module used to open URLs in web browsaers on macOS.