HTML is a markup language used to create the structure of web pages. It uses tags to define different elements on a page. Tags are enclosed in angle brackets (<>
). For example, the <p>
tag is used to define a paragraph.
<h1>
- <h6>
tags. <h1>
represents the most important heading, while <h6>
is the least important.<h1>This is a Heading 1</h1>
<h2>This is a Heading 2</h2>
<p>
tag.<p>This is a paragraph of text.</p>
<a>
tag. The href
attribute specifies the destination URL.<a href="https://www.example.com">Visit Example.com</a>
<img>
tag. The src
attribute points to the image file.<img src="example.jpg" alt="An example image">
CSS is a style sheet language used to describe the presentation of an HTML document. It separates the content (HTML) from the style, making it easier to maintain and update the look of a website.
<p>
elements:p {
color: blue;
}
.
) in CSS.<p class="highlight">This is a highlighted paragraph.</p>
.highlight {
background - color: yellow;
}
#
) in CSS.<p id="unique">This is a unique paragraph.</p>
#unique {
font - size: 20px;
}
An HTML document starts with an <!DOCTYPE html>
declaration, followed by an <html>
tag. Inside the <html>
tag, there are <head>
and <body>
sections.
<!DOCTYPE html>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<h1>Welcome to my page</h1>
<p>This is some sample text.</p>
</body>
</html>
HTML forms are used to collect user input. They use elements like <input>
, <textarea>
, and <select>
.
<form>
<label for="name">Name:</label>
<input type="text" id="name" name="name"><br>
<label for="message">Message:</label>
<textarea id="message" name="message"></textarea><br>
<input type="submit" value="Submit">
</form>
Inline CSS is applied directly to an HTML element using the style
attribute.
<p style="color: red; font - size: 18px;">This is a paragraph with inline CSS.</p>
Internal CSS is placed inside the <style>
tag in the <head>
section of an HTML document.
<!DOCTYPE html>
<html>
<head>
<style>
h2 {
color: green;
}
</style>
</head>
<body>
<h2>This is a green heading</h2>
</body>
</html>
External CSS is stored in a separate .css
file and linked to an HTML document using the <link>
tag.
style.css
body {
font - family: Arial, sans - serif;
}
index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<p>This text will have an Arial font.</p>
</body>
</html>
<header>
, <nav>
, <main>
, <article>
, <section>
, and <footer>
to give meaning to the structure of your page. This helps search engines and screen readers understand the content better.<header>
<h1>My Website</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>
<li>
tag should be inside a <ul>
or <ol>
tag.@media (max - width: 768px) {
body {
font - size: 14px;
}
}
div {
width: 200px;
padding: 20px;
border: 1px solid black;
margin: 10px;
}
alt
attribute for images. This helps users who cannot see the images (e.g., due to a visual impairment) understand what the image represents.HTML and CSS are essential technologies for web development. By understanding their fundamental concepts, usage methods, common practices, and best practices, you can create well - structured, visually appealing, and user - friendly websites. Remember to keep learning and practicing, as web development is an ever - evolving field.