Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Understanding HTML: A Comprehensive Guide

Tech May 18 3
  1. What is HTML?

HTML stands for Hyper Text Markup Language. It is the standard language used to create and design web pages.

An HTML file is a plain text document, usually saved with a .html extension (.htm is less common). You can create or edit HTML files using any text editor, such as Windows Notepad, Linux Vim, Notepad++, Sublime Text, or VS Code.

Every web page is essentially an HTML document. When you visit a URL in a browser, you are downloading, parsing, and displaying an HTML document. A collection of HTML documents placed in a folder and made accessible online forms a website.

It is important to understand that HTML is not a programming language. It has no logic, no computational ability, and cannot generate dynamic content. Its purely for structuring and presenting static information on a web page.

Let's break down the name "Hyper Text Markup Language" to understand its core:

1) Hyper Text

"Hyper Text" means beyond plain text. HTML documents can contain not just text, but also images, audio, video, tables, lists, links, buttons, input fields, and other rich content.

Hyperlinks are the backbone of the internet. They connect different web pages together, forming a vast "web" of information. Without hyperlinks, the internet as we know it would not exist.

2) Markup Language

HTML is a computer language, but it is not for programming. It is used to mark up content with tags. These tags define the structure, format, and meaning of different parts of the content.

For example:

  • ![]() marks an image
  • <a> marks a link
  • <input></input> marks a paragraph of text - ** makes text bold - <div> marks a block-level layout division HTML uses tags (markup instructions) to display content like text, audio, video, images, tables, buttons, and input fields. In short, HTML is used for laying out and formatting web page content. ## 2. HTML Elements ### 2.1. Block-level Elements Block-level elements typically start on a new line and occupy the full width of their parent container (unless styled otherwise with CSS). They are used for structuring the main layout of a page. Common block-level elements include: - <div>: A generic container, often used for grouping and layout. No default styling. html <div>This is a div element, which is a block-level element.</div> - : Defines a paragraph. 8971198392 - to ###### : Heading elements, with `` being the highest level and ###### the lowest. ```html This is a main heading ======================

This is a secondary heading ---------------------------

- ``: Ordered list.html 1. First item 2. Second item

- : Unordered list.html - Item one - Item two

- - : List item, used inside `` or .html - Apple - Banana

- ``: Represents the introductory content or navigational aids for a page or section.html My Website

- ``: Represents the footer of a page or section, often containing copyright info or links.html © 2023 My Website - ``: Represents a self-contained, reusable piece of content, like a blog post or news story.html Article Title -------------

Here is the article content...

- ``: Represents a thematic grouping of content, typically with a heading.html Section Title -------------

Here is the section content...

- ``: Represents a section with navigation links.html - Home- About Us

- ``: Represents content tangentially related to the main content, like a sidebar.html Sidebar Title -------------

Sidebar content...

- ``: Represents the dominant content of the document. There should be only one `` per page.html Main Content Title

Main content...

