HTML, or Hypertext Markup Language, is the standard markup language for creating web pages. It uses tags to structure the content on a page. Tags are enclosed in angle brackets, like <tagname>
. For example, the <h1>
tag is used to create a main heading, and the <p>
tag is used to create a paragraph.
<!DOCTYPE html>
<html>
<head>
<title>My First HTML Page</title>
</head>
<body>
<h1>Welcome to My Page</h1>
<p>This is a simple paragraph.</p>
</body>
</html>
In this example:
<!DOCTYPE html>
declares that this is an HTML5 document.<html>
tag is the root element of an HTML page.<head>
section contains meta-information about the page, such as the title.<body>
section contains the visible content of the page.CSS, or Cascading Style Sheets, is used to style HTML documents. 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.
Inline CSS is applied directly to an HTML element using the style
attribute.
<p style="color: blue; font-size: 18px;">This is a paragraph with inline CSS.</p>
Internal CSS is placed in the <style>
tag within the <head>
section of an HTML document.
<!DOCTYPE html>
<html>
<head>
<style>
p {
color: green;
font-size: 16px;
}
</style>
<title>Internal CSS Example</title>
</head>
<body>
<p>This is a paragraph styled with internal CSS.</p>
</body>
</html>
External CSS is stored in a separate .css
file and linked to an HTML document using the <link>
tag.
style.css
p {
color: red;
font-size: 20px;
}
index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="style.css">
<title>External CSS Example</title>
</head>
<body>
<p>This is a paragraph styled with external CSS.</p>
</body>
</html>
JavaScript is a programming language that adds interactivity to web pages. It can be used to create dynamic content, handle user events, and communicate with servers. JavaScript can be embedded directly in an HTML document using the <script>
tag or linked as an external .js
file.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello, JavaScript!";
}
</script>
</body>
</html>
script.js
function myFunction() {
document.getElementById("demo").innerHTML = "Hello from external JavaScript!";
}
index.html
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
<script src="script.js"></script>
</body>
</html>
To create a fully functional and visually appealing web page, you need to combine HTML, CSS, and JavaScript. Here is an example: index.html
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="styles.css">
<title>Combined Example</title>
</head>
<body>
<h1 id="heading">Welcome to My Page</h1>
<p id="paragraph">This is a paragraph with some text.</p>
<button onclick="changeText()">Change Text</button>
<script src="script.js"></script>
</body>
</html>
styles.css
h1 {
color: purple;
text-align: center;
}
p {
color: orange;
font-size: 14px;
}
script.js
function changeText() {
document.getElementById("paragraph").innerHTML = "The text has been changed!";
}
<header>
, <nav>
, <main>
, <article>
, <section>
, and <footer>
to improve the structure and accessibility of your web page.try...catch
blocks.em
and rem
for font sizes and spacing to make your design more responsive.CSS, HTML, and JavaScript are essential technologies for web development. HTML provides the structure, CSS adds the style, and JavaScript brings interactivity to web pages. By understanding the fundamental concepts, usage methods, common practices, and best practices of these technologies, beginners can start creating their own web pages and gradually build more complex and sophisticated web applications.