Unit 2 Study Materials
Unit 2 Study Materials
Definition:
HTML (HyperText Markup Language): The standard markup language used to create
web pages and web applications.
Purpose: Structures the content on the web, such as text, images, links, and other
multimedia elements.
History:
HTML documents are plain text files with a .html or .htm extension.
They consist of a series of elements that define the structure and content of the web page.
Example:
html
Copy code
<!DOCTYPE html>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a paragraph of text on my first HTML page.</p>
</body>
</html>
HTML documents are simple text files, which means you can create them using any text editor.
They are typically saved with a .html or .htm extension.
What makes HTML special is the use of tags. These are special keywords enclosed in angle
brackets (like < and >). These tags tell the web browser how to display the content.
For example, the tag <h1> tells the browser to display the enclosed text as a main heading, while
<p> is used for paragraphs.
We’ve already mentioned <h1> and <p>. Here are some other essential tags:
Headings
HTML
Paragraphs
HTML
<p>This is the first paragraph. Lorem ipsum dolor sit amet, consectetur
adipiscing elit.</p>
<p>This is the second paragraph.</p>
Lists
HTML
<!DOCTYPE html>
<html>
<body>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
<ul>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
Coffee
Tea
Milk
<!DOCTYPE html>
<html>
<body>
<ol>
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ol>
</body>
</html>
1. Coffee
2. Tea
3. Milk
Images
HTML
Links
HTML
The document layout of an HTML page is essential to both the functionality and organization of
a webpage. It defines how the content is structured, and it ensures that the browser can correctly
interpret and render the webpage. Let’s dive deeper into each component of the HTML
document structure:
This declaration defines the version of HTML the document is written in. For modern
web development, <!DOCTYPE html> is used, which specifies that the document is
HTML5. This declaration helps the browser to render the page correctly, ensuring it
adheres to HTML5 standards.
The <html> tag is the root of the HTML document. Everything within this tag is part of
the HTML content. It encloses all other HTML elements on the page, creating a
hierarchical structure.
Example:
<html>
</html>
The <head> section contains information about the HTML document that is not displayed
directly on the webpage but is essential for the document's functionality. This section
typically includes:
o <title>: Sets the title of the webpage, which appears in the browser tab and is
important for SEO. It should be concise and descriptive of the page content.
Example:
<head>
<title>Welcome to My Website</title>
</head>
<meta> Tags: Provide metadata about the HTML document. Common meta tags include:
Example:
<meta charset="UTF-8">
<link>: Used to link external resources like stylesheets (CSS files). This is crucial for adding
styles to your HTML content.
Example:
<script>: Links to external JavaScript files or includes inline JavaScript. JavaScript adds
interactivity to the webpage.
Example:
<script src="script.js"></script>
<style>: Allows embedding CSS styles directly within the document. Although using external
stylesheets is more common, inline styles can be useful for small projects or specific
customizations.
Example:
<style>
The <body> section contains all the content that users see and interact with on the
webpage. It is the main container for text, images, videos, links, forms, and any other
elements that make up the web page.
o Text content: Organized using headings (<h1> to <h6>), paragraphs (<p>), lists
(<ul>, <ol>), and other textual elements.
o Multimedia: Images (<img>), videos (<video>), and audio (<audio>).
o Links: Hyperlinks (<a>), which connect the webpage to other web resources.
o Forms: Elements that allow user input, such as text fields (<input>), buttons
(<button>), and dropdowns (<select>).
Example:
<body>
<h1>Welcome to My Website</h1>
</body>
Example:
<header>
<h1>My Website</h1>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<footer>: Positioned at the bottom of the page, it typically contains information like copyright
details, contact information, or links to related pages. The footer is consistent across multiple
pages of a website.
Example:
<footer>
</footer>
Example:
<section>
<h2>About Us</h2>
</section>
<article>
<h3>Latest News</h3>
</article>
Example of a Complete HTML Document Layout
Here's how all these components come together in a full HTML document:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My Webpage</title>
</head>
<body>
<header>
<h1>Welcome to My Website</h1>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
</header>
<section>
<h2>About Us</h2>
</section>
<article>
<h3>Latest News</h3>
</article>
<footer>
</footer>
</body>
</html>
This example demonstrates the full structure of an HTML document, providing a clear and
organized layout for both content and metadata. Understanding this layout is fundamental to
creating web pages that are both functional and easy to maintain.
HTML Elements
HTML elements are the fundamental building blocks of an HTML document. They define the
structure and content of a webpage. Each HTML element typically consists of a start tag,
content, and an end tag. Here’s a detailed look at some of the most important HTML elements:
Headings are used to define the hierarchical structure of content on a webpage. There are
six levels of headings, from <h1> (the highest level) to <h6> (the lowest level).
o <h1>: Represents the main heading of a page. It’s usually the largest and most
important heading.
o <h2> to <h6>: Represent subheadings, with decreasing importance and size.
Example:
<h1>Main Heading</h1>
Headings are crucial for both SEO and accessibility, as search engines and screen readers use
them to understand the structure and importance of content.
Paragraphs (<p>)
The <p> element is used to define a block of text as a paragraph. It’s a block-level
element, meaning it automatically starts on a new line and takes up the full width
available.
Example:
Links (<a>)
The <a> element, known as the anchor tag, is used to create hyperlinks. The href
attribute specifies the destination URL. Links are essential for navigating between web
pages and other resources on the web.
Example:
Links can also be used to link to other sections within the same page, by using an id attribute in
the destination element and a hash symbol # in the link.
Example:
...
Images (<img>) :
The <img> element is used to embed images in a webpage. It’s a self-closing tag,
meaning it doesn’t need an end tag. The src attribute specifies the path to the image file,
and the alt attribute provides alternative text for the image (important for accessibility
and SEO).
Example:
Images enhance the visual appeal of a webpage and can also convey important information.
Lists
HTML provides two types of lists: ordered lists and unordered lists.
o Ordered List (<ol>): This creates a list of items with numbers or letters,
indicating a sequence.
Example:
<ol>
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>
Unordered List (<ul>): This creates a list of items with bullet points, without any particular
order.
Example
<ul>
<li>Item one</li>
<li>Item two</li>
<li>Item three</li>
</ul>
Tables (<table>)
The <table> element is used to display data in a tabular format, organized in rows and
columns.
o <tr> (Table Row): Defines a row in the table.
o <th> (Table Header): Defines a header cell in a table, typically displayed in bold
and centered by default.
o <td> (Table Data): Defines a data cell in a table, containing the actual content.
Example:
<table>
<tr>
<th>Header 1</th>
<th>Header 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
<tr>
<td>Data 3</td>
<td>Data 4</td>
</tr>
</table>
Tables are useful for displaying structured data, such as comparison charts, schedules, or any
content that benefits from a grid layout.
Forms (<form>)
The <form> element is used to collect user input. Forms can include various types of
input fields, such as text boxes, radio buttons, checkboxes, and submit buttons.
o <input>: Used to create input fields. The type attribute defines the type of input
(e.g., text, password, submit).
o <label>: Provides a label for an input element, making forms more accessible.
o <textarea>: Allows users to enter multi-line text.
o <select>: Creates a dropdown list.
o <button>: Represents a clickable button.
Example:
<label for="name">Name:</label>
<label for="email">Email:</label>
<button type="submit">Submit</button>
</form>
Example:
<header>
<h1>My Website</h1>
</header>
<nav>
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
<section>
<h2>About Us</h2>
</section>
<article>
<h3>Latest News</h3>
</article>
<footer>
</footer>
These semantic elements enhance the readability and organization of the HTML code, making it
easier for developers, search engines, and assistive technologies to understand the structure of
the content.
Inline elements are used for content that does not break the flow of text within a block-
level element.
o <span>: A generic inline container used to group content for styling or scripting.
o <a>: As mentioned earlier, creates hyperlinks.
o <strong>: Indicates strong importance, typically rendered in bold.
o <em>: Represents emphasized text, typically rendered in italics.
Example:
Inline elements are essential for fine-tuning the appearance of text and other content within a
webpage without disrupting the document’s overall layout.