- > : Represents a long quotation from another source.html > This is a quotation... > > - ``: Provides contact information for the author/owner of the document or article.html Contact: example@example.com \*\*Note:\*\* With HTML5, many new semantic block-level elements were introduced. Older presentational elements like `` and `` are deprecated and should be avoided. ### 2.2. Inline Elements Inline elements do not start on a new line. They only take up as much width as necessary and flow within the text. They are used to style or mark up parts of a text line. Common inline elements include: - ``: A generic inline container, often used for styling small sections of text.html This text is red. > > - ``: Creates a hyperlink.html Visit Example.com - : Embeds an image. Although inline, it can have dimensions set via CSS/attributes.html - **: Indicates strong importance, typically displayed as bold.html This text contains important information. > > - *: Indicates emphasis, typically displayed as italic.html This text contains emphasized text. > > - > : Inserts a line break. It is an empty (self-closing) element.html First line. > Second line. > > -: Represents computer code, usually displayed in a monospace font. html <p>Example code: var x = 5;</p> - : Underlines text. However, or CSS is often preferred for semantic clarity. html <p>This is <u>underlined</u> text.</p> - : Represents inserted text, usually displayed with an underline. ```html <p>This is <ins>newly inserted</ins> text.</p> ```- : Represents deleted text, usually displayed with a strikethrough. html <p>This is <del>deleted</del> text.</p> - : Represents a short inline quotation. Browsers typically add quotation marks. ```html <p>He said: <q>This is a great example.</q></p> ```- : Represents subscript text (e.g., chemical formulas). html <p>Water is H<sub>2</sub>O.</p> - : Represents superscript text (e.g., exponents, footnotes). ```html <p>2<sup>3</sup> equals 8.</p> ```- : Defines a label for a form control. It behaves as an inline element and improves usability by associating text with an input. html <label for="username">Username:</label> <input id="username" type="text"></input> ### 2.3. Inline-Block ElementsThere is no dedicated "inline-block" element type in HTML. However, the CSS property display: inline-block allows any element to behave as a hybrid: it flows inline with text (like an inline element) but can have explicit width, height, margins, and padding (like a block element).Examples of elements often styled this way:- with display: inline-block: ```html <span style="display: inline-block; width: 100px; height: 50px; background-color: lightblue;">Inline-block</span> ```- with display: inline-block: html </a><a href="#" style="display: inline-block; width: 150px; height: 50px; background-color: lightgreen; text-align: center; line-height: 50px;">Click Me</a> - : Buttons can be styled with inline-blockfor precise control. ```html <button style="display: inline-block; width: 100px; height: 50px;">Button</button> ```-: Images are naturally inline but can have width and height via attributes or CSS. They behave similarly to inline-block elements in that they respect width/height without breaking the line.Remember: no element is inline-block by default. You achieve this behavior via CSS.### 2.4. Form ElementsForm elements are used to collect user input and submit it to a server.- : Container for form controls. It defines the action (where to send data) and method (how to send data, e.g., get or post). html </form><form action="/submit-form" method="post"> </form> - : The most versatile form element. Its behavior changes based on the typeattribute. - Text field:type="text" ```html <input name="username" placeholder="Username" type="text"></input> ``` - Password field:type="password" ```html <input name="password" placeholder="Password" type="password"></input> ``` - Submit button:type="submit" ```html <input type="submit" value="Submit"></input> ``` - Radio button:type="radio" ```html <input name="gender" type="radio" value="male"></input> Male <input name="gender" type="radio" value="female"></input> Female ``` - Checkbox:type="checkbox" ```html <input name="interest" type="checkbox" value="sports"></input> Sports <input name="interest" type="checkbox" value="music"></input> Music ```-: Multi-line text input area. html <textarea cols="30" name="message" placeholder="Enter your message here..." rows="10"></textarea> - : A clickable button. Can be used for form submission, reset, or custom actions. - Submit: type="submit" ```html <button type="submit">Submit</button> ``` - Reset:type="reset" ```html <button type="reset">Reset</button> ``` - Button (custom action):type="button" ```html <button type="button">Click Me</button> ```-: Dropdown menu. - Single select: html <select name="country"> <option value="china">China</option> <option value="usa">USA</option> </select> - Multiple select (with multiple attribute): html <select multiple="multiple" name="hobbies"> <option value="reading">Reading</option> <option value="swimming">Swimming</option> <option value="coding">Coding</option> </select> - : Defines a label for a form control. Clicking the label focuses the associated input. ```html <label for="email">Email:</label> <input id="email" name="email" type="email"></input> ```- : Groups related form elements. Often used with for a group title. ```html </legend><fieldset> <legend>Personal Information</legend> <input name="firstname" placeholder="First Name" type="text"></input> <input name="lastname" placeholder="Last Name" type="text"></input> </fieldset> ```### 2.5. Table ElementsTables are used to display data in rows and columns.Core table elements:-: The container for the entire table. ```html `***

============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

=====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

**

- `<tr>`: Defines a table row.
```html
|
||

  • <th>: Defines a header cell. Text is typically bold and centered.
| Name | Age |
|---|---|

  • <td>: Defines a standard data cell.
| John Doe | 30 |
|---|---|

Optional elements for better structure:

  • <thead>: Groups the header rows.
| Name | Age |
|---|---|

  • <tbody>: Groups the main data rows.
| Name | Age |
|---|---|
| John | 30 |

  • <tfoot>: Groups footer rows (e.g., summaries). It should be placed after <tbody> in the markup but will render at the bottom when printed or displayed with CSS.
| Total: ... |
|---|

  • <caption>: Provides a title/caption for the table. Must be the first child of `Employee Information

These optional elements (`<thead>`, `<tbody>`, `<tfoot>`, `<caption>`) improve readability and make it easier to style different parts of a table.

## 3. New Elements in HTML5

HTML5 introduced many new elements to enhance semantic markup, multimedia support, and form controls.

