What is HTML?

HTML (Hypertext Markup Language) is not a programming language. It is a markup language that tells web browsers how to structure the web pages you visit. It can be as complicated or as simple as the web developer wants it to be. HTML consists of a series of elements, which you use to enclose, wrap, or mark up different parts of content to make it appear or act in a certain way. The enclosing tags can make content into a hyperlink to connect to another page, italicize words, and so on. For example, consider the following line of text:

<p>My cat is very grumpy<∕p>

Output:

My cat is very grumpy
Anatomy of HTML element

Let's further explore our paragraph element from the previous section:

The anatomy of our element is:

The element is the opening tag, followed by content, followed by the closing tag.

Creating your first HTML element

Edit the line below in the "Editable code" area by wrapping it with the tags<em> and <∕em>.To open the element, put the opening tag <em> at the start of the line. To close the element,put the closing tag <∕em> at the end of the line. Doing this should give the line italic text formatting! See your changes update live in the Output area. If you make a mistake, you can clear your work using the Reset button. If you get really stuck, press the Show solution button to see the answer.

Nesting elements

Elements can be placed within other elements. This is called nesting. If we wanted to state that our cat is very grumpy, we could wrap the word very in a <strong>element, which means that the word is to have strong(er) text formatting:

<p>My cat is <strong> very <∕strong> grumpy <∕p>

There is a right and wrong way to do nesting. In the example above, we opened the p element first, then opened the strong element. For proper nesting, we should close the strong element first, before closing the p . The following is an example of the wrong way to do nesting:

The following is an example of the wrong way to do nesting:

<p>My cat is <strong> very grumpy.<∕p><∕strong>

The tags have to open and close in a way that they are inside or outside one another.With the kind of overlap in the example above, the browser has to guess at your intent. This kind of guessing can result in unexpected results.

Block versus Inline elements

There are two important categories of elements to know in HTML: block-level elements and inline elements.

Consider the following example:

<em> is an inline element. As you see below, the first three elements sit on the same line, with no space in between. On the other hand, <p> is a block-level element. Each p element appears on a new line, with space above and below. (The spacing is due to default CSS styling that the browser applies to paragraphs.)

Empty elements

Not all elements follow the pattern of an opening tag, content, and a closing tag. Some elements consist of a single tag, which is typically used to insert/embed something in the document. For example, the <img> element embeds an image file onto a page:

<img src="https://raw.githubusercontent.com/mdn/beginner-html-site/gh-pages/images/firefox-icon.png">

This would output the following:

Attributes

Elements can also have attributes. Attributes look like this:

Attributes contain extra information about the element that won't appear in the content. In this example, the class attribute is an identifying name used to target the element with style information.

An attribute should have:

Adding attributes to an element

Another example of an element is <a>. This stands for anchor. An anchor can make the text it encloses into a hyperlink. Anchors can take a number of attributes, but several are as follows:

Boolean attributes

Sometimes you will see attributes written without values. This is entirely acceptable. These are called Boolean attributes. Boolean attributes can only have one value, which is generally the same as the attribute name. For example, consider the disabled attribute, which you can assign to form input elements. (You use this to disable the form input elements so the user can't make entries. The disabled elements typically have a grayed-out appearance.) For example:

<input type="text" disabled="disabled">

As shorthand, it is acceptable to write this as follows:

<! using the disabled attribute prevents the end user from entering text into the input box > <input type="text" disabled> <! text input is allowed, as it doesn't contain the disabled attribute > <input type="text">
Omitting quotes around attribute values

If you look at code for a lot of other sites, you might come across a number of strange markup styles, including attribute values without quotes. This is permitted in certain circumstances, but it can also break your markup in other circumstances. For example, if we revisit our link example from earlier, we could write a basic version with only the href attribute.

Single or Double quotes?

All the documentation in this page is taken from MDN

Anatomy of HTML document

All the documentation in this page is taken from MDN

Whitespace in HTML

All the documentation in this page is taken from MDN

References

All the documentation in this page is taken from MDN