What is HTML?
HTML (HyperText Markup Language) is the standard markup language used to create web pages. It provides the structure and content of a website, defining elements like headings, paragraphs, links, images, and more. Think of HTML as the skeleton of a webpage – it provides the framework that everything else builds upon.
HTML uses a system of tags to mark up content. Tags are enclosed in angle brackets, like <p>
for paragraphs or <h1>
for headings. Most tags come in pairs – an opening tag and a closing tag – that wrap around content.
Basic HTML Document Structure
Every HTML document follows a basic structure that includes several essential elements:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is my first paragraph.</p>
</body>
</html>
Breaking Down the Structure
- <!DOCTYPE html>: Declares the document type and version of HTML
- <html>: The root element that contains all other elements
- <head>: Contains metadata about the document (not visible on the page)
- <body>: Contains the visible content of the webpage
Essential HTML Elements
Let's explore the most important HTML elements that every beginner should know:
Text Content Elements
- Headings:
<h1>
to<h6>
for different levels of headings - Paragraphs:
<p>
for blocks of text - Line breaks:
<br>
for single line breaks - Horizontal rule:
<hr>
for thematic breaks
Formatting Elements
- Bold text:
<strong>
for important text - Italic text:
<em>
for emphasized text - Underline:
<u>
for underlined text - Highlight:
<mark>
for highlighted text
Links and Navigation
Links are fundamental to the web. The <a>
element creates hyperlinks:
<a href="https://www.example.com">Visit Example</a>
<a href="mailto:[email protected]">Send Email</a>
<a href="#section1">Jump to Section 1</a>
Working with Lists
HTML provides several types of lists to organize information:
Unordered Lists
<ul>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ul>
Ordered Lists
<ol>
<li>Step one</li>
<li>Step two</li>
<li>Step three</li>
</ol>
Images and Media
Adding images to your webpage is straightforward with the <img>
element:
<img src="image.jpg" alt="Description of image" width="300" height="200">
Always include the alt
attribute for accessibility – it provides a text description for screen readers and displays when the image can't load.
Semantic HTML5 Elements
HTML5 introduced semantic elements that provide meaning to your content structure:
- <header>: Introductory content or navigation
- <nav>: Navigation links
- <main>: Main content of the page
- <article>: Independent, self-contained content
- <section>: Thematic grouping of content
- <aside>: Side content like sidebars
- <footer>: Footer information
Example of Semantic Structure
<header>
<nav>
<ul>
<li><a href="/">Home</a></li>
<li><a href="/about">About</a></li>
</ul>
</nav>
</header>
<main>
<article>
<h1>Article Title</h1>
<p>Article content goes here...</p>
</article>
</main>
<footer>
<p>© 2025 My Website</p>
</footer>
HTML Attributes
Attributes provide additional information about HTML elements. They're always specified in the opening tag and come in name/value pairs:
- id: Unique identifier for an element
- class: CSS class name for styling
- style: Inline CSS styles
- title: Tooltip text
- href: URL for links
- src: Source file for images
- alt: Alternative text for images
Forms and Input Elements
HTML forms allow users to input data. Here's a basic form structure:
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="message">Message:</label>
<textarea id="message" name="message" rows="4"></textarea>
<button type="submit">Send Message</button>
</form>
Best Practices for HTML
Follow these best practices to write clean, maintainable HTML:
1. Use Semantic Elements
Choose elements based on their meaning, not their appearance. Use <strong>
for important text, not just to make text bold.
2. Nest Elements Properly
Always close tags in the reverse order they were opened:
<p><strong>This is correct</strong></p>
<p><strong>This is incorrect</p></strong>
3. Use Lowercase for Tags and Attributes
While HTML is case-insensitive, lowercase is the standard convention.
4. Always Include Alt Text for Images
This improves accessibility and SEO:
<img src="logo.png" alt="Company Logo">
5. Validate Your HTML
Use the W3C HTML Validator to check your code for errors and ensure compliance with standards.
Common HTML Mistakes to Avoid
- Missing closing tags: Always close your tags properly
- Incorrect nesting: Don't overlap tags
- Missing alt attributes: Always include alt text for images
- Using deprecated elements: Avoid old elements like
<center>
or<font>
- Forgetting the DOCTYPE: Always include the HTML5 DOCTYPE
Next Steps
Now that you understand HTML basics, you're ready to start building web pages! Here are some next steps to continue your learning journey:
- Practice regularly: Build simple web pages using the elements you've learned
- Learn CSS: Style your HTML with Cascading Style Sheets
- Explore HTML5 features: Learn about forms, multimedia, and APIs
- Focus on accessibility: Ensure your websites work for all users
- Join our CSS course: Take the next step in your web development journey
Remember, becoming proficient in HTML takes practice. Start with simple projects and gradually work your way up to more complex websites. The key is to understand the structure and semantic meaning of HTML elements, not just memorize tags.