HTML Basics
HTML (HyperText Markup Language) is the standard markup language for documents designed to be displayed in a web browser. It defines the structure and content of web pages.
Document Structure
A basic HTML document has this structure:
1 |
|
<!DOCTYPE html>: Declares the document type and HTML version<html>: The root element of an HTML page<head>: Contains meta-information about the document<meta charset="UTF-8">: Specifies character encoding<meta name="viewport">: Controls viewport behavior on mobile devices<title>: Specifies the title shown in the browser tab<body>: Contains the visible page content
Essential HTML Elements
Headings
HTML offers six levels of headings:
1 | <h1>Main Heading</h1> |
Paragraphs
1 | <p>This is a paragraph of text.</p> |
Links
1 | <a href="https://example.com">Link text</a> |
Images
1 | <img src="image.jpg" alt="Description of image"> |
Lists
Unordered list:
1 | <ul> |
Ordered list:
1 | <ol> |
Divisions and Spans
1 | <div>A block-level container for grouping elements</div> |
Semantic HTML
Semantic elements clearly describe their meaning to both the browser and the developer:
1 | <header>Document or section header</header> |
Benefits of semantic HTML:
- Improves accessibility
- Enhances SEO
- Makes code more maintainable
Forms
Forms allow user input:
1 | <form action="/submit" method="post"> |
Common input types:
text: Single-line text inputemail: Email address inputpassword: Password inputnumber: Numeric inputcheckbox: Checkboxes for multiple selectionsradio: Radio buttons for single selectiontextarea: Multi-line text inputselect: Dropdown selection
Tables
1 | <table> |
HTML5 Features
- Audio and Video:
<audio>and<video>elements - Canvas:
<canvas>for drawing graphics - SVG: Scalable Vector Graphics
- Local Storage: Client-side data storage
- Geolocation: Access to user’s location
- Web Workers: Background processing
- Drag and Drop: Native drag-and-drop functionality
Best Practices
- Use semantic elements whenever possible
- Validate your HTML using the W3C validator
- Keep markup clean and properly indented
- Provide alt text for all images
- Use descriptive link text instead of “click here”
- Keep accessibility in mind at all times
- Separate structure (HTML) from presentation (CSS)
Learning Resources
HTML is the foundation of web development. Master these concepts before moving on to CSS and JavaScript.