HTML Basics

HTML Basics Tutorial

What is HTML?

HTML (HyperText Markup Language) is the standard language used to create web pages. It uses tags to structure content and tell the browser how to display text, images, links, and other elements.

Basic HTML Structure

Every HTML document follows this basic structure:

<!DOCTYPE html>
<html>
<head>
    <title>Page Title</title>
</head>
<body>
    <!-- Your content goes here -->
</body>
</html>

Key Components:

  • <!DOCTYPE html> - Declares this as an HTML5 document

  • <html> - Root element that wraps all content

  • <head> - Contains metadata about the document

  • <title> - Sets the page title (appears in browser tab)

  • <body> - Contains all visible content

HTML Tags and Elements

HTML uses tags to mark up content. Tags are enclosed in angle brackets < >.

Tag Structure:

  • Opening tag: <tagname>

  • Closing tag: </tagname>

  • Self-closing tag: <tagname />

Example:

Essential HTML Elements

Headings

HTML provides six levels of headings:

Paragraphs

Text Formatting

Images

Lists

Unordered Lists (Bullet Points)

Ordered Lists (Numbered)

Tables

  • <table> - Creates the table

  • <tr> - Table row

  • <th> - Table header cell

  • <td> - Table data cell

Forms

Common Input Types:

  • text - Single line text

  • email - Email address

  • password - Password field

  • number - Numeric input

  • checkbox - Checkbox

  • radio - Radio button

  • submit - Submit button

Semantic HTML Elements

These elements provide meaning to your content:

Attributes

HTML elements can have attributes that provide additional information:

Common Attributes:

  • id - Unique identifier for an element

  • class - Groups elements for styling

  • src - Source for images, videos, etc.

  • href - URL for links

  • alt - Alternative text for images

  • title - Tooltip text

  • target - How to open links

Comments

Add comments to your HTML code (not visible on the page):

Complete Example

Best Practices

  1. Always close your tags - Every opening tag should have a corresponding closing tag

  2. Use semantic elements - Choose elements based on meaning, not appearance

  3. Include alt text for images - Important for accessibility

  4. Indent your code - Makes it easier to read and debug

  5. Use lowercase for tags and attributes - Standard convention

  6. Validate your HTML - Use online validators to check for errors

Last updated