Creating your first HTML webpage is simple and exciting! Follow this step-by-step guide to write and run your first HTML code.
1. Setup
Before writing your HTML code, you need:
- A text editor (e.g., Notepad, Visual Studio Code, Sublime Text).
- A web browser (e.g., Chrome, Firefox, Edge).
2. Write Your HTML Code
- Open Your Text Editor:
Open a text editor of your choice. For simplicity, let’s use Notepad (Windows) or TextEdit (Mac). - Write Your Code:
Type the following code:<!DOCTYPE html> <html> <head> <title>My First Webpage</title> </head> <body> <h1>Hello, World!</h1> <p>Welcome to my first webpage.</p> <a href="https://example.com" target="_blank">Click here to visit Example</a> </body> </html>
Explanation:
<!DOCTYPE html>
: Declares the document as HTML5.<html>
: The root element of your webpage.<head>
: Contains metadata, such as the title of the page.<title>
: Sets the title shown in the browser tab.<body>
: Contains the content displayed on the webpage.<h1>
: A heading.<p>
: A paragraph.<a>
: A hyperlink to an external website.
3. Save Your File
- Save the File:
- Go to
File > Save As
. - Choose a location (e.g., Desktop).
- Enter a file name, such as
index.html
.
Ensure the extension is.html
. - Set the file type to All Files (if using Notepad).
- Go to
- Check Your File:
- The file icon should look like your browser’s icon (e.g., Chrome or Edge) if saved correctly.
4. Open Your Webpage
- Locate the File:
Navigate to where you saved the file (e.g., Desktop). - Open in a Browser:
- Double-click the file, and it will open in your default web browser.
- You should see:
- A heading: “Hello, World!”
- A paragraph: “Welcome to my first webpage.”
- A link to “Example.”
5. Edit and Update Your Webpage
- Make Changes:
- Open the
index.html
file in your text editor. - Add more content, like another heading or image:
<h2>About Me</h2> <p>I am learning HTML!</p> <img src="https://via.placeholder.com/150" alt="Placeholder Image">
- Open the
- Save the Changes:
- Save the file (
Ctrl + S
orCmd + S
).
- Save the file (
- Refresh the Browser:
- Go back to your browser and refresh the page to see the updates.
6. Try These Enhancements
- Add a List
<ul> <li>HTML</li> <li>CSS</li> <li>JavaScript</li> </ul>
- Style the Text:
<p style="color:blue;">This is blue text.</p>
- Embed a Video:
<iframe width="560" height="315" src="https://www.youtube.com/watch?v=dQw4w9WgXcQ" title="YouTube video" frameborder="0" allowfullscreen> </iframe>
Tips
- Practice Regularly: Try writing different tags to understand their use.
- Experiment: Modify attributes (like
style
,href
) to see changes. - Learn Incrementally: After basics, move to forms, multimedia, and responsive design.