How to write to an HTML file in Python ? Last Updated : 26 Mar, 2021 Comments Improve Suggest changes Like Article Like Report Python language has great uses today in almost every field, it can be used along with other technologies to make our lives easier. One such use of python is getting the data output in an HTML file. We can save any amount of our input data into an HTML file in python using the following examples in two ways. Example 1: Creating an HTML file and saving the input data into it. Approach: Creating an HTML file.Function_Name = open("Complete_File_Name","File_operation")Adding input data in HTML format into the file.Function_Name.write("Adding_Input_data_using_HTML_Synatx_separted_by_/n")Saving the HTML file.Function_Name.close()Opening the HTML file from the saved location. Below is the implementation: Python3 # Creating an HTML file Func = open("GFG-1.html","w") # Adding input data to the HTML file Func.write("<html>\n<head>\n<title> \nOutput Data in an HTML file \ </title>\n</head> <body><h1>Welcome to <u>GeeksforGeeks</u></h1>\ \n<h2>A <u>CS</u> Portal for Everyone</h2> \n</body></html>") # Saving the data into the HTML file Func.close() Output: GFG-1.html file is created in the folderChecking the Output data of the GFG-1.html file Example 2: Creating and Saving an HTML file and then adding input data to it. Approach: Creating an HTML file and saving it.Function_Name = open("Complete_File_Name","File_operation") Function_Name.close()Opening the HTML file from the saved location.Now adding input data into the created HTML file.Function_Name = open(File_Location,"File_operation") Function_Name.write("Adding_Input_data_using_HTML_Synatx_separted_by_/n")Saving the HTML file.Function_Name.close()Opening the HTML file from the saved location again to check the output data. Below is the implementation: Python3 # Opening the existing HTML file Func = open("GFG-2.html","w") # Adding input data to the HTML file Func.write("<html>\n<head>\n<title> \nOutput Data in an HTML file\n \ </title>\n</head> <body> <h1>Welcome to \ <font color = #00b300>GeeksforGeeks</font></h1>\n \ <h2>A CS Portal for Everyone</h2>\n</body></html>") # Saving the data into the HTML file Func.close() Output: Input data is saved into the GFG-2.html fileChecking the Output data of the GFG-2.html file We've successfully saved and output data into an HTML file using a simple function in python. Any one of the above methods can be used to get the desired result. Comment More infoAdvertise with us Next Article How to write to an HTML file in Python ? ayushraghuwanshi80 Follow Improve Article Tags : Python python-file-handling Practice Tags : python Similar Reads How to write the output to HTML file with Python BeautifulSoup? In this article, we are going to write the output to an HTML file with Python BeautifulSoup.  BeautifulSoup is a python library majorly used for web scraping but in this article, we will discuss how to write the output to an HTML file. Modules needed and installation: pip install bs4 Approach: We wi 2 min read Writing to file in Python Writing to a file in Python means saving data generated by your program into a file on your system. This article will cover the how to write to files in Python in detail.Creating a FileCreating a file is the first step before writing data to it. In Python, we can create a file using the following th 4 min read How to use HTML in Tkinter - Python? Prerequisite: Tkinter Python offers multiple options for developing GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter is the fastest and easiest way to 2 min read How to parse local HTML file in Python? Prerequisites: Beautifulsoup Parsing means dividing a file or input into pieces of information/data that can be stored for our personal use in the future. Sometimes, we need data from an existing file stored on our computers, parsing technique can be used in such cases. The parsing includes multiple 5 min read How to Convert HTML to Markdown in Python? Markdown is a way of writing a formatted text on the web. This article discusses how an HTML text can be converted to Markdown. We can easily convert HTML to markdown using markdownify package. So let's see how to download markdownify package and convert our HTML to markdown in python. Installation 1 min read How to write e-mails in HTML and send it using Gmail ? In this article, we are going to learn that how users can write e-mails in HTML format and send them using Gmail. However, Gmail doesn't offer an HTML editor still we can send HTML templates in an e-mail using some tools and methods. Many people need to send an e-mail with HTML templates to others. 3 min read Reading and Writing to text files in Python Python provides built-in functions for creating, writing, and reading files. Two types of files can be handled in Python, normal text files and binary files (written in binary language, 0s, and 1s). Text files: In this type of file, Each line of text is terminated with a special character called EOL 8 min read How to convert IPython notebooks to PDF and HTML? In this article, we will see how to convert IPython notebooks to PDF and HTML. Sometimes according to our necessity, we would want to share or convert the Jupyter notebook to HTML or pdf format. Our Jupyter Notebooks can be easily converted to PDF and HTML files. You may access your notebook as a PD 1 min read How to keep old content when Writing to Files in Python? In this article, we are going to discuss various approaches to keep old content while writing files in Python. We can keep old content while using write in python by opening the file in append mode. To open a file in append mode, we can use either 'a' or 'a+' as the access mode. The definition of th 3 min read How to make HTML files open in Chrome using Python? Prerequisites: Webbrowser HTML files contain Hypertext Markup Language (HTML), which is used to design and format the structure of a webpage. It is stored in a text format and contains tags that define the layout and content of the webpage. HTML files are widely used online and displayed in web brow 2 min read Like