Skip to content

html_examples

This section provides quick links to examples demonstrating various HTML features and techniques. Explore these to see HTML in action.

Basic HTML Document Structure HTML Headings (h1-h6) HTML Paragraphs (<p>) HTML Links (<a>) HTML Images (<img>)

Core examples covering fundamental HTML elements.

The title attribute (tooltip) The href attribute (link destination) The width and height attributes (image dimensions - consider CSS) The alt attribute (image alternative text - crucial for accessibility) Boolean attributes (e.g., disabled, checked)

Examples demonstrating how attributes modify HTML elements. Note: While boolean attributes can be written without values (e.g., <input disabled>), quoting attribute values (e.g., href="...") is standard practice.

HTML Headings (<h1> to <h6>) Horizontal Rules (<hr>) The <head> Element (metadata, title, links to CSS/JS)

Structuring content logically within an HTML document.

Paragraphs (<p>) Line Breaks (<br>) Preformatted Text (<pre>) Controlling whitespace

Managing text flow and presentation.

Inline Styles (using the style attribute - use sparingly) Internal CSS (using <style> tag in <head>) External CSS (linking a .css file - recommended) Styling: Background Color, Text Color, Fonts, Text Size, Text Alignment

Illustrating different ways to apply CSS for styling. External CSS is the best practice for maintainability.

Bold Text: ** (non-semantic) vs ** (semantic importance) Italic Text: <i> (non-semantic) vs <em> (semantic emphasis) Small Text (<small>) Marked/Highlighted Text (<mark>) Deleted Text (<del>) Inserted Text (<ins>) Subscript (<sub>) Superscript (<sup>)

Using tags that convey meaning (semantic) vs. just visual styling.

Short Inline Quotations (<q>) Longer Block Quotations (<blockquote>) Contact Information (<address>) Abbreviations and Acronyms (<abbr> with title attribute) Work Titles (<cite>) Bi-Directional Override (<bdo>)

Marking up specific types of textual content.

Keyboard Input (<kbd>) Sample Output (<samp>) Code Snippets (``` - often used with <pre>) Variables (<var>)

Representing computer-related text semantically.

Adding Comments (<!-- ... -->) for explanations or debugging.

Using comments effectively. Note: Conditional comments for IE are obsolete.

Inline, Internal, External CSS recap CSS Selectors: id (#myId) and class (.myClass) CSS Box Model: Borders, Padding, Margin Full CSS Demo

Deeper dive into how HTML structure works with CSS selectors and the box model.

Absolute vs. Relative URLs Styling Links (color, text-decoration) Link Targets (target="_blank" to open in new tab) Image Links Bookmark Links (linking within the same page using IDs) Mailto Links (`href=“mailto:…”)

Creating hyperlinks to navigate between pages or resources.

Basic Image Embedding (src, alt) Image Dimensions (width, height - CSS preferred for responsiveness) Images in Folders Handling Broken Links (importance of alt text) Linking to External Images Image Maps (client-side <map> - less common now) Responsive Images using <picture> and srcset attribute.

Embedding and managing images, including modern responsive techniques.

Basic Table Structure (<table>, <tr>, <td>, <th>) Table Borders (CSS) Cell Padding & Spacing (CSS padding, border-spacing) Table Headers (<thead>, <th>, scope attribute) Table Body (<tbody>) Table Footer (<tfoot>) Captions (<caption>) Spanning Columns (colspan) and Rows (rowspan) Styling Tables with CSS (classes, IDs)

Structuring and displaying tabular data. Use tables for data, not for page layout.

Unordered Lists (<ul>, <li>, CSS list-style-type) Ordered Lists (<ol>, <li>, type, start attributes) Description Lists (<dl>, <dt>, <dd>) Nested Lists Styling Lists (e.g., horizontal navigation menus with CSS)

Organizing content into lists.

Understanding Block-level elements (e.g., <div>, <p>, <h1>) Understanding Inline elements (e.g., <span>, <a>, <img>) Using <div> for grouping block content Using <span> for styling inline content

Distinguishing between element display types.

Using the class attribute (for multiple elements) Using the id attribute (for unique elements) Styling with Classes and IDs in CSS Using Classes and IDs for JavaScript hooks

Applying identifiers for styling and scripting.

Layout using Semantic Elements (<header>, <nav>, <main>, <aside>, <footer>) CSS Flexbox for 1D layouts (e.g., navigation, aligning items) CSS Grid for 2D layouts (e.g., page structure, complex grids) Layout using <table> (discouraged - only for tabular data)

Structuring web page layouts using modern CSS (Flexbox, Grid) and semantic HTML.

Embedding another HTML page within the current page.

Using inline frames.

The <title> element The <style> element (Internal CSS) The <link> element (External CSS, favicons) The <meta> element (charset, viewport, description) The <script> element (JavaScript) The <base> element (setting base URL)

Understanding the role of elements within the <head>.

Embedding JavaScript (inline vs. external .js file - external recommended) The <noscript> tag (fallback content)

Integrating JavaScript into HTML.

Creating Forms (<form>, action, method) Text Input (<input type="text">, <label>) Password Input (<input type="password">) Radio Buttons (<input type="radio">, name attribute) Checkboxes (<input type="checkbox">) Submit Button (<input type="submit">, <button type="submit">) Grouping Form Data (<fieldset>, <legend>) Associating Labels (<label for="..."> and matching id)

Building interactive forms for user input.

Dropdown Lists (<select>, <option>, <optgroup>) Text Areas (<textarea>) Buttons (<button type="button|submit|reset">) Datalists (<datalist> for input suggestions) Output Element (<output> for calculation results)

Exploring additional form controls. Note: <keygen> is deprecated and removed from web standards.

text, password, radio, checkbox, button, submit Modern Types: number, date, color, range, month, week, time, datetime-local, email, search, tel, url, file

Utilizing specialized input types for better UI and validation.

Validation: required, pattern, min, max, step, minlength, maxlength UI/Behavior: placeholder, readonly, disabled, autofocus, multiple (for email, file) Form Association: form, formaction, formenctype, formmethod, formnovalidate, formtarget Other: list (for <datalist>), autocomplete

Enhancing input fields with attributes for validation and user experience. novalidate on the <form> disables browser validation.

Canvas: Drawing shapes, text, gradients, images using JavaScript APIs. SVG: Defining vector graphics (circles, rectangles, paths) using XML markup.

Creating graphics directly within HTML.

Embedding Audio (<audio>, <source>, controls, autoplay, loop, muted) Embedding Video (<video>, <source>, controls, autoplay, loop, muted, poster) Providing captions/subtitles (<track>)

Integrating audio and video content.

Geolocation API (getting user location) Web Storage (Local & Session Storage) Web Workers (background JavaScript execution) Server-Sent Events (SSE - server push) Drag and Drop API

Examples of powerful browser APIs interacting with HTML. Note: Application Cache is deprecated; use Service Workers instead.