-
Notifications
You must be signed in to change notification settings - Fork 0
Syntax
Every HTML file must follow a specific structure.
π A simple HTML document looks like this:
<!DOCTYPE html>
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is my first web page.</p>
</body>
</html>π Letβs break it down! π
π The first line of every HTML file is always:
<!DOCTYPE html>β This tells the browser:
"Hey! This is an HTML5 document!"
π‘ Without this line, the browser might not understand how to correctly display your page.
π The <html> tag is the biggest container for your entire webpage.
<html>
<!-- Everything inside here is part of the webpage -->
</html>β
Everything inside <html> is read by the browser to display the page.
π‘ It must have an opening (<html>) and a closing (</html>) tag.
π The <head> tag contains important information about the page but does not appear on the webpage itself.
<head>
<title>My Website</title>
</head>β The head section is like a brain π§ . It includes:
-
<title>β The title of the webpage (shows on the browser tab). - Other settings (like fonts, styles, and scripts).
π‘ Example:
<head>
<title>Awesome Website</title>
<meta charset="UTF-8">
</head>- The
<meta charset="UTF-8">ensures the page supports all languages π (English, Japanese, Arabic, etc.).
π The <body> tag contains everything that will be displayed on the webpage.
<body>
<h1>Welcome!</h1>
<p>This is my first webpage.</p>
</body>β
Inside <body>, we can have:
-
Headings (
<h1>to<h6>) -
Paragraphs (
<p>) -
Images (
<img>) -
Links (
<a>) -
Buttons (
<button>) -
Videos (
<video>)
π‘ Example:
<body>
<h1>π My Awesome Website π</h1>
<p>Welcome to my first website!</p>
<img src="https://example.com/image.jpg" alt="Cute cat" width="200">
<a href="https://google.com">Go to Google</a>
</body>π HTML uses "TAGS" to structure content.
π Basic format of an HTML tag:
<tagname>Content</tagname>β
Opening tag β <p>
β
Closing tag β </p>
Here are some common HTML elements with examples:
| Tag | Purpose | Example |
|---|---|---|
<h1> - <h6>
|
Headings (titles) | <h1>Big Title</h1> |
<p> |
Paragraph | <p>This is text.</p> |
<a> |
Hyperlink | <a href="https://google.com">Google</a> |
<img> |
Image | <img src="cat.jpg" alt="A cute cat"> |
<ul>, <li>
|
Unordered List | <ul><li>Item 1</li></ul> |
<ol>, <li>
|
Ordered List | <ol><li>First</li></ol> |
<table> |
Table | <table><tr><td>Data</td></tr></table> |
π Letβs put everything together into a full HTML page!
<!DOCTYPE html>
<html>
<head>
<title>π My First Web Page</title>
</head>
<body>
<h1>π Welcome to My Website! π</h1>
<p>Hello! This is my first webpage.</p>
<h2>πΈ My Favorite Image:</h2>
<img src="https://example.com/cute-cat.jpg" alt="A cute cat" width="200">
<h2>π Useful Links:</h2>
<a href="https://google.com">Click here to go to Google</a>
<h2>π My To-Do List:</h2>
<ul>
<li>Learn HTML</li>
<li>Practice CSS</li>
<li>Build a website</li>
</ul>
</body>
</html>β What happens when you open this file?
- Title: βπ My First Web Pageβ appears on the browser tab.
- Big heading: "π Welcome to My Website! π"
- Paragraph: "Hello! This is my first webpage."
- An image of a cat π±
- A link to Google π
- A to-do list π