HTML is a web language. It is used to design web pages or to arrange a website's page layouts. HTML stands for HYPERTEXT MARKUP LANGUAGE, and as the name implies, it is a markup language rather than a programming language. So, no such error can occur during the execution of HTML code. HTML code was rendered by the browser. It was not compiled or interpreted.
HTML uses specified tags and attributes to instruct browsers on how to display text, which includes what format, style, font size, and pictures to display. HTML is a case-insensitive language. Case insensitive means that there is no distinction between upper and lower case (capital and small letters), which are both viewed as the same; for example, 'P' and 'p' are both the same here. In HTML, tags are classified into two types:
An HTML document is divided into two parts:
An HTML document's basic structure consists of5 elements:
The tag in HTML is used to inform the browser about the HTML version used in the web page. It is referred as the document type declaration (DTD). It is not really a tag/element but rather an instruction to the browser regarding the document type. It is a null element that does not have a closing tag and must not contain any content.
Actually, there are various types of HTML e.g. HTML 4.01 Strict, HTML 4.01 Transitional, HTML 4.01 Frameset, XHTML 1.0 Strict, XHTML 1.0 Transitional, XHTML 1.0 Frameset, XHTML 1.1, etc.
Since HTML 4.01 was based on SGML, the declaration relates to the Document Type Declaration (DTD) in HTML 4.01. However, HTML 5 is not based on SGML (Standard Generalized Markup Language).
<!DOCTYPE html>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
Example: In the given example, we are going to use the <!DOCTYPE html> tag to declare the version of HTML the page is written in. It is an empty tag and does not contain any information.
<!DOCTYPE html>
<html>
<head>
<title>!DOCTYPE tag</title>
</head>
<body>
<h1> !DOCTYPE tag </h1>
</body>
</html>
Output
The <html> tag in HTML is used to specify the root of HTML and XHTML pages. The <html> tag informs the browser that this is an HTML document. It is the second outer container for everything in an HTML document, followed by the tag. The <html> tag requires a beginning and ending tag.
<!DOCTYPE html>
<html>
...
</html>
Example: In the given example, we are going to use the <html> tag to show how it contains the contents of an HTML document.
<!DOCTYPE html>
<title>HTML tag</title>
<!-- HTML tag starts here -->
<html>
<body>
<h1>html Tag</h1>
</body>
</html>
<!-- HTML tag ends here -->
Output:
The following is a list of metadata tags:
<!DOCTYPE html>
<html>
<head>
...
</head>
</html>
Example: In this example, we are going to use the <head> tag containing the <style> (to add CSS to our content) and <title> (to add title to our webpage) tag.
<!DOCTYPE html>
<html>
<head>
<title>head tag</title>
<style>
h1{
color: blue;
}
</style>
</head>
<body>
<h1> head tag </h1>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<head>
<title> ... </title>
</head>
</html>
Example: In this example, we are going to use the <title> tag to add a title to our webpage.
<!DOCTYPE html>
<html>
<head>
<title>title tag</title>
</head>
<body>
<h1> title tag </h1>
</body>
</html>
Output:
The <body> tag in HTML specifies the main content of an HTML document that appears on the browser. It can contain headings, text, paragraphs, photos, tables, links, videos, etc.
The <body> tag must come after the <head> tag, or it must be inserted between the </head> and </html> tags. This tag is essential for all HTML documents and should only be used once throughout the document.
<!DOCTYPE html>
<html>
<head>
<title>Body Tag</title>
</head>
<body>
<h1>...</h1>
<p>...</p>
</body>
</html>
Example: In the given example, we are going to use the <body> tag to add a heading, paragraph, and image to our webpage.
<!DOCTYPE html>
<html>
<head>
<title>Body Tag</title>
</head>
<body>
<h1>Example of body tag</h1>
<p>This paragraph and the image displayed below is written between the body tag.</p>
<img src="https://cdn.pixabay.com/photo/2022/07/09/13/24/mountains-7310910__340.jpg" alt="mountains">
</body>
</html>
Output of the above code:
20 videos|15 docs|2 tests
|
1. What is the basic structure of an HTML document? |
2. What are HTML tags? |
3. How is text and other elements added to an HTML document? |
4. Can you provide an example of the syntax and document structure of an HTML document? |
5. How can I structure my HTML document to improve search engine optimization (SEO)? |
|
Explore Courses for Software Development exam
|