HTML Basic Tags
HTML Basic Tags
<!DOCTYPE html>
<html>
<head>
<title> Web and Database Level I </title>
</head>
<body>
<h1>This is a heading</h1>
<p>Document content goes here.....</p>
</body>
</html>
save it in an HTML file test.html
HTML Tags
<!DOCTYPE...>
<html>
<head>
<title>
<body>
<h1>
<p>
A. Heading Tags
HTML provides six levels of headings, from <h1> (largest) to <h6> (smallest), to structure the
content hierarchy. Headings add line breaks automatically before and after the text.
<!DOCTYPE...>
<html>
<head>
<title></title>
</head>
<body>
B. Paragraph Tag
The <p> tag is used to define paragraphs, creating space around blocks of text.
<!DOCTYPE...>
<html>
<head>
<title></title>
</head>
<body>
The <br /> tag is an empty element that inserts a line break. It does not require a closing tag.
<!DOCTYPE...>
<html>
<head>
<title></title>
</head>
<body>
<p>This is a paragraph of text.</p><br />
<p>This is another paragraph.</p>
</body>
</html>
The <hr /> tag creates a horizontal line that visually separates sections of content.
<!DOCTYPE...>
<html>
<head>
<title></title>
</head>
<body>
<p>This is some content.</p>
<hr />
<p>This is content after the horizontal line.</p>
</body>
</html>
The <pre> tag preserves whitespace and line breaks, displaying text exactly as it appears in the
HTML source.
<!DOCTYPE...>
<html>
<head>
<title></title>
</head>
<body>
<pre>
This text
will keep
its formatting.
</pre>
</body>
</html>
F. Nonbreaking Space
To prevent text from breaking at spaces, use instead of a normal space.
<!DOCTYPE...>
<html>
<head>
<title></title>
</head>
<body>
<p>Here is the phrase "12 Angry Men" without line breaks between
words.</p>
</body>
</html>
G. HTML Comments
Comments in HTML, enclosed within <!-- ... -->, are ignored by the browser and don’t
appear on the page. Comments help in organizing and explaining the code.
Single-line comment:
<!DOCTYPE...>
<html>
<head>
<title></title>
</head>
<body>
<p>this is paragraph one<!-- This is a single-line comment -->followed
by comment</p>
</body>
</html>
Multi-line comment:
<!DOCTYPE...>
<html>
<head>
<title></title>
</head>
<body>
<p>this is paragraph one
<!--
This is a
multi-line comment
-->
followed by comment</p>
</body>
</html>
It’s recommended to wrap JavaScript and CSS in comments for compatibility with older
browsers.
JavaScript comment:
html
Copy code
<script>
<!--
document.write("Hello World!");
//-->
</script>
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello JavaScript!";
}
</script>
</head>
<body>
</body>
</html>
CSS comment:
html
Copy code
<style>
<!--
.example {
border: 1px solid #4a7d49;
}
//-->
</style>
CSS Example
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<style>
body {background-color: powderblue;}
h1 {color: red;}
p {color: blue;}
</style>
</head>
<body>
</body>
</html>
1. HTML Elements
HTML elements are defined by a starting tag and, if containing content, end with a closing tag.
Some elements, called void or empty elements, don’t require a closing tag.
Examples:
<html>
<body>
</body>
</html>
A tag defines the start or end of an element, while an element includes the start tag, content, and
end tag.
Example:
html
Copy code
<p>This is paragraph</p> <!-- <p> is a tag; <p> ... </p> is an element
-->
Example:
html
Copy code
<h1>This is <i>italic</i> heading</h1>
<p>This is <u>underlined</u> paragraph</p>
2. HTML Attributes
Attributes provide additional information about HTML elements and are placed within the
opening tag. Common attributes include id, class, style, and title.
Core Attributes
html
Copy code
<p id="intro">This paragraph has a unique id.</p>
2. Title Attribute: Adds a tooltip that appears when hovering over the element.
html
Copy code
<h3 title="Hello HTML!">Hover over this heading</h3>
3. Class Attribute: Assigns the element to a specific class for CSS styling.
html
Copy code
<p class="text-primary">This text belongs to the 'text-primary'
class.</p>
html
Copy code
<p style="font-family: Arial; color: #FF0000;">Some styled text</p>
B. Internationalization Attributes
html
Copy code
<html dir="rtl"> <!-- Sets document text direction to right-to-left -->
html
Copy code
<html lang="en"> <!-- Sets language to English -->
3. xml
html
Copy code
<html xml:lang="en"> <!-- Sets language for XHTML documents -->
C. Generic Attributes
Attribute Options Function
html
Copy code
<p id="intro" class="highlight" title="Intro Text" style="color: blue;">
This is a paragraph with multiple attributes.
</p>