Why is HTML used in Web Pages ?
Last Updated :
02 Apr, 2024
Web pages are built using the HyperText Markup Language or HTML. It is a markup language that defines a webpage's content and structure using tags. These tags provide instructions to web browsers on how to show links, photos, videos, text, and other content. Consider HTML as a house's plan, detailing the rooms, doors, windows, and general design.
Working of HTML
The HTML document is typically structured as follows:
HTML document format
- Document Type Declaration (DOCTYPE): This statement tells the web browser what version of HTML (the language used to create web pages) the document is written in. It helps the browser interpret and display the code correctly.
<!DOCTYPE html>
- HTML Tag: HTML tag as the starting point or the main container of your webpage. It is like the root or base of a tree from which all other elements branch out. Everything else on your webpage, like text, images, and links, is nested within this HTML tag.
<html>
<!-- Content -->
</html>
- Head: The head section of a webpage is like a storage room for important details about the webpage, such as its title, design instructions, and extra features. These details are not shown right away when you open the webpage. they are more like background information that helps the webpage function correctly and look good.
<head>
<title>Example Page</title>
<!-- Other meta-information -->
</head>
- Body: The body section of a webpage is where you find all the main content like text, images, headings, and lists. It is what you actually see when you visit a webpage in your browser.
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
<!-- Other content -->
</body>
HTML Rendering Process
- Receiving the Code: When we type a website address on our browser, it sends a request to the web server where that website is stored. The server then sends back the webpage you requested, including all the text, images, and other elements it is made of. It is like asking for a book from a library, and the server sends you the book along with any pictures or extra information.
- Parsing the Code: When our browser opens on a webpage, it reads the code to understand it. It looks for specific HTML tags and their order. It knows it is an HTML document because of a special line at the start. It is like a reader recognizing a book by its cover.
- Building the Content Model: The browser sorts all its parts, when a webpage loads, like text and images, into a structured layout called a content model. This layout looks like a tree and shows how different parts of the webpage are connected. It's like organizing your toys into different boxes based on what they are.
- Applying CSS: Cascading Style Sheets (CSS) is like a designer for web pages. It tells the browser how things should look, like what color text should be, how big headings should be, and where things should be placed on the page. So, when you visit a webpage, the browser reads the CSS instructions and styles the page accordingly.
- Painting the Page: When you open a webpage, our browser organizes all the elements on the page like images, paragraphs, and headings according to how they are described in the code (HTML) and how they should appear (CSS). It is like a decorator arranging furniture in a room to make it look nice and tidy.
Viewing the HTML Code
There are two ways to see the HTML code of a webpage:
- Right-Click and View Page Source: We can right click anywhere on a webpage in most web browsers to choose an option like "View Page Source" or "Inspect." This displays the full HTML code for that page in a new window or panel.
- Developer Tools: Developer tools come built in with web browsers, and they provide a lot of information about webpages. We can usually access them by pressing (F12 or Ctrl+Shift+I). These tools let you look at and change the HTML code of the page you are on. It is like peeking behind the scenes of a magic show and being able to adjust how things work.
How to Use HTML to Create a Web Page
HTML is mainly used to structure our web page with the help of the elements and tags. It can be further used with CSS and JavaScript to enhance the attractiveness and interactivity of the web page.
Example: The below code example creates a simple web page with the help of CSS and HTML.
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>
My Simple Webpage
</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>
Welcome to My Page!
</h1>
<p>
This is some content on my webpage.
</p>
<img alt="My Image" src=
"https://media.geeksforgeeks.org/wp-content/uploads/20240324185837/GFG-logo.jpg">
</body>
</html>
CSS
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 20px;
}
h1 {
text-align: center;
color: #333;
}
p {
text-align: center;
line-height: 1.5;
}
img {
width: 200px;
display: block;
margin: 0 auto;
}
ul {
list-style: none;
padding: 0;
}
li {
margin: 10px 0;
}
Output:
OutputThe below list contains some most commonly used HTML tags on every web page:
- Headings (<h1> to <h6>): HTML headings are titles or subtitles that you want to display on a webpage.
- Paragraph (<p>): A paragraph element consists of content that appears between an opening <p> tag and a closing </p> tag. This content can be text, graphics, or other types of content, such as form fields.
- Lists (<ul> for unordered, <ol> for ordered): There are may be one or more list elements in every list. Three varieties of HTML lists exist: Lists can either be ordered(ol), unordered(ul), or description list (dl).
- List Items (<li>): When you want to list of items, you can use the <li> element. This element must be placed inside either a menu (<menu>), an unordered list (<ul>), or an ordered list (<ol>). It's like saying each item in your list belongs to a specific category, whether it's a menu, a bulleted list, or a numbered list.
- Images (<img>): The <img> tag in HTML creates a space where an image can be shown on a webpage. However, the actual image is not part of the HTML page itself; instead, it's linked from another location on the web. So, when you use the <img> tag, you're basically telling the browser to display an image from somewhere else on the internet within your webpage.
- Links (<a>): Create hyperlinks to other webpages or sections of the same page.
- Tables (<table>, <tr>, <td>): When you want to create a table, We can use the <table> tag. Inside this tag, you create rows with <tr>, and within each row, you add cells using <th> for headers or <td> for regular cells. So, <th> makes the table header, <td> makes the table cell, and <tr> marks each row.
- Forms (<form>, <input>, <button>): An HTML form is a part of a webpage where users can fill in information or make selections, like typing in a text box or choosing from a list. Each option has a label next to it to explain what it is. It's like a way for users to interact with a webpage, such as filling out a survey or entering their details.
Advantages of Using HTML in a Webpage
- Structure and Organization: HTML is like a framework for web content, ensuring websites appear consistent across different devices. It organizes information in a way that browsers can understand, making it easier for users to navigate and access content seamlessly.
- Flexibility: HTML forms is the basic structure of web pages. With the addition of CSS for styling and JavaScript for interactivity, it allows for the creation of complex and engaging websites.
- Standardization: HTML is a uniform structure ensures web pages appear consistently across different browsers, enhancing user experience. This standardization simplifies development and guarantees accessibility to all users, regardless of their preferred browser.
- Easy to Learn: HTML is a good choice for beginners to learn web programming due to its straightforward syntax and rules. It provides an accessible starting point for newcomers to understand the basics of building web pages, setting a solid foundation for further learning in web development.
Latest Version of HTML (HTML5)
HTML5, launched in 2014, is the current standard for web development. It offers significant improvements over its predecessors, enhancing the capabilities and functionality of websites and applications. This version has become widely adopted due to its modern features and improved performance.
Features of HTML5
- Semantic Tags: These tags, like <header>, <nav>, <section>, and <article>, provide extra context to the content on a webpage. This helps search engines and screen readers understand the structure of the page better, making it easier for users to navigate and comprehend the information presented.
- Multimedia Support: We can include audio and video elements directly in web pages without relying on additional plugins. This eliminates the need for third party software to play media, making the web experience more seamless and accessible across different devices and platforms.
- Offline Capabilities: Web applications can keep working a bit even if you are not online, this tools like storing data locally and caching parts of the app. This means you might still be able to use some features or access stored information without an internet connection.
- Canvas and SVG: These components offer advanced sketching tools for creating interactive visuals and animations. They enable users to draw and animate images with precision and ease, allowing for dynamic and engaging content creation.
- Web Storage: In HTML5, websites can remember your login information even after you close the browser. This is because HTML5 allows data to be saved directly on your device, using tools like local storage and session storage. So, you don't have to log in every time you visit the website.
Advantages of HTML5 over HTML
- In the HTML5, websites can do more things and have cleaner code. This means they can have extra features and everything is arranged in a neater way behind the scenes.
- HTML5 helps websites show videos, music, and other cool stuff better, so you have more fun when you are online.
- HTML5 allows websites to work better even when you are not connected to the internet.
- HTML5 provides advanced tools for creating visually impressive and interactive graphics on websites. This means that online content can have really cool and dynamic visual effects.
- It easier for websites to remember your login details, so you don't have to keep entering them every time you visit.
Similar Reads
Most Commonly Used Tags in HTML
HTML tags are the fundamental building blocks of web development, providing the structure and organization necessary for creating web pages.They include tags for headings, paragraphs, links, images, and more.Commonly used tags like <html>, <head>, and <body> are essential for creat
4 min read
What is utf 8 in HTML
When creating websites and web applications, one important can ensuring that content displays correctly for users around the world. Text encoding can play a critical role in this, as it defines how characters are represented in the digital form. UTF-8 (Unicode Transformation Format 8-bit) is one of
4 min read
When to use <samp> tag in HTML ?
The <samp> tag in HTML is used to define sample output from a computer program. It is typically used to represent text that is the output of a program or script. The <samp> tag is an inline tag and its content is rendered on the browsers in a monospaced font. Syntax: <samp> Sample
1 min read
Why should we avoid use of tables for layout in HTML ?
In this article, we will learn why we should avoid using tables for layout in HTML. A website can be divided into various sections comprising of header, menus, content, and footer based on which there are many different layout designs available for developers. Different layouts can be created by usi
4 min read
What is the use of <canvas> Tag in HTML ?
HTML <canvas> Tag allows you to create graphics, animations, and interactive content directly on a web page using JavaScript. It provides a drawing surface where you can use various JavaScript functions to create dynamic and visually appealing content. Here are key aspects of the <canvas
1 min read
What is the use of html() method in jQuery ?
The html() method in jQuery is used to get the contents of the first element in the set of matched elements or is used to set the HTML contents of every matched element. It returns the content of the first matched element. This function does not accept any arguments. Syntax: $(selector).html();Appro
4 min read
5 Easy Ways to Insert Spaces in HTML
In HTML, we can add spaces using a special character called the non-breaking space ( ). This ensures the space is visible and doesn't collapse when the page loads. We can use multiple to create larger spaces. However, it's better to use CSS properties like margin and padding to c
3 min read
What is the meaning of DOCTYPE in HTML ?
The HTML document type declaration or Doctype is an instruction used by web browsers to fetch what version of HTML the website is written in. It helps browsers in understanding how the document should be interpreted thus eases the rendering process. It is neither an element nor a tag. The doctype sh
2 min read
Space in HTML
In HTML, space management is very important for layout and readability. The "<br>" tag creates a line break in text, which brings content to start on a new line. This makes it easy when you want to structure text into separate lines, similar to hitting "Enter" on your keyboard. On the other ha
3 min read
What are logical tags in HTML ?
Logical tags are used to tell the browser what kind of text is written inside the tags. They are different from physical tags because physical tags are used to decide the appearance of the text and do not provide any information about the text. Logical tags are used to indicate to the visually impai
5 min read