### 1. Semantic Elements

- `<article>`: Represents a self-contained piece of content.
```html
<article>
  <h1>Article Title</h1>
  <p>Article content...</p>
</article>

  • <aside>: Represents content indirectly related to the main content, like a sidebar.
<aside>
  <h2>Related Links</h2>
  - [Link 1](#)
- [Link 2](#)
</aside>

  • <footer>: Defines a page or section footer.
<footer>
  <p>Copyright &copy; 2023 Example Corp.</p>
</footer>

  • <header>: Defines introductory content or a set of navigational links.
<header>
  <h1>My Website</h1>
  <nav>
    - [Home](#)
- [About](#)
  </nav>
</header>

  • <nav>: Defines a section of navigation links.
<nav>
  - [Home](#)
- [About](#)
</nav>

  • <section>: Defines a thematic grouping of content.
<section>
  <h2>Section One</h2>
  <p>Content for section one...</p>
</section>

2. Form Controls

  • <datalist>: Provides a list of predefined options for an <input> element. It enables autocomplete functionality.
<input list="browsers" name="browser">
<datalist id="browsers">
  <option value="Internet Explorer">
  <option value="Firefox">
  <option value="Chrome">
  <option value="Opera">
  <option value="Safari">
</datalist>

  • <output>: Represents the result of a calculation or user action.
<form oninput="x.value=parseInt(a.value)+parseInt(b.value)">
  <input type="number" id="a" value="50"> +
  <input type="number" id="b" value="50"> =
  <output name="x" for="a b"></output>
</form>

3. Multimedia Elements

  • <audio>: Embeds audio content.
<audio controls>
  <source src="audiofile.mp3" type="audio/mpeg">
  Your browser does not support the audio element.
</audio>

  • <video>: Embeds video content.
<video width="320" height="240" controls>
  <source src="movie.mp4" type="video/mp4">
  Your browser does not support the video element.
</video>

4. Graphics Element

  • <canvas>: Used for drawing graphics via JavaScript (e.g., charts, game graphics).
<canvas id="myCanvas" width="200" height="100" style="border:1px solid #000000;">
  Your browser does not support the HTML5 canvas tag.
</canvas>
<script>
  var canvas = document.getElementById("myCanvas");
  var ctx = canvas.getContext("2d");
  ctx.fillStyle = "#FF0000";
  ctx.fillRect(0, 0, 150, 75);
</script>

  1. Semantic HTML Elements and They Usage

Semantic elements clearly describe their meaning to both the browser and the developer. They improve accessibility, SEO, and code maintainability.

Here are key semantic elements:

1. <header>

  • Purpose: Represents introductory content or navigational aids for a page or a section.
  • Example:
<header>
  <h1>My Website Title</h1>
  <nav>
    - [Home](/)
- [About](/about)
- [Contact](/contact)
  </nav>
</header>

2. <footer>

  • Purpose: Represents a footer for a page or section, typically containing metadata, copyright, or contact info.
  • Example:
<footer>
  <p>&copy; 2023 My Website. All rights reserved.</p>
</footer>

3. <article>

  • Purpose: Represents a self-contained, independent piece of content (e.g., blog post, news article).
  • Example:
<article>
  <h2>Blog Post Title</h2>
  <p>Blog post content...</p>
</article>

4. <section>

  • Purpose: Represents a thematic grouping of content, usually with a heading.
  • Example:
<section>
  <h2>Chapter 1</h2>
  <p>Content of chapter 1...</p>
</section>

5. <aside>

  • Purpose: Represents content indirectly related to the main content, like sidebars, advertisements, or related links.
  • Example:
<aside>
  <h2>Related Articles</h2>
  - [Related 1](/related1)
- [Related 2](/related2)
</aside>

6. <nav>

  • Purpose: Defines a section with navigation links.
  • Example: See <header> example above.

7. <main>

  • Purpose: Represents the dominant content of the document. A document should have only one <main> element.
  • Example:
<main>
  <article>
    <h1>Main Article Title</h1>
    <p>Main article content...</p>
  </article>
</main>

8. <figure> and <figcaption>

  • Purpose: <figure> encapsulates media (images, diagrams, code snippets) along with an optional caption provided by <figcaption>.
  • Example:
<figure>
  ![Sample Image](image.jpg)
  <figcaption>Caption for the sample image</figcaption>
</figure>

Using these semantic elements leads to more meaningful, accessible, and well-structured web pages.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.