Chapter 1.3.5 - Advanced HTML Formatting


Advanced HTML Formatting

In Chapter 1.2.4, you learned about the HTML document and its tag-based syntax. In this chapter, you will explore more advanced HTML tags that will help you format your code for ease of readability and illustration.


Tags

There are a few key tags that are incredibly useful to know, let's walk you through them.

A link or hyperlink is a connection from one web resource to another. Links allow users to move seamlessly from one page to another, on any server anywhere in the world.A link or hyperlink is a connection from one web resource to another. Links allow users to move seamlessly from one page to another, on any server anywhere in the world.

A link has two ends, called anchors. The link starts at the source anchor and points to the destination anchor, which may be any web resource, for example, an image, an audio or video clip, a PDF file, an HTML document or an element within the document itself, and so on.

We can specify a link in HTML by using the <a> tag. This could be a word, group of words, or even an image.

<a href="url">Link text</a>

In the example above, we generated this Link text.

The href attrilbute specifes the target of the link and its value can be an absolute or relative URL.

URLExampleDescription
Relativeimages/smiley.pngincludes every part of the URL format, such as protocol, host name, and path of the document.
Absolutehttps://oval-webdev.netlify.app/syllabus.htmlare page-relative paths, never include the http:// or https:// prefix.

You can add a target attribut to your <a> tags to specify to the browser how it should open a linked document.

targetDescription
_blankOpens the linked document in a new window or tab.
_parentOpens the linked document in the parent window.
_selfOpens the linked document in the same window/tab as the source. This is the default behaviour and can be omitted.
_topOpens the linked document in the full browser window.
<a href="https://www.google.com" target="_blank">Google.</a>

The above example generates this link: Google.

Create Bookmark Anchors

You can create bookmark anchors to allow users to jump to specific sections of a web page. These are useful for very long web pages.

