Description and Basic Syntax
HTML (HyperText Markup Language) is the standard markup language for creating web pages and web applications. It provides the semantic structure and content of web documents, serving as the foundation upon which CSS and JavaScript build.
Declarative Language: Describes what should be displayed, not how to compute it
Semantic Markup: Elements convey meaning about their content
Tree Structure: Nested elements form a Document Object Model (DOM)
Fault-Tolerant: Browsers attempt to render even malformed HTML
HTML terminology
Tags
Tags are the building blocks of HTML that define how content should be structured and displayed. They are keywords wrapped in angle brackets < >.
<!-- Opening and closing tags -->
<p>This is a paragraph</p>
<!-- Self-closing tags (void elements) -->
<img src="image.jpg" alt="Description">
<br>
<hr>
<input type="text">
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css">HTML tags come in two types. Opening and closing tags like <p>...</p> wrap around content to define its purpose. Self-closing tags like <img>, <br>, and <hr> don't need a closing tag because they represent single elements without content inside them. These are also called void elements.
Common tags by category:
Structural:
<html>,<head>,<body>Text:
<p>,<h1>...<h6>,<span>,<strong>,<em>Container:
<div>,<section>,<article>,<main>Lists:
<ul>,<ol>,<li>,<dl>,<dt>,<dd>Media:
<img>,<video>,<audio>,<picture>Interactive:
<a>,<button>,<form>,<input>
Elements
Elements are complete HTML components consisting of:
Opening tag
Content (optional)
Closing tag (unless self-closing)
Elements can be nested to create complex document structures:
HTML elements can be placed inside each other to create structured documents. An article contains a header, which itself contains a heading and time element, plus a paragraph. This nesting creates a tree-like hierarchy that browsers use to render the page.
Attributes
Attributes provide additional information about elements. They appear in the opening tag as name/value pairs:
Attributes provide additional information about HTML elements and appear inside the opening tag as name-value pairs. Global attributes like id, class, and data-* work on any element. Element-specific attributes like href for links or src for images only apply to certain tags.
Essential Global Attributes:
id- Unique identifierclass- CSS styling hooks (space-separated list)data-*- Custom data attributes for JavaScriptstyle- Inline CSS (use sparingly)title- Tooltip textlang- Language specificationdir- Text direction (ltr/rtl)hidden- Hide elementtabindex- Tab order for keyboard navigationcontenteditable- Make content editable

