What is HTML?

HTML (Hypertext Markup Language) is a programming language used to build and structure components in a Website. HTML is temporarily understood simply as hypertext markup language. People often use HTML in the process of dividing paragraphs, Heading, Blockquote, links, ...

Why Learn HTML?

HTML is the foundation of all web pages. Without HTML, you wouldn’t be able to organize text or add images or videos to your web pages. HTML is the beginning of everything you need to know to create engaging web pages!

HTML Structure

HTML Structure

  • HTML is organized into a family tree structure. HTML elements can have parents, grandparents, siblings, children, grandchildren, etc.
  • The document type declaration <!DOCTYPE html> is required as the first line of an HTML document. The doctype declaration is an instruction to the browser about what type of document to expect and which version of HTML is being used, in this case it’s HTML5.
  • The <html> element, the root of an HTML document, should be added after the !DOCTYPE declaration. All content/structure for an HTML document should be contained between the opening and closing <html> tags.
  • The <head> element contains general information about an HTML page that isn’t displayed on the page itself. This information is called metadata and includes things like the title of the HTML document and links to stylesheets.
  • The <title> element contains a text that defines the title of an HTML document. The title is displayed in the browser’s title bar or tab in which the HTML page is displayed. The <title> element can only be contained inside a document’s <head> element.
  • The <body> element represents the content of an HTML document. Content inside <body> tags are rendered on the web browsers. Note: There can be only one <body> element in a document.

Structure of a tag in HTML that you should know

HTML Element

An HTML element is a piece of content in an HTML document and uses the following syntax: opening tag + content + closing tag. In the code provided:

  • <p> is the opening tag.
  • Hello World! is the content. The content of an HTML element is the information between the opening and closing tags of an element.
  • </p> is the closing tag. An HTML closing tag is used to denote the end of an HTML element. The syntax for a closing tag is a left angle bracket < followed by a forward slash / then the element name and a right angle bracket to close >

HTML tag attributes

The tags in the generated HTML all have associated attributes such as class , id is the most common, in addition, each tag will have its own attributes, for example a tag will have hreftargetinput then typerequireplaceholder... Then You need to know these things to use the right way to code well like this

HTML tag attributes

All the most commonly used HTML tags

<h1>-<h6> tags

Heading Elements

  • HTML can use six different levels of heading elements. The heading elements are ordered from the highest level <h1> to the lowest level <h6>.
  • The h1 tag is the tag that is often used for the largest title of the website and note that in a web page, there is only a maximum of one h1 tag , because it affects SEO, so if you use more an h1 tag is not good.

<div> tag

Div Element

  • The <div> element is used as a container that divides an HTML document into sections and is short for “division”. <div> elements can contain flow content such as headings, paragraphs, links, images, etc.

<p> tag

Paragraph Element

  • The <p> paragraph element contains and displays a block of text.

<span> tag

Span Element

  • The <span> element is an inline container for text and can be used to group text for styling purposes. However, as <span> is a generic container to separate pieces of text from a larger body of text, its use should be avoided if a more semantic element is available.

<strong> tag

Strong Element

  • The <strong> element highlights important, serious, or urgent text and browsers will normally render this highlighted text in bold by default.

<a> tag

Anchor Element

  • The <a> anchor element is used to create hyperlinks in an HTML document. The hyperlinks can point to other webpages, files on the same server, a location on the same page, or any other URL via the hyperlink reference attribute, href. The href determines the location the anchor element points to.

<em> tag

Emphasis Element

  • The <em> emphasis element emphasizes text and browsers will usually italicize the emphasized text by default.

List tags

List tag

The list tag has 2 main tags with the commonly used structure ul li and ol li. Where ul means unorderedlist means unordered list, i.e. when used it will display like this with default round or square dots based on CSS will talk later.

  • a
  • b

And ol is orderedlist which means that the list is numbered like the table of contents 1 2

  1. a
  2. b

<video> tag

Video Element

  • The <video> element embeds a media player for video playback. The src attribute will contain the URL to the video. Adding the controls attribute will display video controls in the media player.
  • Note: The content inside the opening and closing tag is shown as a fallback in browsers that don’t support the element.

<iframe> tag

iframe tag

  • This tag is used to embed another website or video into our website like the video below I use this tag iframe.

<audio> tag

audio tag

True to its name, the tag is used for you to insert music into our website, which src is to pass in the file path, which also controls allows displaying tools such as play button, pause button ...

<br> tag

Line Break Element

  • The <br> line break element will create a line break in text and is especially useful where a division of text is required, like in a postal address. The line break element requires only an opening tag and must not have a closing tag.

<img> tag

Image Element

  • HTML image <img> elements embed images in documents. The src attribute contains the image URL and is mandatory. <img> is an empty element meaning it should not have a closing tag.


Structure of <table>

