HTML is a markup language used to create the structure of web pages. It consists of elements, which are represented by tags. An HTML element typically has an opening tag <tagname>
, content, and a closing tag </tagname>
. For example, the <p>
tag is used to create a paragraph:
<p>This is a paragraph of text.</p>
<h1>
- <h6>
), lists (<ul>
for unordered lists, <ol>
for ordered lists), and images (<img>
).<!DOCTYPE html>
declaration, followed by an <html>
element that encloses the entire document. Inside the <html>
element, there are two main sections: the <head>
and the <body>
. The <head>
contains metadata about the page, like the title, while the <body>
holds the visible content.<!DOCTYPE html>
<html>
<head>
<title>My Web Page</title>
</head>
<body>
<h1>Welcome to my page</h1>
<p>Here is some content.</p>
</body>
</html>
CSS is used to style HTML elements. It allows you to control the layout, colors, fonts, and other visual aspects of a web page. CSS can be applied in three ways: inline, internal, and external.
style
attribute.<p style="color: blue;">This text is blue.</p>
<style>
tags in the <head>
section of an HTML document.<!DOCTYPE html>
<html>
<head>
<style>
p {
color: green;
}
</style>
</head>
<body>
<p>This text will be green.</p>
</body>
</html>
.css
file and linked to the HTML document using the <link>
tag.<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<p>Text styled by external CSS</p>
</body>
</html>
In styles.css
:
p {
color: purple;
}
To create a simple web page with HTML, you first need to understand the basic structure. Here is a step - by - step guide to creating a basic HTML page:
<!DOCTYPE html>
declaration to indicate the HTML version.<html>
tag to enclose the entire document.<html>
tag, create the <head>
and <body>
sections.<head>
with metadata and the <body>
with content.<!DOCTYPE html>
<html>
<head>
<title>Sample Page</title>
</head>
<body>
<h2>Sample Heading</h2>
<p>This is a sample paragraph for the page.</p>
</body>
</html>
Once you have an HTML structure, you can start styling it with CSS. For example, if you want to style all the paragraphs on the page to have a specific font size and color:
<!DOCTYPE html>
<html>
<head>
<style>
p {
font-size: 16px;
color: #333;
}
</style>
</head>
<body>
<p>This paragraph will have a font - size of 16px and a dark gray color.</p>
</body>
</html>
<header>
, <nav>
, <main>
, <article>
, <section>
, and <footer>
instead of just using generic <div>
tags. This makes the code more readable and accessible for both developers and search engines.<header>
<h1>My Website Header</h1>
</header>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
</ul>
</nav>
<main>
<article>
<h2>Article Title</h2>
<p>Article content goes here.</p>
</article>
</main>
<footer>
<p>© 2024 My Website</p>
</footer>
<!-- This is the main content section -->
<main>
<p>Main content of the page</p>
</main>
<div>
element:div {
margin: 10px;
padding: 5px;
border: 1px solid black;
}
@media (max - width: 768px) {
body {
font - size: 14px;
}
}
.text - style {
color: #333;
font - size: 16px;
}
And in HTML:
<p class="text - style">This paragraph uses the common text style.</p>
The MTA Introduction to Programming using HTML and CSS provides a solid foundation for web development. HTML forms the structure of web pages, while CSS enhances their visual appeal. By understanding the fundamental concepts, following common and best practices, you can create well - structured, stylish, and maintainable web pages. Remember to use semantic HTML for better readability and accessibility, and modular CSS for easier maintenance.