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 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.
<html>element, the root of an HTML document, should be added after the
!DOCTYPEdeclaration. All content/structure for an HTML document should be contained between the opening and closing
<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.
<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
<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
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
target, input then
placeholder... Then You need to know these things to use the right way to code well like this
All the most commonly used HTML tags
- HTML can use six different levels of heading elements. The heading elements are ordered from the highest level
<h1>to the lowest level
- 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>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>paragraph element contains and displays a block of text.
<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>element highlights important, serious, or urgent text and browsers will normally render this highlighted text in bold by default.
<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,
hrefdetermines the location the anchor element points to.
<em>emphasis element emphasizes text and browsers will usually italicize the emphasized text by default.
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.
And ol is orderedlist which means that the list is numbered like the table of contents 1 2
<video>element embeds a media player for video playback. The
srcattribute will contain the URL to the video. Adding the
controlsattribute 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.
- This tag is used to embed another website or video into our website like the video below I use this 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>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.
- HTML image
<img>elements embed images in documents. The
srcattribute contains the image URL and is mandatory.
<img>is an empty element meaning it should not have a closing tag.
- 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,
- 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
<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.
colspanattribute on a table header
<th>or table data
<td>element indicates how many columns that particular cell should span within the table. The
colspanvalue is set to 1 by default and will take any positive integer between 1 and 1000.
- Similar to
rowspanattribute on a table header or table data element indicates how many rows that particular cell should span within the table. The
rowspanvalue is set to 1 by default and will take any positive integer up to 65534.
<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.
actionpassed to the path or file that handles the form's information when the user presses the submit button
- The attribute
namehelp distinguish between forms if you use multiple forms in a web page
- The attribute
autocompletehas a default value that
onmeans 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
enctypedefine the types of data that will be sent to the server, such as text, or html or images, etc.
<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>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.
<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
nameattribute value. Only a single option can be chosen from a group of radio buttons.
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
nameattribute. 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
numberand a name of
- A slider can be created by using the
type="range"attribute on an HTML
inputelement. The range slider will act as a selector between a minimum and a maximum value. These values are set using the
maxattributes respectively. The slider can be adjusted to move in different steps or increments using the
stepattribute. 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.
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.
- This property
forwill point to
idthe 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
- As a block tag, this card will display as a dropdown allowing you to choose a drop-down list in
selectthis card that will have the corresponding tags
valuethe option you choose. In the select tag, there are also fields
namelike input tags because to distinguish and use in the form.
- The value of the selected
valueattribute are sent as a key-value pair when the form is submitted.
- 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
textareathat it allows the user to enter a lot of content and can enter down the line, but input cannot.
- Is a tag when you want to group fields like input, button, textarea together and then disable a group instead of disabling each one.
- 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
typewith 3 values
submitto submit data and
resetto clear all data in the form when entering (quite dangerous), and finally, it
buttonwill have no effect when clicked.
Difference between input type submit and button type submit
- Button tags can use pseudo like
:afterbut input type submit can't. So often when working with forms, most people will use the button tag because it can be customized more.
- 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.