Table Element

  • In HTML, the <table> element has content that is used to represent a two-dimensional table made of rows and columns.
  • The table head element, <thead>, defines the headings of table columns encapsulated in table rows.
  • The table row element, <tr>, is used to add rows to a table before adding table data and table headings.
  • The table heading element, <th>, is used to add titles to rows and columns of a table and must be enclosed in a table row element, <tr>.
  • The table body element, <tbody>, is a semantic element that will contain all table data other than table heading and table footer content. If used, <tbody> will contain all table row <tr> elements, and indicates that <tr> elements make up the body of the table. <table> cannot have both <tbody> and <tr> as direct children.
  • The table footer element, <tfoot>, uses table rows to give footer content or to summarize content at the end of a table.

colspan Attribute

colspan Attribute

  • The colspan attribute on a table header <th> or table data <td> element indicates how many columns that particular cell should span within the table. The colspan value is set to 1 by default and will take any positive integer between 1 and 1000.

rowspan Attribute

rowspan Attribute

  • Similar to colspan, the rowspan attribute on a table header or table data element indicates how many rows that particular cell should span within the table. The rowspan value is set to 1 by default and will take any positive integer up to 65534.


Structure of <form>

As <form> tag, this tag is often used when you want to send data to the server such as login, registration, update information through submitting a form. In this form tag, there are many attributes that you need to know as follows.

Form Element

  • Attribute action passed to the path or file that handles the form's information when the user presses the submit button
  • The attribute method is related to HTTP methods when submitting the form, if you learn the basics here, you don't need to understand these things, later you learn Javascript and then work with API Server, you will know these better
  • Attributes name help distinguish between forms if you use multiple forms in a web page
  • The attribute autocomplete has a default value that on means it will display suggestions when you log in or register, you put the mouse in the typing box, it suggests an email, for example, it's called autocomplete, if you want to turn it off it goes, just set it autocomplete="off" up
  • Attributes enctype define the types of data that will be sent to the server, such as text, or html or images, etc.

Tags of <form>

<input> Element

The HTML <input> element is used to render a variety of input fields on a webpage including text fields, checkboxes, buttons, etc. <input> element have a type attribute that determines how it gets rendered to a page.

Input Element

  • HTML <input> elements can support text input by setting the attribute type="text". This renders a single row input field that users can type text inside.
  • The HTML <input> element can have the attribute type="password" that renders a single row input field which allows the user to type censored text inside the field. It is used to type in sensitive information.
  • HTML <input> elements can be given a type="radio" attribute that renders a single radio button. Multiple radio buttons of a related topic are given the same name attribute value. Only a single option can be chosen from a group of radio buttons.
  • The type="checkbox" attribute will render a single checkbox item. To create a group of checkboxes related to the same topic, they should all use the same name attribute. Since it’s a checkbox, multiple checkboxes can be selected for the same topic.
  • HTML input elements can be of type number. These input fields allow the user to enter only numbers and a few special characters inside the field. The example code block shows an input with a type of number and a name of balance
  • A slider can be created by using the type="range" attribute on an HTML input element. The range slider will act as a selector between a minimum and a maximum value. These values are set using the min and max attributes respectively. The slider can be adjusted to move in different steps or increments using the step attribute. The range slider is meant to act more as a visual widget to adjust between 2 values, where the relative position is important, but the precise value is not as important. An example of this can be adjusting the volume level of an application.

<label> tag

As an inline tag, this tag is often used with input and textarea so that when the user clicks on it, it will automatically point to the input or textarea to focus on them through the for attribute in the label.

label tag

  • This property for will point to id the input, so the input needs to have the id corresponding to the value in the label's for.
  • . By default, clicking on the <label> will focus the field of the related <input>.

<select> tag

Select Element

  • As a block tag, this card will display as a dropdown allowing you to choose a drop-down list in select this card that will have the corresponding tags option for value the option you choose. In the select tag, there are also fields name like input tags because to distinguish and use in the form.
  • The value of the selected <select>’s name and the <option>’ s value attribute are sent as a key-value pair when the form is submitted.

<textarea> tag

textarea element

  • As an inline tag, this tag is the same as the input tag in that it has the same attributes as input, the other point here is textarea that it allows the user to enter a lot of content and can enter down the line, but input cannot.

<fieldset> tag

fieldset tag

  • Is a tag when you want to group fields like input, button, textarea together and then disable a group instead of disabling each one.

<button> tag

button tag

  • As an inline tag, this tag is used in the form when the user clicks to submit the entered data or delete all the data. This button tag has an attribute type with 3 values submit to submit data and reset to clear all data in the form when entering (quite dangerous), and finally, it button will have no effect when clicked.

Difference between input type submit and button type submit

Difference between input type submit and button type submit

  • Button tags can use pseudo like :before good, :after but input type submit can't. So often when working with forms, most people will use the button tag because it can be customized more.

Semantic tags

Semantic tags

  • The semantic tags you may see when you check your blog code or other website blogs... such as header tag, footer tag, nav tag, aside tag, article tag, main tag, section tag, you can understand like These tags are the way I use them, it will make our code structure clearer and more coherent, but if you use all div tags instead of using these semantic tags, it's still fine, it's okay.