Working with Text, Links, Images and Tables in HTML
1. Displaying Plain, Bold, Italic, Small, Subscripted, and Superscripted Text
HTML provides a wide range of tags for text formatting. Each of these tags is used to style text in different ways.
Plain Text:
Plain text is the default text that appears in the browser without any specific formatting applied.
Example:
Bold Text:
To display bold text, you can use the <b>
or <strong>
tag. Both visually make text bold, but <strong>
also conveys emphasis for semantic meaning, suggesting importance.
Example:
Or using <strong>
(semantically emphasizes importance):
Italic Text:
To display italic text, use the <i>
or <em>
tag. Similar to the bold tags, <i>
just provides a visual italic style, while <em>
indicates emphasis.
Example:
Or using <em>
(emphasizes meaning):
Small Text:
The <small>
tag is used to decrease the font size.
Example:
Subscripted Text:
Subscript text can be created using the <sub>
tag, which positions the text slightly below the normal text line.
Example:
Superscripted Text:
Superscript text is created using the <sup>
tag, which positions the text slightly above the normal text line.
Example:
Comparison of Text Formatting Tags:
Tag | Purpose | Usage Example |
---|---|---|
<b> | Bold text (visual only) | <b>This is bold</b> |
<strong> | Bold text (semantic, important) | <strong>Important text</strong> |
<i> | Italic text (visual only) | <i>This is italic</i> |
<em> | Italic text (semantic, emphasis) | <em>Emphasized text</em> |
<small> | Smaller text | <small>Smaller text</small> |
<sub> | Subscript text | H<sub>2</sub>O |
<sup> | Superscript text | E = mc<sup>2</sup> |
2. Displaying Program Code, Program Output, and Keyboard Text
Program Code:
HTML provides the <code>
, <pre>
, and <samp>
tags to display code and output.
<code>
: Used for inline code.
<pre>
: Used for preformatted text, preserving line breaks and spaces.
<samp>
: Displays program output.
Keyboard Text:
To represent keyboard input or text typed by the user, use the <kbd>
tag.
Example:
3. Emphasizing Text, Defining New Terms
Emphasizing Text:
- The
<em>
tag emphasizes text by rendering it in italics by default (though this can vary with CSS).
Defining New Terms:
- The
<dfn>
tag is used to define a term, which is usually highlighted and linked to its definition.
4. Short and Long Quotations
Short Quotations:
For short quotations, you can use the <q>
tag. The text inside the <q>
tag is enclosed in quotation marks automatically by the browser.
Example:
Long Quotations:
For longer quotes, the <blockquote>
tag is used. It indents the text and is typically used for multi-line quotations.
Example:
5. Creating Links with the Anchor (<a>
) Tag
The <a>
tag is used to create hyperlinks. It requires the href
attribute to specify the destination URL.
You can also link to an email address by using the mailto:
scheme in the href
attribute.
Example:
6. Formatting Text with HTML Physical Style Elements
HTML offers physical style elements, which directly modify the appearance of text. These are considered presentational, and it is recommended to use CSS for styling in modern web development.
<b>
: Bold<i>
: Italic<u>
: Underlined text
Example:
7. Formatting Text with HTML Logical Style Elements
Logical style elements define the meaning or importance of text, rather than its visual style.
<strong>
: Strong emphasis (typically bold)<em>
: Emphasized text (typically italic)
Example:
8. Arranging Text: Line Breaks and Paragraphs
<br>
: Adds a line break.
<p>
: Creates a paragraph.
<hr>
: Creates a horizontal line to separate content.
9. Exploring Hyperlinks and Linking to a Mail System
Links can be used not only for web pages but also for linking to emails, documents, and other resources.
Mail Links:
To link to an email system, use the mailto:
scheme in the href
attribute.
Example:
This will open the user's default email client with the specified email address.
Exploring Link Relations (Linking External Resources)
HTML allows linking to external resources using the <link>
tag. This tag is typically used in the <head>
section of a webpage to link CSS files, icons, or other metadata.
10. Working with Images in a Web Page
Images are embedded in a webpage using the <img>
tag. The src
attribute specifies the path to the image, and the alt
attribute provides alternative text in case the image is not loaded.
Common Image Attributes:
Attribute | Purpose |
---|---|
src | Specifies the image source URL. |
alt | Provides alternative text for accessibility. |
width | Specifies the width of the image in pixels. |
height | Specifies the height of the image in pixels. |