Home >Web Front-end >CSS Tutorial >Introduction to HTML Elements
In this lesson, we are going to explore the different HTML tags, their purposes, and how to use them effectively in your web applications. We will discuss some of the most commonly used HTML tags and their corresponding attributes.
The paragraph is probably the most commonly used HTML element, which is defined by
. It is a block-level element, meaning each paragraph will start on a new line.<p>This is the first paragraph.</p> <p>This is the second paragraph, which starts on a new line.</p>
Without the
element, your browser will automatically ignore the extra white spaces and render the text in a single line.
<!-- prettier-ignore --> This is the first paragraph. This is the second paragraph, which starts on a new line.
Visit Code Demo ↗
You'll need to use the
element if you want a line break inside a single paragraph element. This is one of those HTML elements that does not require a closing tag.
<p> This is the first paragraph.<br> This is the second paragraph, which starts on a new line. </p>
Visit Code Demo ↗
When writing an article, it is good to add headings between paragraphs to make the article more organized. An HTML document works the same way. HTML offers six different levels of headings from
<h1>Heading 1</h1> <h2>Heading 2</h2> <h3>Heading 3</h3> <h4>Heading 4</h4> <h5>Heading 5</h5> <h6>Heading 6</h6>
Visit Code Demo ↗
In most cases,
Sometimes, you may want to emphasize specific words and paragraphs by giving them different formats, such as making them appear bold, italic, or underlined. HTML provides formatting elements that can help achieve this effect.
<b></b> <strong></strong> <i></i> <em></em> <mark></mark> <small></small> <del></del> <ins></ins> <sub></sub> <sup></sup>
Visit Code Demo ↗
<p> Lorem ipsum <b>dolor sit</b> amet consectetur <strong>adipisicing elit</strong>. </p>
Even though they have the same appearance, as shown in the CodePen demo, they serve different purposes for browsers and search engines.
only makes the text bold without adding any particular meaning, while indicates the enclosed texts have substantial importance.
<p>This is the first paragraph.</p> <p>This is the second paragraph, which starts on a new line.</p>
<!-- prettier-ignore --> This is the first paragraph. This is the second paragraph, which starts on a new line.
<p> This is the first paragraph.<br> This is the second paragraph, which starts on a new line. </p>
<h1>Heading 1</h1> <h2>Heading 2</h2> <h3>Heading 3</h3> <h4>Heading 4</h4> <h5>Heading 5</h5> <h6>Heading 6</h6>
<b></b> <strong></strong> <i></i> <em></em> <mark></mark> <small></small> <del></del> <ins></ins> <sub></sub> <sup></sup>
Sometimes, the default representations of these formatting elements are inadequate to express their intended meanings.
For example, the element indicates deleted texts with a strikethrough, which is easy to understand. However, the element uses underline to represent insertions, which can be very confusing.
To improve the default appearance of these elements, you can use a style attribute like this:
<p> Lorem ipsum <b>dolor sit</b> amet consectetur <strong>adipisicing elit</strong>. </p>
By default, the Introduction to HTML Elements will be underlined and displayed in blue, and when you click on it, you will be taken to the Introduction to HTML Elements specified by the href attribute.
To demonstrate, create a Introduction to HTML Elements.html file in your work directory.
<p>Lorem ipsum <i>dolor sit</i> amet consectetur <em>adipisicing elit</em>.</p>
<p>Lorem ipsum <mark>dolor sit</mark> amet consectetur adipisicing elit.</p>
And then, add a Introduction to HTML Elements in your index.html file that points to the Introduction to HTML Elements.
<p>Lorem ipsum <small>dolor sit</small> amet consectetur adipisicing elit.</p>
You will be taken to the Introduction to HTML Elements.html document when you click on the Introduction to HTML Elements.
You can also add a Go Back Introduction to HTML Elements in the Introduction to HTML Elements.html to take you back to index.html.
<p> Lorem ipsum <del>dolor sit</del> amet <ins>consectetur adipisicing</ins> elit. </p>
These interconnected Introduction to HTML Elementss form the internet we see today.
By default, the Introduction to HTML Elementsed Introduction to HTML Elements will be opened in the same window. You can change that behavior by setting a target attribute. For example, target="_blank" opens the Introduction to HTML Elements in a new tab.
<p> Lorem ipsum <sub>dolor sit</sub> amet <sup>consectetur adipisicing</sup> elit. </p>
Visit Code Demo ↗
Another thing you may have noticed is that the Introduction to HTML Elements is initially displayed in blue. The moment you click on it, it turns red. Afterward, the Introduction to HTML Elements becomes purple, indicating that the Introduction to HTML Elements has been visited before.
This behavior has to do with a concept called the pseudo-class, which allows you to define different styles for an element under different conditions. We will revisit this topic when we talk more about CSS.
Visit Code Demo ↗
There are three different types of lists in HTML: ordered, unordered, and description lists.
Ordered lists are defined with the
<p>This is the first paragraph.</p> <p>This is the second paragraph, which starts on a new line.</p>
Unordered lists are defined with the
<!-- prettier-ignore --> This is the first paragraph. This is the second paragraph, which starts on a new line.
Description lists are a bit more complex, as they consist of a list of items and a description for each item. The description list is defined with the
<p> This is the first paragraph.<br> This is the second paragraph, which starts on a new line. </p>
So far, we've only been discussing elements used to display content, such as texts, lists, and images. In fact, there is another category of elements in HTML in charge of organizing these elements.
They are not designed to display any specific type of content, but instead, they act as a container for other elements. When combined with CSS, they can create different layouts for the webpage. Some of the commonly used layout elements are shown in the list below.
<h1>Heading 1</h1> <h2>Heading 2</h2> <h3>Heading 3</h3> <h4>Heading 4</h4> <h5>Heading 5</h5> <h6>Heading 6</h6>
Visit Code Demo ↗
This is the most commonly used layout element, because for real-life webpages, most sections and blocks do not match any of the semantic elements mentioned above. As a result, many developers like to use
<p>This is the first paragraph.</p> <p>This is the second paragraph, which starts on a new line.</p>
Notice that the
element always starts on a new line and takes up as much horizontal space as possible. On the other hand, the element does not start on a new line and only takes up as much space as necessary.
This is, in fact, the difference between the block elements and inline elements.
Most of the elements we mentioned so far are block elements, such as
,
There are many other elements, both block and inline elements available in HTML. It is impossible to discuss all of them in one lesson, but here is a reference of all HTML elements from W3Schools if you are interested.
The above is the detailed content of Introduction to HTML Elements. For more information, please follow other related articles on the PHP Chinese website!