How to Run HTML Code: A Guide to Viewing and Testing Web Pages
HTML (HyperText Markup Language) is the foundation of every website on the internet. If you’re learning web development or just curious about how websites work, understanding how to write and run HTML code is an essential first step.

Luckily, running HTML is easy and doesn’t require any fancy software. Whether you want to view your own webpage on a browser or test a bit of code, this guide will walk you through how to run HTML code in simple, beginner-friendly steps.
What Is HTML?
HTML is a markup language used to structure the content of web pages. It tells the browser how to display text, images, links, and other elements.
Here’s a very basic HTML example:
<!DOCTYPE html>
<html>
<head>
<title>My First Page</title>
</head>
<body>
<h1>Hello, world!</h1>
<p>This is my first HTML page.</p>
</body>
</html>
When run in a web browser, this code displays a heading and a paragraph.
What Do You Need to Run HTML Code?
You don’t need to install any special tools to run HTML code. All you need are:
-
A text editor to write your code.
-
A web browser (like Chrome, Firefox, Safari, or Edge) to view it.
Let’s explore both of these in more detail.
Step 1: Choose a Text Editor
You can write HTML in any text editor, including:
Simple Editors:
-
Notepad (Windows)
-
TextEdit (Mac)
Advanced Editors (Recommended):
-
VS Code
-
Sublime Text
-
Atom
-
Brackets
Tip: If you’re just starting, Notepad or TextEdit works fine. But as you progress, tools like VS Code offer useful features like syntax highlighting and auto-complete.
Step 2: Write Your HTML Code
Open your text editor and type this basic code:
<!DOCTYPE html>
<html>
<head>
<title>Test Page</title>
</head>
<body>
<h1>This is a test</h1>
<p>Hello from HTML!</p>
</body>
</html>
Save the file with a .html
extension, like:
Important: When saving in Notepad, make sure the file type is All Files and the encoding is UTF-8. Otherwise, it may save as a
.txt
file.
Step 3: Open the HTML File in a Browser
Once you’ve saved your HTML file:
-
Go to the folder where you saved the
.html
file. -
Right-click on the file.
-
Choose Open with > Your Browser (e.g., Chrome, Firefox).
Your HTML code will now be displayed as a webpage in your browser!
Alternatively, you can drag and drop the HTML file directly into a browser window.
Step 4: Edit and Refresh
You can make changes to your HTML file at any time in your text editor. After editing:
-
Save the file, then
-
Refresh the browser to see the changes.
This is how web developers test their pages during development.
Using Online HTML Editors
If you don’t want to install anything, try an online HTML editor. These tools let you write and run HTML code directly in your browser.
Popular Online Editors:
-
JSFiddle (https://jsfiddle.net/)
-
CodePen (https://codepen.io/)
-
W3Schools Tryit Editor (https://www.w3schools.com/html/tryit.asp)
-
JSBin (https://jsbin.com/)
These editors usually let you combine HTML with CSS and JavaScript and show the result instantly.
Bonus: Running HTML with CSS and JavaScript
HTML becomes more powerful when combined with CSS (for styling) and JavaScript (for interactivity). You can write all three in one HTML file.
Here’s an example:
<!DOCTYPE html>
<html>
<head>
<title>Styled Page</title>
<style>
body {
background-color: #f0f0f0;
font-family: Arial;
text-align: center;
}
h1 {
color: #333;
}
</style>
</head>
<body>
<h1>Welcome to My Page</h1>
<button onclick=”sayHello()”>Click Me</button>
<script>
function sayHello() {
alert(“Hello, world!”);
}
</script>
</body>
</html>
Save the file as index.html
and open it in your browser to see the styled heading and a clickable button.
Folder Structure Tips for Larger Projects
As your HTML projects grow, organize your files:
/MyWebsite
│
├── index.html
├── about.html
├── /css
│ └── style.css
├── /js
│ └── script.js
├── /images
└── logo.png
Keep HTML files at the root, and place your CSS, JavaScript, and images in separate folders for easier management.
Troubleshooting Common HTML Issues
Problem | Solution |
---|---|
Browser shows code, not page | Make sure file ends in .html and not .txt |
Styling not working | Check your <style> tag or linked CSS file |
Changes not showing | Save file and refresh browser (Ctrl + R) |
Buttons or links not working | Double-check syntax and JavaScript |
Tips for HTML Beginners
-
Use proper indentation for readability.
-
Always include
<!DOCTYPE html>
at the top of your file. -
Make sure tags are properly opened and closed.
-
Use browser Developer Tools (F12) to inspect and debug.
-
Learn basic HTML tags like
<a>
,<img>
,<div>
,<ul>
, and<form>
.
Best Practices When Writing HTML
-
Use semantic tags like
<header>
,<nav>
,<section>
,<footer>
for structure. -
Avoid inline styling. Use external or internal CSS for maintainability.
-
Keep your code clean and well-commented.
-
Test in multiple browsers to ensure compatibility.
Conclusion
Learning to run HTML code is the first step to understanding how websites work. Whether you’re building your first webpage or testing a small code snippet, running HTML is quick, easy, and requires minimal setup. With just a browser and a text editor, you can start creating your own web pages today.
From simple “Hello World” messages to fully interactive websites, the possibilities with HTML are endless. So fire up your editor, write some code, and see your work come to life in the browser.