As a web developer, you’re likely familiar with HTML, or Hypertext Markup Language. HTML is the backbone of the web, providing structure and meaning to the online content. But beyond its basic functionality, HTML also allows developers to format content in a variety of ways. This guide will explore the ins and outs of HTML formatting, from text formatting to creating tables and forms.
Text Formatting in HTML
Text formatting is one of the most fundamental aspects of HTML, allowing developers to create headings, bold and italicized text, and more. Let’s take a closer look at some of the most common text formatting tags in HTML:
Headings
HTML headings are used to provide structure and hierarchy to content on a web page. There are six levels of headings in HTML, from <h1>
(the largest and most important) to <h6>
(the smallest and least important). Here’s an example of how to use an <h1>
tag:
<h1>Welcome to My Website!</h1>
Bold and Italicized Text
To create bold text, you can use the <strong>
tag, like so:
<p>This text is <strong>bold</strong>.</p>
For italicized text, you can use the <em>
tag:
<p>This text is <em>italicized</em>.</p>
Underlining Text
While underlining text is generally discouraged in modern web design, it can still be achieved using the <u>
tag:
<p>This text is <u>underlined</u>.</p>
Strikethrough Text
To create strikethrough text (where a line is drawn through the text), use the <s>
tag:
<p>This text is <s>strikethrough</s>.</p>
Superscript and Subscript Text
To create superscript text (text that is raised above the baseline), use the <sup>
tag:
<p>This text is <sup>superscript</sup>.</p>
For subscript text (text that is lowered below the baseline), use the <sub>
tag:
<p>This text is <sub>subscript</sub>.</p>
Creating Lists in HTML
Lists are another common element in HTML, used to organize content in an ordered or unordered fashion. Let’s take a look at the two types of lists in HTML:
Unordered Lists
To create an unordered list (also known as a bulleted list), use the <ul>
tag, with each list item enclosed in <li>
tags:
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
Ordered Lists
To create an ordered list (also known as a numbered list), use the <ol>
tag, with each list item enclosed in <li>
tags:
<ol>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ol>
Creating Tables in HTML
Tables are a powerful way to display tabular data on a web page, and HTML provides several tags for creating tables. Let’s take a look at the basic structure of an HTML table:
<table>
<thead>
<tr>
<th>Header 1</th>
<th>Header 2</th>
<th>Header 3</th
</tr>
</thead>
<tbody>
<tr>
<td>Row 1, Cell 1</td>
<td>Row 1, Cell 2</td>
<td>Row 1, Cell 3</td>
</tr>
<tr>
<td>Row 2, Cell 1</td>
<td>Row 2, Cell 2</td>
<td>Row 2, Cell 3</td>
</tr>
<tr>
<td>Row 3, Cell 1</td>
<td>Row 3, Cell 2</td>
<td>Row 3, Cell 3</td>
</tr>
</tbody>
</table>
In this example, the <table>
tag is used to define the table itself, while the <thead>
and <tbody>
tags are used to define the table header and body, respectively. The <tr>
tag defines a table row, and the <th>
and <td>
tags define table headers and data cells, respectively.
Creating Forms in HTML
Forms are a crucial element in HTML, allowing users to submit information to a web server. HTML provides a variety of form elements, from text input fields to radio buttons and checkboxes. Let’s take a look at an example form:
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br>
<label for="message">Message:</label>
<textarea id="message" name="message"></textarea><br>
<input type="submit" value="Submit">
</form>
In this example, the <form>
tag is used to define the form, while the various input fields (name, email, and message) are defined using the <input>
and <textarea>
tags. The <label>
tag is used to provide a description of each input field, and the <input type="submit">
tag is used to create a submit button.
Conclusion
HTML formatting is a crucial part of web development, allowing developers to create structured, organized, and visually appealing content for the web. In this guide, we’ve explored some of the most common formatting techniques in HTML, from text formatting to creating tables and forms. By mastering these techniques, you’ll be well on your way to creating beautiful, functional web pages that engage and delight your users.
📕 Related articles about HTML
- How to Make a 404 Page in HTML
- How to Make Your Own HTML: A Comprehensive Guide
- How to make website HTML and CSS
- How to Make Your HTML Website Public
- How to Add CSS to HTML: A Comprehensive Guide for Incredible Web Design
- HTML Block & Inline Elements: Understanding the Differences and Usage