RStudio does not have a built-in "read HTML" button, but you can save HTML output in three ways: by exporting a rendered document, by copying code from the editor, or by locating files RStudio creates automatically when you knit or render a document.
The method you use depends on what you want. If you have written an R Markdown file and rendered it to HTML, RStudio saves that HTML file to your computer automatically — you just need to find where. If you want the raw HTML code itself, you copy it from the viewer pane or open the saved file in a text editor. If you want to read someone else's HTML output from the internet, that is a browser task, not an RStudio task.
This guide covers the three real situations: saving HTML you created in RStudio, viewing the code behind that HTML, and understanding where RStudio puts files so you can find them later.
Key Takeaways
- When you knit an R Markdown file to HTML in RStudio, the HTML file saves automatically to your project folder with the same name as your .Rmd file but with a .html extension.
- You can view the raw HTML code by opening the saved .html file in a text editor like Notepad or by right-clicking the file and selecting "Open With".
- The Viewer pane in RStudio shows a preview of your HTML output, but the actual file lives in your working directory, not inside RStudio.
- If you want to share or move your HTML file, navigate to your project folder using Windows Explorer or Finder and copy the .html file like any other document.
Finding HTML Files RStudio Creates When You Knit
When you knit an R Markdown document to HTML, RStudio creates an .html file and saves it in the same folder as your .Rmd file. If your file is named analysis.Rmd and you knit it to HTML, RStudio creates analysis.html in that same location.
To find this file, open your file browser (Windows Explorer on Windows, Finder on Mac) and navigate to the folder where you saved your .Rmd file. Look for a file with the same name but ending in .html instead of .Rmd. This is your rendered HTML document. You can open it in any web browser by double-clicking it, and you can move it, copy it, or email it like any other file.
If you cannot find the file, check your working directory in RStudio. In the Console pane, type getwd() and press Enter. RStudio will print the full path to your working directory. Navigate there in your file browser, and your HTML file should be there.
Viewing the Raw HTML Code in a Text Editor
The HTML file RStudio creates is a plain text file with code inside it. To read that code, you do not need any special software — you can open it in Notepad (Windows), TextEdit (Mac), or any text editor.
Right-click the .html file in your file browser and select "Open With". Choose Notepad or your preferred text editor. The file will open showing all the HTML tags, CSS styling, and JavaScript that RStudio generated from your R Markdown document. You can read this code, copy sections of it, or edit it by hand if you know HTML.
Do not open the .html file by double-clicking it if you want to see the code — that will open it in your web browser as a rendered page, not as text. Use "Open With" and select a text editor instead.
Copying HTML Code From the RStudio Viewer Pane
When you knit a document in RStudio, the Viewer pane (usually in the bottom right) shows a preview of your HTML output. This is not the same as the code — it is a live preview of what the HTML looks like when rendered.
You cannot copy the rendered preview directly from the Viewer pane. Instead, open the .html file itself in a text editor to access the code. The Viewer pane is useful for checking that your document looks correct before you share it, but the actual code lives in the .html file on your computer.
Exporting R Markdown to HTML Without Knitting
If you want to convert an R Markdown file to HTML but do not want to run the code inside it, you can render the document without executing the R chunks. In RStudio, click the dropdown arrow next to the Knit button and select "Knit to HTML (without running R code)". This creates an HTML file that shows your R code and markdown text, but does not run any calculations.
This is useful if you want to share the source code itself rather than the results. The HTML file will still be saved in your project folder with the same name as your .Rmd file.
Moving or Sharing Your HTML File
Once RStudio creates your .html file, it is a standalone document. You can move it to a different folder, email it, upload it to a website, or open it on a different computer. The HTML file does not depend on RStudio or your R project to work — any web browser can open it.
If your HTML includes images or other files, those files need to be in the same folder as the .html file, or the links inside the HTML will break. Check your document before you move it to make sure all images and resources are included.
To share your HTML file with someone else, locate it in your file browser, right-click it, and select "Copy". Then paste it into an email, cloud storage folder, or shared drive. The person who receives it can open it in any web browser without needing RStudio or R installed.
Understanding File Paths and Working Directories
RStudio saves files relative to your working directory — the folder RStudio considers "home" for your current project. When you knit a document, the HTML file goes into this working directory by default.
You can change your working directory in RStudio by going to Session > Set Working Directory > Choose Directory, or by typing setwd("path/to/folder") in the Console. After you change it, any new files you knit will save to that new location.
If you are working inside an RStudio Project (a .Rproj file), the working directory is automatically set to the project folder. This is the easiest way to keep your files organized — create a project, put your .Rmd files in it, and all your HTML output will save there too.
Frequently Asked Questions
Can I read HTML from a website using RStudio?
No. RStudio is for creating and rendering documents on your computer, not for downloading files from the internet. To read HTML from a website, use your web browser: right-click the page, select "Save As", and choose "Webpage, HTML Only" or "Complete Webpage". RStudio is not involved in this process.
What if I knit my document but cannot find the HTML file?
Check your working directory by typing getwd() in the RStudio Console. Navigate to that folder in your file browser. If the file is not there, check that you actually clicked the Knit button and waited for it to finish — a progress bar appears while RStudio is working. If knitting failed, error messages will appear in the Console.
Can I edit the HTML file after RStudio creates it?
Yes. Open the .html file in a text editor, make changes to the code, and save it. Your changes will appear the next time you open the file in a web browser. However, if you knit the same R Markdown file again, RStudio will overwrite your edited HTML file with a new version, so save a copy first if you want to keep your edits.
Do I need to install anything extra to save HTML from RStudio?
No. RStudio comes with everything you need to knit R Markdown documents to HTML. You do not need to read or install additional software. You do need R and RStudio installed, but if you are already using RStudio, you have what you need.
Can I open an HTML file created by RStudio on a different computer?
Yes. The .html file is a standard web document that any computer can open. Double-click it or drag it into any web browser — Chrome, Firefox, Safari, or Edge all work. You do not need RStudio, R, or any special software installed on the other computer.