An HTML element is a building block of a webpage that consists of a start tag, content, and an end tag. Elements form the structure of the content on the page.
Tags are the keywords that define the start and end of an element. Attributes provide additional information about the elements and are included within the opening tag.
<a href="https://olevelcccexam.link">
Visit our site</a>
<a>
is the tag, href
is an attribute, and "Visit our site" is the content.
Tags in HTML can be divided into two types: empty tags and container tags.
Empty Tags: These tags do not have any content or closing tags. They are self-closing.
<br>
, <img src="image.jpg" alt="Sample Image">
Container Tags: These tags come in pairs (an opening and a closing tag) and enclose content between them.
<p>This is a paragraph.</p>
, <div>Content here</div>
The <body> tag contains all the main visible content of an HTML document. Every text, image, and multimedia content is enclosed within this tag.
Important attributes of the <body> tag:
<body bgcolor="#e0f7fa">
)<body background="background.jpg">
)<body text="#333">
)<body margin="0">
)<body bgcolor="#f0f0f0" text="#000">
The <p> tag is used to define paragraphs in HTML. It automatically adds space above and below the content.
Attribute: The align
attribute aligns the paragraph content. (Example: <p align="center">Centered text</p>
)
The <pre> tag is used to define preformatted text. It preserves spaces and line breaks exactly as they appear in the code.
<pre>Line 1
Line 2
Line 3</pre>
The <br> tag is an empty tag that inserts a line break. It is often used within paragraphs to separate lines of text.
First Line<br>Second Line
Formatting elements were designed to display special types of text:
<b>
- Bold text<strong>
- Important text<i>
- Italic text<em>
- Emphasized text<mark>
- Marked text<small>
- Smaller text<del> or <strike>
- Deleted text<big>
- Big text<sub>
- Subscript text<sup>
- Superscript textThis text is bold.
This text is important.
This text is italic.
This text is emphasized.
This text is highlighted (marked).
This is smaller text.
This text is deleted.
This text is big.
H2O (subscript)
x2 + y2 = z2 (superscript)
The <center> tag is used to align the content to the center of its containing element. It is deprecated in HTML5, and CSS should be used for centering instead.
<center>This text is centered</center>
The <hr> tag is used to create a horizontal rule (a line) across the page, usually for separating content.
Important attributes of the <hr> tag:
<hr width="50%">
)<hr size="3">
)<hr noshade>
)<hr align="left">
)<hr color="red">
)<hr width="70%" size="5" noshade align="center" color="blue">
The <div> tag is a block-level element used to group content together. It is often styled using CSS.
Important attribute of the <div> tag:
<div align="center">Centered content</div>
)<div align="center">This content is centered</div>
The <font> tag is used to change the font style of text. It is deprecated in HTML5, and CSS should be used instead for styling fonts.
Important attributes of the <font> tag:
<font color="blue">Blue text</font>
)<font size="5">Larger text</font>
)<font face="Arial">Text in Arial</font>
)<font color="red" size="4" face="Verdana">Stylized text</font>
The <img> tag is used to insert images into a webpage. It is an inline element.
Important attributes of the <img> tag:
<img src="image.jpg">
)<img src="image.jpg" alt="Description of image">
)<img src="image.jpg" height="100">
)<img src="image.jpg" width="200">
)<img src="image.jpg" border="2">
)<img src="image.jpg" hspace="10">
)<img src="image.jpg" vspace="10">
)<img src="image.jpg" align="left">
)<img src="example.jpg" alt="Example Image" width="200" height="100" border="1" hspace="5" vspace="5" align="right">
The <h1> to <h6> tags are used to define HTML headings. <h1> is the highest level heading and <h6> is the lowest.
Important attribute for these heading tags:
<h2 align="right">Right Aligned Heading</h2>
)<h1 align="center">Centered Heading</h1>
<h2 align="left">Left Aligned Heading</h2>
<h3 align="right">Right Aligned Heading</h3>
<h4 align="justify">Justified Heading</h4>
The <marquee> tag is used to create scrolling text or images. It is a non-standard HTML element and is not recommended for modern web design.
Important attributes of the <marquee> tag:
<marquee width="300">
)<marquee height="100">
)<marquee direction="left">
)<marquee scrollamount="10">
)<marquee loop="5">
)<marquee vspace="10">
)<marquee hspace="10">
)<marquee behavior="alternate">
)<marquee width="300" height="50" direction="right" scrollamount="5" loop="10" vspace="10" hspace="10" behavior="alternate">Scrolling Text</marquee>
Comments in HTML are not displayed in the browser but can help you explain your code or leave notes for others. To add a comment, use:
<!-- This is a comment -->
Lists are used to group related items together. There are four main types of lists in HTML:
Ordered ListAn ordered list displays items in a numbered format.
Attributes:
<ol type="A" start="3"><li>Item 1</li></ol>
An unordered list displays items with bullets.
Attributes:
<ul type="circle"><li>Item 1</li></ul>
A definition list is used to display items in a glossary format.
<dl><dt>HTML</dt><dd>A markup language for creating web pages.</dd></dl>
Nesting lists allows you to create sub-lists within a list item.
<ul>
<li>Item 1<ul>
<li>Subitem 1</li>
</ul></li>
</ul>
HTML provides different tags to create various types of lists:
The <table> tag is used to create a table in HTML. It can contain several child elements like <tr>, <th>, and <td> to define the structure and content of the table.
<caption>Table Title</caption>
)Important attributes of the <table> tag:
<table border="1">
)<table bordercolor="blue">
)<table bgcolor="#f0f0f0">
)<table background="image.jpg">
)<table align="center">
)<table width="80%" height="200">
)<table cellspacing="5">
)<table cellpadding="10">
)<td colspan="2">
)<td rowspan="2">
)
<table border="1" bordercolor=
"black" bgcolor="#f9f9f9" align="
center" width="60%" cellspacing=
"2" cellpadding="5">
<caption>Monthly Sales
</caption>
<tr>
<th>Product</th>
<th>Price</th>
<th>Quantity</th>
</tr>
<tr>
<td>Laptop</td>
<td>$1200</td>
<td>5</td>
</tr>
<tr>
<td>Tablet</td>
<td colspan="2">$400
(Special Offer)</td>
</tr>
</table>
Output:
Product | Price | Quantity |
---|---|---|
Laptop | $1200 | 5 |
Tablet | $400 (Special Offer) |
The <frameset> and <frame> tags were used to divide a web page into multiple sections or frames, which can load different HTML documents.
Important attributes of the <frameset> and <frame> tags:
<frameset rows="50%,50%">
)<frameset cols="30%,70%">
)<frameset border="2">
)yes
, no
, or auto
.
<frameset rows="50%,50%" cols="50%,50%">
<frame src="top.html" scrolling="yes" noresize>
<frame src="bottom.html" border="2">
</frameset>
Using nested <frameset> tags allows you to create more complex layouts by placing one frameset inside another.
<frameset rows="50%,50%" border="1">
<frame src="top.html" scrolling="yes" noresize>
<frameset cols="50%,50%">
<frame src="left.html" >
<frame src="right.html" scrolling="auto" >
</frameset>
</frameset>
The anchor tag (<a>) is used to create hyperlinks in HTML. There are three main types of links you can create:
Links to sections within the same webpage using Name Attribute.
<a href="#section1">Go to Section 1</a>
<h2 name="section1">Section 1</h2>
Links to another webpage.
<a href="name.html">Visit Example.com</a>
Links that use complete URLs (including protocol and domain) to ensure they work from any location.
<a href="https://www.example.com/
page.html"
>Global Link</a>
<a href="https://www.example.com">Visit Example</a>
<a name="top">Top of page</a>
<a href="page.html" target="_blank">Open in new tab</a>
<a href="page.html" title="Click to learn more">Learn More</a>
<a href="file.pdf" download>Download PDF</a>
<a href="https://www.example.com/
document.pdf"
target="_blank"
title="Download our brochure"
download="brochure.pdf">
Download Brochure
</a>
The <form> tag is used to create an HTML form for user input. It is a block-level element.
Important attributes of the <form> tag:
<form name="myForm" action="/submit.php" method="post"></form>
The <input> tag is used to create form input fields. It is an inline element.
Important attributes of the <input> tag:
The <textarea> tag is used to create a multi-line text input field, allowing users to enter longer pieces of text. It has the following important attributes:
<form name="myForm" action="/submit.php" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="John Doe" size="20" maxlength="50"><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br>
<input type="checkbox" id="agree" name="agree" value="yes">
<label for="agree">I agree to the terms</label><br>
<input type="submit" value="Submit">
</form>
The <fieldset> tag is used to group related form controls together, such as a set of radio buttons or checkboxes.
The <legend> tag provides a caption for the <fieldset> element.
<form name="myForm" action="/submit.php" method="post">
<fieldset>
<legend>Personal Information</legend>
<label for="name">Name:</label>
<input type="text" id="name" name="name" value="John Doe" size="20" maxlength="50"><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email"><br>
</fieldset>
<fieldset>
<legend>Preferences</legend>
<input type="checkbox" id="agree" name="agree" value="yes">
<label for="agree">I agree to the terms</label><br>
<input type="submit" value="Submit">
</fieldset>
</form>
The <fieldset> tag groups the form controls, and the <legend> tag provides a caption for each fieldset, making the form more organized and easier to understand.
The <select> tag is used to create a dropdown list or a combo box. It is a block-level element.
Important attributes of the <select> tag:
The <option> tag is used to create individual options within the <select> dropdown list.
Important attributes of the <option> tag:
<form name="myForm" action="/submit.php" method="post">
<label for="country">Select a country:</label>
<select id="country" name="country">
<option value="">-- Select a country --</option>
<option value="usa">United States</option>
<option value="can">Canada</option>
<option value="mex">Mexico</option>
</select>
<input type="submit" value="Submit">
</form>
HTML5 is the latest version of HyperText Markup Language, the standard language used to create web pages. It was designed to simplify web development, improve user experience, and support the latest multimedia formats. HTML5 introduces new tags, attributes, and APIs that enhance the functionality and structure of web pages.
<audio src="audio-file.mp3" type="audio/mpeg" controls autoplay loop></audio>
<video src="video-file.mp4" type="video/mp4" controls autoplay loop width="640" height="360"></video>
HTML5 introduced built-in form validations to ensure users provide valid input before submitting forms. These validations prevent form submission until fields meet specified criteria, like being filled in or matching a required format.
Example form with validation:
HTML Code:
<form>
<label for="name">Name:</label>
<input type="text" id="name"
name="name" required>
<br><br>
<label for="email">Email:</label>
<input type="email" id="email"
name="email" required>
<br><br>
<label for="password">Password:</label>
<input type="password" id="password"
name="password" pattern=".{6,}" required>
<br><br>
<button type="submit">Submit</button>
</form>
required
AttributeThe required
attribute ensures that a form field must be filled out before submitting the form. If a field with required
is empty, the form won’t submit and displays a warning to the user.
Example:
HTML Code:
<form>
<label for="username">Username:</label>
<input type="text" id="username"
name="username" required>
<br><br>
<button type="submit">Submit</button>
</form>
pattern
AttributeThe pattern
attribute allows you to specify a regular expression that the input must match. If the input doesn’t match the pattern, the form won’t submit, and a validation message is displayed.
Example:
The autofocus attribute makes it easy to start typing. When the page opens, the cursor will already be in this box!
The iframe tag lets you see another webpage inside this webpage! Here’s a sample webpage inside a box:
<iframe src="https://www.olevelcccexam.link" width="600" height="400" title="Example Website"> Your browser doesn’t support iframes. </iframe>