HTML Quick Sheet
A comprehensive HTML cheatsheet to help you master web page structure, content, and semantic markup.
1. Introduction to HTML
What is HTML?
HTML (HyperText Markup Language) is the standard markup language for creating web pages and web applications. It provides the structure of a web page using a system of tags and attributes. HTML works in conjunction with CSS (for styling) and JavaScript (for interactivity) to build dynamic and visually appealing websites.
Key Features of HTML:
- Structure: HTML defines the basic structure of a web page, including headings, paragraphs, lists, links, images, and more.
- Markup Language: It uses tags to "mark up" the content, telling the browser how to display it.
- Hypertext: Allows for linking between documents, forming the "web" of information.
Basic HTML Document Structure
Every HTML document follows a basic structure, starting with a doctype declaration and containing <html>, <head>, and <body> tags.
<!DOCTYPE html>: Declares the document type and version of HTML (HTML5).<html>: The root element of an HTML page.<head>: Contains meta-information about the HTML document (e.g., title, character set, links to stylesheets).<body>: Contains the visible page content.
Here's the general structure:
Try it Yourself »index.html<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Page Title</title> </head> <body> <!-- Your visible content goes here --> <h1>Hello, HTML!</h1> <p>This is a paragraph.</p> </body> </html>
In the above example:
- The
<html lang="en">attribute specifies the language of the document. <meta charset="UTF-8">ensures proper character encoding.<meta name="viewport">is crucial for responsive design.
2. HTML Elements & Tags
HTML elements are the building blocks of web pages. They consist of a start tag, content, and an end tag. Some elements are self-closing (empty elements) and don't require an end tag.
Example:
Try it Yourself »index.html<!-- Paragraph element --> <p>This is a paragraph.</p> <!-- Image element (self-closing) --> <img src="image.jpg" alt="Description of image">
1. Common Block-Level Elements
Block-level elements always start on a new line and take up the full width available.
Examples:
Try it Yourself »index.html<h1>Heading 1</h1> <p>This is a paragraph.</p> <div>A generic container.</div> <ul> <li>List item 1</li> </ul> <form>Form content</form>
They are used for structuring major parts of the content.
2. Common Inline Elements
Inline elements do not start on a new line and only take up as much width as necessary.
Examples:
Try it Yourself »index.html<a href="#">Link</a> <span>A generic inline container.</span> <strong>Bold text</strong> <em>Emphasized text</em> <img src="icon.png" alt="Icon">
They are used for styling or marking up small pieces of content within a block.
<b>: Bold text (presentational, no added semantic importance).<i>: Italic text (presentational, no added semantic importance).<mark>: Highlighted text (marks text relevant in another context).
Try it Yourself »index.html<p>My <b>favorite</b> color is blue. This is <i>really</i> important. Please <mark>remember this</mark>.</p>
3. Self-Closing (Empty) Elements
These elements do not have closing tags because they don't contain content.
Examples:
Try it Yourself »index.html<img src="photo.jpg" alt="A photo"> <br> <!-- Line break --> <hr> <!-- Horizontal rule --> <input type="text"> <link rel="stylesheet" href="style.css">
They are used to embed external resources or create structural breaks.
<wbr>: Word Break Opportunity (suggests a line break in long words).
Try it Yourself »index.html<p>Thisis<wbr>avery<wbr>long<wbr>wordthatmightbreak.</p>
3. HTML Attributes
1. Global Attributes
Attributes that can be used on all HTML elements.
Examples:
Try it Yourself »index.html<div id="myDiv" class="container" style="color: blue;" data-info="example"> Content </div>
id: Unique identifier for an element.class: Specifies one or more class names for an element.style: Specifies inline CSS styles.data-*: Custom data attributes.title: Provides extra information (tooltip).lang: Specifies the language of the element's content.
2. Common Element-Specific Attributes
Attributes that are specific to certain HTML elements.
Examples:
Try it Yourself »index.html<a href="page.html" target="_blank">Visit Page</a> <img src="image.png" alt="A descriptive image" width="300" height="200"> <input type="text" name="username" value="JohnDoe" placeholder="Enter username" required>
href(for<a>): Specifies the URL of the page the link goes to.src(for<img>,<script>,<video>,<audio>): Specifies the path to the resource.alt(for<img>): Provides alternative text for an image.type(for<input>,<button>): Specifies the type of input/button.value(for<input>,<button>): Specifies the initial value.placeholder(for<input>,<textarea>): Provides a hint for the user.required(for<input>): Specifies that an input field must be filled out.
4. Document Structure: Head & Body
1. The <head> Section
Contains meta-information about the HTML document, not displayed directly on the page.
Example:
Try it Yourself »index.html<head> <meta charset="UTF-8"> <meta name="description" content="Free web tutorials"> <meta name="keywords" content="HTML, CSS, JavaScript"> <meta name="author" content="John Doe"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>My Awesome Page</title> <link rel="stylesheet" href="styles.css"> <script src="script.js" defer></script> </head>
<meta>: Provides metadata (charset, description, keywords, viewport).<title>: Defines the title of the document (shown in browser tab).<link>: Links to external resources (e.g., stylesheets, favicons).<style>: Contains internal CSS.<script>: Embeds or links to JavaScript code.<base>: Specifies the base URL/target for all relative URLs in the document.
Try it Yourself »index.html<head> <base href="https://www.example.com/images/" target="_blank"> </head> <body> <img src="image.jpg" alt="Example Image"> <!-- This will load from https://www.example.com/images/image.jpg --> </body>
2. The <body> Section
Contains all the visible content of the web page.
Example:
Try it Yourself »index.html<body> <header> <h1>Website Title</h1> <nav>...</nav> </header> <main> <section> <h2>About Us</h2> <p>Welcome to our site.</p> </section> <aside> <h3>Related Links</h3> <ul><li>...</li></ul> </aside> </main> <footer> <p>© 2025 My Website</p> </footer> </body>
Includes all text, images, forms, videos, and other content that users interact with.
5. Text Formatting
1. Headings (<h1> to <h6>)
Define headings of different levels, with <h1> being the most important.
Example:
Try it Yourself »index.html<h1>Main Title</h1> <h2>Section Heading</h2> <h3>Sub-section Heading</h3> <h4>Sub-sub-section Heading</h4> <h5>Smallest Heading (Level 5)</h5> <h6>Smallest Heading (Level 6)</h6>
2. Paragraphs (<p>) and Line Breaks (<br>)
<p> defines a paragraph. <br> inserts a single line break.
Example:
Try it Yourself »index.html<p>This is the first line.<br>This is the second line.</p>
3. Bold (<b>, <strong>) and Italic (<i>, <em>)
<strong> and <em> convey semantic importance/emphasis, while <b> and <i> are for stylistic purposes.
Example:
Try it Yourself »index.html<p>This is <strong>important</strong> text and <em>emphasized</em> text.</p> <p>This is <b>bold</b> text (without strong importance) and <i>italic</i> text (without emphasis).</p>
<mark>: Represents text that is marked or highlighted for reference or notation purposes.
Try it Yourself »index.html<p>Please ensure you <mark>read the instructions carefully</mark>.</p>
4. Lists (Unordered <ul>, Ordered <ol>, Description <dl>)
Used to present items in a list format.
Example:
Try it Yourself »index.html<ul> <li>Item 1</li> <li>Item 2</li> </ul> <ol> <li>First step</li> <li>Second step</li> </ol> <dl> <dt>Coffee</dt> <dd>- A hot black drink.</dd> <dt>Milk</dt> <dd>- A cold white drink.</dd> </dl>
<dl>: Defines a description list.<dt>: Defines a term (an item in a description list).<dd>: Defines a description of a term (an item in a description list).
5. Links (<a>)
Creates hyperlinks to other pages or resources.
Example:
Try it Yourself »index.html<a href="https://www.example.com" target="_blank">Visit Example.com</a> <a href="#section2">Go to Section 2</a>
6. Horizontal Rule (<hr>)
Represents a thematic break in content.
Example:
Try it Yourself »index.html<p>Content above the line.</p> <hr> <p>Content below the line.</p>
7. Other Text-Level Semantics
<del>: Represents a range of text that has been deleted from a document.<sub>: Renders text as a subscript.<sup>: Renders text as a superscript.<pre>: Represents preformatted text. Text inside is typically displayed in a fixed-width font, and it preserves both spaces and line breaks.<code>: Displays a short fragment of computer code. Often used inside<pre>tags for multi-line code blocks.<q>: Represents a short inline quotation. Browsers typically render this by enclosing the content in quotation marks.<abbr>: Represents an abbreviation or acronym; the expansion of the abbreviation can be provided via the title attribute.
Examples:
Try it Yourself »index.html<p>This is <del>old text</del> and this is H<sub>2</sub>O.</p> <p>The formula for water is H<sub>2</sub>O. In mathematics, $x^2$ is written as x<sup>2</sup>.</p> <pre><code>function hello() { console.log('Hello'); }</code></pre> <p>As <q>to be or not to be</q>, that is the question.</p> <p>The <abbr title="World Health Organization">WHO</abbr> was founded in 1948.</p>
6. HTML Forms
1. The <form> Element
Used to collect user input.
Example:
Try it Yourself »index.html<form action="/submit-form" method="post"> <label for="fname">First name:</label><br> <input type="text" id="fname" name="fname"><br> <input type="submit" value="Submit"> </form>
<fieldset>: Groups related elements in a form.<legend>: Provides a caption for the<fieldset>.
Try it Yourself »index.html<form> <fieldset> <legend>Personal Information:</legend> <label for="firstname">First Name:</label><br> <input type="text" id="firstname" name="firstname"><br> </fieldset> </form>
2. Input Types (<input>)
Various types for different data input.
Example:
Try it Yourself »index.html<input type="text" placeholder="Name"> <input type="email" placeholder="Email"> <input type="password" placeholder="Password"> <input type="number" min="1" max="10"> <input type="date"> <input type="checkbox" id="agree"><label for="agree">Agree</label> <input type="radio" id="male" name="gender" value="male"><label for="male">Male</label> <input type="file"> <input type="submit" value="Send">
3. Textarea (<textarea>)
For multi-line text input.
Example:
Try it Yourself »index.html<textarea name="message" rows="5" cols="30" placeholder="Your message"></textarea>
4. Dropdown Lists (<select> and <option>)
Allows users to select one or more options from a list.
Example:
Try it Yourself »index.html<select name="cars" id="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> </select>
<optgroup>: Groups related options in a drop-down list.
Try it Yourself »index.html<select name="vehicles"> <optgroup label="Cars"> <option value="audi">Audi</option> <option value="bmw">BMW</option> </optgroup> <optgroup label="Bikes"> <option value="honda">Honda</option> <option value="yamaha">Yamaha</option> </optgroup> </select>
<datalist>: Specifies a list of pre-defined options for an<input>element.
Try it Yourself »index.html<input list="browsers" name="browser"> <datalist id="browsers"> <option value="Edge"> <option value="Firefox"> <option value="Chrome"> </datalist>
5. Buttons (<button>)
Clickable buttons for various actions.
Example:
Try it Yourself »index.html<button type="submit">Submit Form</button> <button type="reset">Reset Form</button> <button type="button">Click Me</button>
6. Labels (<label>)
Provides a caption for an item in a user interface.
Example:
Try it Yourself »index.html<label for="username">Username:</label> <input type="text" id="username" name="username">
7. Form Output (<output>)
<output>: Represents the result of a calculation.
Try it Yourself »index.html<form oninput="result.value=parseInt(a.value)+parseInt(b.value)"> <input type="number" id="a" value="10"> + <input type="number" id="b" value="20"> = <output name="result" for="a b"></output> </form>
7. HTML Tables
1. Basic Table Structure
Used to display tabular data.
Example:
Try it Yourself »index.html<table> <tr> <th>Header 1</th> <th>Header 2</th> </tr> <tr> <td>Data 1</td> <td>Data 2</td> </tr> </table>
2. Table Headers (<th>) and Data Cells (<td>)
<th> defines a header cell, <td> defines a standard data cell.
Example:
Try it Yourself »index.html<tr> <th>Name</th> <th>Age</th> </tr> <tr> <td>Alice</td> <td>30</td> </tr>
3. Table Sections: <thead>, <tbody>, <tfoot>
Semantic grouping for table content.
Example:
Try it Yourself »index.html<table> <thead> <tr><th>Header</th></tr> </thead> <tbody> <tr><td>Body Data</td></tr> </tbody> <tfoot> <tr><td>Footer</td></tr> </tfoot> </table>
<caption>: Specifies the caption of a table.
Try it Yourself »index.html<table> <caption>Monthly Savings</caption> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>January</td> <td>$100</td> </tr> </table>
4. Spanning Rows/Columns (rowspan, colspan)
Merge cells across rows or columns.
Example:
Try it Yourself »index.html<table border="1"> <tr> <th colspan="2">Name</th> <th rowspan="2">Age</th> </tr> <tr> <td>First</td> <td>Last</td> </tr> </table>
8. HTML Multimedia
1. Images (<img>)
Embeds an image into the document.
Example:
Try it Yourself »index.html<img src="myimage.jpg" alt="A beautiful landscape" width="500" height="300">
<picture>: Allows you to display different images based on screen size or resolution.<map>and<area>: Define a client-side image map (clickable areas on an image).
Try it Yourself »index.html<picture> <source media="(min-width:650px)" srcset="img_white_flower.jpg"> <img src="img_pink_flower.jpg" alt="Flowers" style="width:auto;"> </picture> <img src="planets.gif" alt="Planets" usemap="#planetmap"> <map name="planetmap"> <area shape="rect" coords="0,0,82,126" href="sun.htm" alt="Sun"> <area shape="circle" coords="90,58,3" href="mercury.htm" alt="Mercury"> </map>
2. Audio (<audio>)
Embeds audio content.
Example:
Try it Yourself »index.html<audio controls> <source src="audio.mp3" type="audio/mpeg"> <source src="audio.ogg" type="audio/ogg"> Your browser does not support the audio element. </audio>
3. Video (<video>)
Embeds video content.
Example:
Try it Yourself »index.html<video width="320" height="240" controls> <source src="movie.mp4" type="video/mp4"> <source src="movie.ogg" type="video/ogg"> Your browser does not support the video tag. </video>
4. Iframes (<iframe>)
Embeds another HTML document within the current document.
Example:
Try it Yourself »index.html<iframe src="https://www.w3schools.com" title="W3Schools Free Online Web Tutorials"></iframe>
5. Generic Embeds (<embed>, <object>, <param>)
<embed>: Used as a container for external content (e.g., plugins, interactive content).<object>: Embeds external resources (generic object).<param>: Defines parameters for<object>elements.
Try it Yourself »index.html<embed type="video/quicktime" src="movie.mov" width="300" height="200"> <object data="flashmovie.swf" type="application/x-shockwave-flash" width="300" height="200"> <param name="quality" value="high"> </object>
9. Semantic HTML5
1. What is Semantic HTML?
Using HTML elements according to their meaning, not just for presentation.
Example:
Try it Yourself »index.html<!-- Non-semantic --> <div id="header">...</div> <!-- Semantic --> <header>...</header>
2. Common Semantic Elements
<header>: Introduction content, navigation.<nav>: Navigation links.<main>: Dominant content of the<body>.<article>: Self-contained content (e.g., blog post).<section>: Generic standalone section of a document.<aside>: Content tangentially related to the content around it.<footer>: Footer for a document or section.<figure>and<figcaption>: For self-contained content with a caption.<time>: Represents a specific period in time.<address>: Defines contact information for the author/owner of a document or an article.
Try it Yourself »index.html<address> Written by John Doe.<br> Visit us at:<br> Example.com<br> Box 564, Disneyland<br> USA </address>
Example:
Try it Yourself »index.html<article> <h2>Blog Post Title</h2> <p>Content of the post.</p> <footer>Published on <time datetime="2024-07-15">July 15, 2024</time></footer> </article>
10. Accessibility (A11y)
1. Importance of Accessibility
Making web content usable by people with disabilities (e.g., visual, auditory, motor, cognitive).
2. Alt Text for Images
Provides a textual alternative for images, crucial for screen readers.
Example:
Try it Yourself »index.html<img src="cat.jpg" alt="A fluffy cat sitting on a couch"> <!-- If image is purely decorative: --> <img src="spacer.gif" alt="">
3. Semantic HTML for Structure
Using elements like <header>, <nav>, <main>, <footer> helps screen readers understand page layout.
4. ARIA Attributes
Accessible Rich Internet Applications (ARIA) attributes provide additional semantics for dynamic content and custom UI controls.
Example:
Try it Yourself »index.html<button aria-expanded="false" aria-controls="menu">Toggle Menu</button> <div role="alert">Error message!</div>
5. Keyboard Navigation
Ensure all interactive elements are reachable and operable via keyboard (e.g., using Tab key).
Use proper HTML elements like <a> for links and <button> for buttons, as they have built-in keyboard support.
11. HTML Entities
1. What are HTML Entities?
Special characters that are reserved in HTML or are not present on a standard keyboard.
Example:
Try it Yourself »index.html<p>right &; 2024</p> <p>Less than: <</p> <p>Greater than: ></p> <p>Ampersand: &</p> <p>Non-breaking space: </p>
2. Common HTML Entities
HTML
12. HTML Best Practices
1. Valid HTML
Always validate your HTML to ensure it conforms to W3C standards. This helps with cross-browser compatibility and SEO.
W3C HTML Validator
Example (using a validator):
Try it Yourself »index.html<!-- This HTML has a missing closing tag for 'p' --> <div> <p>This is a paragraph. </div> <!-- A validator would flag this as an error. -->
2. Use Semantic Markup
Choose the HTML element that best describes the content. This improves accessibility and SEO.
Example:
Try it Yourself »index.html<!-- Bad: Using div for everything --> <div class="header">...</div> <!-- Good: Using semantic header --> <header>...</header>
3. Keep Code Clean and Organized
Indent your code properly.
Use meaningful IDs and class names.
Add comments for complex sections.
Example:
Try it Yourself »index.html<!-- Main navigation section --> <nav class="main-nav"> <ul> <li><a href="/">Home</a></li> <li><a href="/about">About</a></li> </ul> </nav>
4. Optimize for Performance
Minimize DOM depth.
Use appropriate image formats and sizes.
Defer non-critical JavaScript.
13. Tools and Resources
1. HTML Validators
Check for errors and ensure compliance with web standards.
W3C HTML Validator
Example (using a validator):
Try it Yourself »index.html<!-- This HTML has a missing closing tag for 'p' --> <div> <p>This is a paragraph. </div> <!-- A validator would flag this as an error. -->
2. Online HTML Editors/Playgrounds
Write, test, and share HTML code directly in your browser.
- CodePen
- JSFiddle
- W3Schools Tryit Editor
Example (Using an online editor):
Try it Yourself »index.html<!DOCTYPE html> <html> <head> <title>My Live Demo</title> </head> <body> <h1>Hello from CodePen!</h1> </body> </html>
3. Learning Resources
Further your HTML knowledge with these resources:
Websites:
- MDN Web Docs (HTML)
- W3Schools HTML Tutorial
- freeCodeCamp (Basic HTML)
Books:
- "HTML and CSS: Design and Build Websites" by Jon Duckett
Courses:
- Udemy
- Coursera
📌 Note:
Tap on any of the links above to directly open the tools and resources in your browser. These will help you write, test, and improve your HTML faster and more efficiently!
14. Miscellaneous HTML Elements
1. Canvas (<canvas>)
Definition: Used to draw graphics on a web page using JavaScript. Ideal for animations, games, and data visualizations.
Try it Yourself »index.html<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;"></canvas> <script> const canvas = document.getElementById('myCanvas'); const ctx = canvas.getContext('2d'); ctx.fillStyle = "#FF0000"; ctx.fillRect(0,0,150,75); </script>
2. Meter (<meter>)
Definition: Represents a scalar measurement within a known range, or a fractional value; for example, disk usage, relevance of a query result.
Try it Yourself »index.html<label for="disk_c">Disk usage C:</label> <meter id="disk_c" value="2" min="0" max="10">2 out of 10</meter>
3. Progress (<progress>)
Definition: Displays the progress of a task.
Try it Yourself »index.html<label for="file">Downloading progress:</label> <progress id="file" value="32" max="100"> 32% </progress>
4. Noscript (<noscript>)
Definition: Defines an alternate content for users that have disabled scripts in their browser or have a browser that doesn't support client-side scripting.
Try it Yourself »index.html<script>document.write("Hello JavaScript!")</script> <noscript>Your browser does not support JavaScript!</noscript>
5. Keygen (<keygen>) - Deprecated
Definition: This element was used to generate a pair of keys, and submit the public key to the server. It is deprecated in HTML5 and should not be used.