HTML Basics
1. Introduction
HTML (HyperText Markup Language) is the standard markup language for creating web pages. It describes the structure of a webpage using a series of elements that define different parts of the content.
2. Basic Structure of HTML
An HTML document is structured in a specific way:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document Title</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a paragraph.</p>
</body>
</html>
Key components include:
- DOCTYPE declaration
- HTML element
- Head section (metadata)
- Body section (content)
3. HTML Elements
HTML elements are the building blocks of HTML. They are defined by tags. Here are some common elements:
- <h1> to <h6> - Headings
- <p> - Paragraph
- <a> - Anchor (link)
- <img> - Image
- <div> - Division
Example of using different elements:
<h1>Main Heading</h1>
<p>This is a sample paragraph.</p>
<a href="https://example.com">Visit Example</a>
4. HTML Attributes
Attributes provide additional information about HTML elements. They are always specified in the opening tag and come in name/value pairs.
Example:
<a href="https://example.com" target="_blank">Visit Example</a>
Common attributes include:
- href - Specifies the URL of the link
- src - Specifies the URL of the image
- alt - Provides alternative text for images
- class - Specifies a class for CSS styling
5. Best Practices
Follow these best practices to write clean, effective HTML:
- Use semantic HTML elements for better accessibility.
- Keep your HTML well-indented for readability.
- Always close your tags.
- Use comments to document your code.
FAQ
What is the purpose of HTML?
HTML serves as the backbone of web development, providing the structure for web pages.
Can HTML be used for styling?
No, HTML is used for structure. CSS (Cascading Style Sheets) is used for styling HTML elements.
Is HTML case-sensitive?
No, HTML is not case-sensitive. However, it is best practice to use lowercase for tags and attributes.