The complete HTML5 document structure
Every HTML page needs a standard skeleton structure. The <!DOCTYPE html> declaration identifies the document type. The <head> section contains metadata, character encoding, viewport settings, SEO information, and links to external resources. The <body> contains all visible content organized with semantic elements.
Important Meta tags for modern web apps:
Meta tags control browser and search engine behavior without appearing on the page. The viewport tag enables responsive design on mobile devices. Theme-color sets the browser toolbar color on mobile. Robots controls search engine indexing. Refresh auto-reloads pages. Content-Security-Policy enhances security by restricting resource loading.
Divisions and Spans
Container elements that have no semantic meaning on their own, used primarily for styling and JavaScript manipulation:
<div> creates block-level containers that take full width and start on new lines. <span> creates inline containers that only take up as much space as their content. Both are generic containers without semantic meaning, primarily used for styling or JavaScript manipulation. Modern semantic alternatives like <main>, <section>, and <article> should be preferred when they match the content's purpose.
Linking Between Pages and Resources
Creating Hyperlinks
The <a> (anchor) element creates hyperlinks to other pages, files, locations within the same page, email addresses, or any other URL:
The <a> (anchor) element creates clickable links to other pages, sections, emails, or phone numbers. External links use absolute URLs, internal links use relative paths. Fragment identifiers starting with # jump to sections on the same page. The target="_blank" attribute opens links in new tabs. Always include rel="noopener noreferrer" for security when opening external sites.
Link Best Practices:
Use descriptive link text (avoid "click here")
Include
rel="noopener noreferrer"fortarget="_blank"links (security)Use relative URLs for internal links (maintainability)
Consider adding
titleattributes for additional context
Adding Media
Images
Images are embedded using the <img> tag with required src and alt attributes. The <picture> element enables responsive images that adapt to screen size. The loading="lazy" attribute improves performance by deferring offscreen images. Setting explicit width and height prevents layout shift during page loading. The <figure> and <figcaption> elements semantically group images with their captions.
Video and Audio
HTML5 provides native media support without plugins. The <video> and <audio> elements accept multiple <source> children with different file formats, allowing browsers to choose supported formats. The controls attribute adds playback controls. Fallback content inside the media tags appears in browsers without HTML5 support.
Background Images (CSS)
While not HTML, background images are commonly set via CSS:
Background images are set using CSS properties rather than HTML. The background-size: cover property scales images to fill containers. The background-position: center property centers images. The background-repeat: no-repeat property prevents tiling. These properties are commonly used for hero sections and decorative backgrounds.
Display Types: Block vs. Inline vs. Inline-block
Understanding how elements display is crucial for layout control:
Block Elements
Characteristics:
Start on a new line
Occupy full width available
Stack vertically
Respect all margin and padding values
Can contain other block and inline elements
Inline Elements
Characteristics:
Flow within text content
Only occupy necessary width
Don't force line breaks
Ignore top/bottom margins
Vertical padding may overlap other lines
Cannot contain block elements
Inline-block Elements
Characteristics:
Flow inline like text
Respect width and height
Respect all margins and paddings
Don't force line breaks
Inline-block elements combine inline flow with block dimensioning. They sit side-by-side like inline elements but accept width and height like blocks. Form elements like <button>, <input>, <select>, and <textarea> are naturally inline-block. Any element can be converted using CSS display: inline-block, useful for creating side-by-side cards or navigation buttons.
HTML5 Semantic Elements
Semantic elements clearly describe their meaning to both the browser and developer, improving:
SEO: Search engines better understand content structure
Accessibility: Screen readers can navigate more effectively
Maintainability: Code is self-documenting
Styling: More specific CSS targeting
Common Semantic Elements
HTML5 semantic elements describe their purpose and content type. The <header> contains introductory content, <nav> holds navigation menus, <main> wraps primary content, <article> represents standalone content, <section> groups thematic content, <aside> holds sidebar content, and <footer> contains footer information. Using semantic tags instead of generic divs improves accessibility, SEO, and code readability.
Additional Semantic Elements
HTML5 provides specialized elements for specific purposes. The <details> and <summary> elements create collapsible sections with built-in functionality. The <figure> and <figcaption> elements semantically group images with captions. The <mark> element highlights text. The <progress> element displays progress bars. The <dialog> element creates modal dialogs.
Forms and Input Elements
Forms are crucial for user interaction in web applications:
Forms collect user input through various input types. Text inputs, email fields, passwords, numbers, dates, and file uploads each have specific input types. Dropdown menus use <select> with <option> children. Radio buttons allow single selections from groups. Checkboxes enable multiple selections. Text areas accept multi-line input. The <form> element wraps inputs and defines submission behavior. Attributes like required, min, max, and pattern provide built-in validation.
Modern Input Types (HTML5)
HTML5 introduced specialized input types for better user experiences. Color pickers, range sliders, search boxes, telephone inputs, URL fields, and time pickers provide optimized interfaces. Mobile browsers display appropriate keyboards for each type. Datalists enable autocomplete functionality by suggesting values as users type. Browsers provide built-in validation for these specialized types.
Best Practices for Modern HTML
1. Semantic HTML First
Semantic tags convey meaning while generic divs do not. Using <header> and <nav> instead of <div class="header"> and <div class="nav"> makes HTML more meaningful. Semantic markup improves accessibility for screen readers, helps search engines understand content structure, and makes code easier to read and maintain.
2. Accessibility (a11y)
Accessible websites work for all users including those with disabilities. Images require alt attributes so screen readers can describe them. Icon buttons need ARIA labels to convey their purpose. Form inputs must be connected to labels using matching for and id attributes. Skip links help keyboard users jump directly to main content without tabbing through navigation.
3. Performance Optimization
Performance techniques improve page loading speed and user experience. The loading="lazy" attribute defers loading offscreen images until needed. The rel="preload" attribute loads critical resources early. The defer attribute on script tags loads JavaScript without blocking page rendering. Faster pages rank higher in search engines and reduce bounce rates.
4. SEO Optimization
Search engines use metadata to understand and display content. Descriptive title tags appear in search results and browser tabs. Meta descriptions under 160 characters show in search snippets. Structured data using Schema.org JSON-LD format enables rich results with ratings, prices, or other enhanced information. These optimizations improve visibility and click-through rates.
5. Mobile-First Design
The viewport meta tag is essential for responsive websites. It tells mobile browsers to use device width instead of desktop width. Touch-friendly interfaces require tap targets at least 44x44 pixels for easy finger interaction. Mobile-first design ensures websites function properly on smartphones and tablets where most web traffic originates.
6. Progressive Enhancement
Progressive enhancement builds websites that work for everyone then adds features for modern browsers. Providing fallback content ensures users with older browsers or disabilities can still access information. Video elements should include download links for browsers without HTML5 support. Core functionality should never depend on cutting-edge features.
HTML Validation and Testing
Validation Tools
W3C Validator: validator.w3.org
HTML5 Validator: Browser developer tools
Accessibility: WAVE, axe DevTools
Common Validation Errors
Valid HTML follows specific nesting rules. Anchor tags cannot be nested inside each other. Block elements cannot be placed inside inline elements. ID attributes must be unique across the entire page. Following these rules ensures consistent rendering across browsers and prevents accessibility issues. Validators can automatically detect these common mistakes.
Integration with Modern Frameworks
When working with Vue.js (which you'll study later), HTML becomes templated:
JavaScript frameworks transform HTML into dynamic templates. Double curly braces display JavaScript variables and expressions. The v-for directive loops through arrays to create repeated elements. The :key attribute helps frameworks track elements efficiently. Event listeners like @click connect user actions to JavaScript functions. This templating approach enables reactive interfaces that update automatically when data changes.
This foundation in semantic HTML will be essential when you build dynamic applications with Express, Firebase, and Vue.js, as these frameworks ultimately generate and manipulate HTML in the browser.
Summary
HTML provides the structural foundation of web applications. While frameworks like Vue.js abstract much of the HTML writing, understanding these fundamentals is crucial for:
Debugging rendered output
Optimizing performance
Ensuring accessibility
Improving SEO
Creating maintainable applications
Remember: Good HTML is semantic, accessible, and performant - principles that apply whether you're writing HTML directly or through a framework.
Last updated
Was this helpful?