Basic of html
what is HTML?
- HTML (Hypertext Markup Language) is the standard markup language used for creating web pages and web applications. It provides a set of predefined tags and attributes that structure and define the content of a webpage.
Structure: HTML documents are structured using a hierarchical model called the Document Object Model (DOM). The DOM organizes the content into a tree-like structure of nested elements, with the root element being the
<html>
tag.Tags: HTML tags define different elements and their roles on the webpage. Tags are written using angle brackets ("<>" and "</>"). They usually consist of an opening tag and a closing tag, although some tags are self-closing. For example,
<p>
is the opening tag for a paragraph, and</p>
is the closing tag.Attributes: HTML tags can have attributes that provide additional information about the elements. Attributes are specified within the opening tag and consist of a name and a value. For example, the
<img>
tag has attributes likesrc
(source) andalt
(alternative text) to define the image source and provide a text description.Document Structure: HTML documents typically have a structure that includes a
<head>
section and a<body>
section. The<head>
section contains meta-information about the document, such as the title, character encoding, and linked stylesheets or scripts. The<body>
section contains the visible content of the webpage.Text Formatting: HTML provides tags for formatting text, such as headings (
<h1>
to<h6>
), paragraphs (<p>
), bold text (<b>
or<strong>
), italic text (<i>
or<em>
), and more. These tags allow you to structure and style your content.Links and Navigation: HTML includes tags for creating hyperlinks (
<a>
) that allow users to navigate between different web pages. The<nav>
tag can be used to define navigation menus, while the<ul>
and<li>
tags are used for unordered lists and list items.Images and Media: HTML enables the embedding of images (
<img>
) and media content such as videos (<video>
) and audio (<audio>
) within web pages. These tags allow you to display and control multimedia elements.Forms: HTML provides tags to create interactive forms for user input. Form elements include input fields (
<input>
), checkboxes (<input type="checkbox">
), radio buttons (<input type="radio">
), text areas (<textarea>
), buttons (<button>
), and more. Form data can be submitted to a server for processing using the<form>
tag.Semantic HTML: HTML5 introduced a set of semantic tags that describe the meaning of the content they enclose. These tags, such as
<header>
,<footer>
,<section>
,<article>
,<aside>
,<nav>
,<main>
, etc., help improve the accessibility, structure, and search engine optimization of web pages.CSS Integration: HTML works in conjunction with CSS (Cascading Style Sheets) to control the presentation and layout of web pages. CSS is used to define styles, colors, fonts, positioning, and other visual aspects of HTML elements.
HTML Element
HTML elements consist of an open tag(<>), attribute(s), content, and closing tag(<>). Look at the figure below to understand the syntax of an HTML element.
HTML elements can represent various types of content, such as headings, paragraphs, images, links, tables, forms, and more. Each element has a specific purpose and formatting associated with it.
comment in HTML
In HTML, you can add comments to your code to provide explanations or notes that are not displayed on the webpage. Comments are useful for documenting your HTML code or temporarily disabling specific sections of code without deleting them.
<!-- This is a comment -->
Metadata
- Metadata: HTML allows you to specify metadata about the document using the
<meta>
tag within the<head>
section. Metadata includes information such as the character encoding (<meta charset="UTF-8">
), viewport settings for responsive design (<meta name="viewport" content="width=device-width, initial-scale=1.0">
), and keywords for search engine optimization (<meta name="keywords" content="web development, HTML, CSS">
).
List in HTML
- Lists: HTML provides tags for creating both ordered lists (
<ol>
) and unordered lists (<ul>
). List items are defined using the<li>
tag, and you can nest lists within each other to create sublists.
<h2>Ordered List Example</h2>
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
<h2>Unordered List Example</h2>
<ul>
<li>Red</li>
<li>Green</li>
<li>Blue</li>
</ul>
semantic tags in HTML
<header>
: The <header>
tag represents the introductory or navigational content at the top of a webpage or a section. It typically contains the site title, logo, and primary navigation.
<header><h1>Welcome to My Website</h1></header>
<nav>
: The <nav>
tag defines a section of navigation links within a webpage. It is used to mark menus, navigation bars, or other groups of links that allow users to navigate the website or a specific section.
<nav>
<ul>
<li>
<a href="#">Home</a>
</li>
<li>
<a href="#">About</a>
</li>
</ul>
</nav>
<section>
: The <section>
tag represents a standalone section of content within a webpage. It is used to logically group related content together. For example, an article can be divided into multiple sections like introduction, body, and conclusion.
<section>
<h2>About Me</h2>
<p>I am a web developer with a passion for creating interactive websites.</p>
</section>
<article>
: The <article>
tag is used to define an independent, self-contained piece of content. It represents a complete composition that could be distributed or syndicated independently, such as a blog post, news article, or forum post.
<article>
<h2>10 Tips for Effective Web Design</h2>
<p>Here are ten valuable tips for creating visually appealing and user-friendly websites...</p>
</article>
<aside>
: The <aside>
tag represents content that is tangentially related to the main content of a webpage. It is typically used for sidebars, pull quotes, or additional information that complements the primary content.
<aside>
<h3>Related Links</h3>
<ul>
<li>
<a href="#">Web Design Trends 2023</a>
</li>
<li>
<a href="#">Responsive Design Techniques</a>
</li>
</ul>
</aside>
<main>
: The <main>
tag identifies the main content area of a webpage. It should be unique and contain the primary content that is directly related to the purpose or central theme of the page.
<main>
<h1>Welcome to My Blog</h1>
<article>...</article>
</main>
Usage: The <main>
<footer>
: The <footer>
tag defines the footer section of a webpage. It usually contains information such as copyright notices, contact information, related links, and other auxiliary content.
<footer>
© 2023 My Website. All rights reserved.
</footer>
<figure>
and <figcaption>
: The <figure>
tag is used to encapsulate multimedia content, such as images, illustrations, videos, or graphs, that are referenced within the main content. The optional <figcaption>
tag can be used to provide a caption or description for the figure.
<figure>
<img src="image.jpg" alt="A beautiful sunset">
<figcaption>Photo by John Doe</figcaption></figure>
<time>
: The <time>
tag represents a specific date, time, or duration. It is useful for marking up dates and times within the content, such as publishing dates, event timings, or article timestamps.
Subscribe to my newsletter
Read articles from Tejas Gojariya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by