This is a two step process:

  1. Add the id attribute on the element where you want to jump.
  2. Use the id attribute value preceded by the has sign (#) as the value of the href attribute of the <a> tag.
<a href="#sectionX">Jump to Section X</a>
<h2 id="sectionX">Section X</h2>

The above example creates this link: Jump to Section X

...which jumps to here:

Section X

Text Formatting

HTML provides you with several tags that can be used to make text on your web site appear different from normal text.

<p>This is <b>bold text</b>.</p>
<p>This is <strong>strongly important text</strong>.</p>
<p>This is <i>italic text</i>.</p>
<p>This is <em>emphasized text</em>.</p>
<p>This is <mark>highlighted text</mark>.</p>
<p>This is <code>computer code</code>.</p>
<p>This is <small>smaller text</small>.</p>
<p>This is <sub>subscript</sub> and <sup>superscript</sup> text.</p>
<p>This is <del>deleted text</del>.</p>
<p>This is <ins>inserted text</ins>.</p>

In the above example, you can see the most commonly used formatting tags. This is how they would appear:

This is bold text.

This is strongly important text.

This is italic text.

This is emphasized text.

This is highlighted text.

This is computer code.

This is smaller text.

This is subscript and superscript text.

This is deleted text.

This is inserted text.

Quotations

To format quotation blocks from other sources, you should use the blockquote tag.

<blockquote>
    <p>Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning.</p>
    <cite>— Albert Einstein</cite>
</blockquote>

The above example showcases the blockquote tag in action. The cite tag is used to describe a reference to a creative work. This is how it appears:

Learn from yesterday, live for today, hope for tomorrow. The important thing is not to stop questioning.

— Albert Einstein

For short inline quoatations, you use the HTML <q> tag.

<p>According to the World Health Organization (WHO): <q>Health is a state of complete physical, mental, and social well-being.</q></p>

According to the World Health Organization (WHO): Health is a state of complete physical, mental, and social well-being.

To display an address, use the <address> tag.

<address>
Mozilla Foundation<br>
331 E. Evelyn Avenue<br>
Mountain View, CA 94041, USA
</address>

The above example would appear as follows:

Mozilla Foundation
331 E. Evelyn Avenue
Mountain View, CA 94041, USA

Images

You can add images to your site by using the <img> tag. This tag contains attributes only.

<img src="https://api.time.com/wp-content/uploads/2019/12/ducks-walk-on-glass-roof-video.jpg" alt="duckss">

The above image displays ducks: ducks

The src attribute tells the browser where to find the image. The alt tag provides an alternative text for the image.

You can set the width of an image using the width and height attributes.

<img src="https://api.time.com/wp-content/uploads/2019/12/ducks-walk-on-glass-roof-video.jpg" alt="ducks" width="200px" height="100px">

The above code produces the following image: ducks

Below is a list of all of the currently available and useful HTML5 tags. You may try them out by navigating to this website, copy/pasting the html snippet at the bottom of this page, and running the project. You may also modify your index.html file in your project repossitory.

TagDescriptionEnd Tag?
<a>Defines a hyperlink.
<abbr>Defines an abbreviated form of a longer word or phrase.
<address>Specifies the author's contact information.
<area>Defines a specific area within an image map.
<article>Defines an article.
<aside>Defines some content loosely related to the page content.
<audio>Embeds a sound, or an audio stream in an HTML document.
<b>Displays text in a bold style.
<base>Defines the base URL for all relative URLs in a document.
<bdi>Represents text that is isolated from its surrounding for the purposes of bidirectional text formatting.
<bdo>Overrides the current text direction.
<blockquote>Represents a section that is quoted from another source.
<body>Defines the document's body.
<br>Produces a single line break.
<button>Creates a clickable button.
<canvas>Defines a region in the document, which can be used to draw graphics on the fly via scripting (usually JavaScript).
<caption>Defines the caption or title of the table.
<cite>Indicatess a citation or reference to another source.
<code>Specifies text as computer code.
<col>Defines attribute values for one or more columns in a table.
<colgroup>Specifies attributes for multiple columns in a table.
<data>Links a piece of content with a machine-readable translation.
<datalist>Represents a set of pre-defined options for an <input> element.
<dd>Specifies a description, or value for the term (<dt>) in a description list (<dl>).
<del>Represents text that has been deleted from the document.
<details>Represents a widget from which the user can obtain additional information or controls on-demand.
<dfn>Specifies a definition.
<dialog>Defines a dialog box or sub window.
<div>Specifies a division or a section in a document.
<dl>Defines a description list.
<dt>Defines a term (an item) in a description list.
<em>Defines emphasized text.
<embed>Embeds external application, typically multimedia content like audio or video into an HTML document.
<fieldset>Specifies a set of related form fields.
<figcaption>Defines a caption or legend for a figure.
<figure>Represents a figure illustrated as part of the document.
<footer>Represents the footer of a document or a section.
<form>Defines an HTML form for user input.
<head>Defines the head portion of the document that contains information about the document such as title.
<header>Represents the header of a document or a section.
<hgroup>Defines a group of headings.
<h1 to <h6>Defines HTML headings.
<hr>Produce a horizontal line.
<html>Defines the root of an HTML document.
<i>Displays text in an italic style.
<iframe>Displays a URL in an inline frame.
<img>Represents an image.
<input>Defines an input control
<ins>Defines a block of text that has been inserted into a document.
<kbd>Specifies text as keyboard input.
<keygen>Represents a control for generating a public-private key pair.
<label>Defines a label for an <input> control.
<legend>Defines a caption for a <fieldset> element.
<li>Defines a list item.
<link>Defines the relationship between the current document and an external resource.
<main>Represents the main or dominant content of the document.
<map>Defines a client-side image-map.
<mark>Represents text highlighted for reference purposes.
<menu>Represents a list of commands.
<menuitem>Defines a list (or menuitem) of commands that a user can perform.
<meta>Provides structured metadata about the document content.
<meter>Represents a scalar measurement within a known range.
<nav>Defines a section of navigation links.
<noscript>Defines alternative content to display when the browser doesn't support scripting.
<object>Defines an embedded object.
<ol>Defines an ordered list.
<optgroup>Defines a group of related options in a selection list.
<option>Defines an option in a selection list.
<output>Represents the result of a calculation.
<p>Defines a paragraph.
<param>Defines a parameter for an object or applet element.
<picture>Defines a container for multiple image sources.
<pre>Defines a block of preformatted text.
<progress>Represents the completion progress of a task.
<q>Defines a short inline quotation.
<rp>Provides fall-back parenthesis for browsers that don't support ruby annotations.
<rt>Defines the pronounciation of character presented in a ruby annotation.
<ruby>Represents a ruby annotation.
<s>Represents contents that are no longer accurate or no longer relevant.
<samp>Specifies text as sample output from a computer program.
<script>Places script in the document for a client-side processing.
<section>Defines a section of a document, such as header, footer, etc.
<select>Defines a selection list within a form.
<small>Displays text in a smaller size.
<source>Defines alternative media resources for the media elements like <audio> or <video>.
<span>Defines an inline styleless section in a document.
<strong>Indicate strongly emphasized text.
<style>Inserts style information (commonly CSS) into the head of a document.
<sub>Defines subscripted text.
<summary>Defines a summary for the <details> element.
<sup>Defines superscripted text.
<svg>Embed SVG (Scalable Vector Graphics) content in an HTML document.
<table>Defines a data table.
<tbody>Groups a set of rows defining the main body of the table data.
<td>Defines a cell in a table.
<template>Defines the fragments of HTML that should be hidden when the page is loaded, but can be cloned and inserted in the document by JavaScript.
<textarea>Defines a mutli-line text input control (text area).
<tfoot>Groups a set of rows summarizing the columns of the table.
<th>Defines a header cell in a table.
<thead>Groups a set of rows that describes the column labels of a table.
<time>Represents a time and/or date.
<title>Defines a title for the document.
<tr>Defines a row of cells in a table.
<track>Defines text tracks for the media elements like <audio> or <video>.
<u>Displays text with an underline.
<ul>Defines an unordered list.
<var>Defines a variable.
<video>Embeds video content in an HTML document.
<wbr>Represents a line break opportunity.
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>A quote</title>
    </head>

   <body>
        <h1>This is a header element.</h1>

        <blockquote>
            <p>This is a paragraph element. It is inside a blockquote element.</p>
        </blockquote>

        
    </body>
</html>