All image on this articol via Image by rawpixel.com on Freepik
Creating a web page from scratch is a fundamental skill for anyone interested in web development. Whether you're a beginner or someone looking to refresh your knowledge, this guide will walk you through the steps of creating a basic web page. We will cover HTML, CSS, and JavaScript—the core technologies of web development—and provide examples to help you understand each concept.
Before writing code, you need the right tools:
Code Editor: Use a text editor like Visual Studio Code, Sublime Text, or Notepad++.
Browser: A modern browser like Google Chrome, Firefox, or Edge to view and test your page.
Basic Knowledge: Familiarity with HTML, CSS, and JavaScript is beneficial but not mandatory.
HTML (HyperText Markup Language) defines the structure of your web page. It uses tags to organize and display content.
<!DOCTYPE html>
<html>
<head>
<title>My First Web Page</title>
</head>
<body>
<h1>Welcome to My Web Page</h1>
<p>This is a simple paragraph explaining the purpose of the page.</p>
<a href="https://www.example.com">Visit Example</a>
</body>
</html>
<!DOCTYPE html>
: Declares the document as HTML5.
<html>
: The root element of the web page.
<head>
: Contains meta-information, such as the page title.
<body>
: Holds the visible content, like headings, paragraphs, and links.
CSS (Cascading Style Sheets) controls the visual appearance of the web page.
<p style="color: blue; font-size: 20px;">This is a blue paragraph.</p>
<head>
<style>
body {
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
h1 {
color: #333;
}
</style>
</head>
Create a file named styles.css
and link it to your HTML:
<link rel="stylesheet" href="styles.css">
Contents of styles.css
:
body {
background-color: #f0f0f0;
font-family: Arial, sans-serif;
}
h1 {
color: #333;
}
p {
font-size: 16px;
line-height: 1.5;
}
JavaScript makes your web page dynamic and interactive.
<button onclick="alert('Hello, World!')">Click Me</button>
<script>
function greetUser() {
alert('Welcome to my web page!');
}
</script>
<button onclick="greetUser()">Click Me</button>
Create a file named script.js
and link it to your HTML:
<script src="script.js"></script>
Contents of script.js
:
function greetUser() {
alert('Welcome to my web page!');
}
Here is an example of a simple web page that combines HTML, CSS, and JavaScript:
<!DOCTYPE html>
<html>
<head>
<title>My Complete Web Page</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<h1>Welcome to My Web Page</h1>
<p>This page demonstrates HTML, CSS, and JavaScript working together.</p>
<button onclick="changeText()">Click to Change Text</button>
<p id="dynamicText">This text will change when you click the button.</p>
<script src="script.js"></script>
</body>
</html>
styles.css
):
body {
background-color: #f9f9f9;
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}
h1 {
color: #4CAF50;
}
button {
background-color: #008CBA;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button:hover {
background-color: #005f73;
}
script.js
):
function changeText() {
document.getElementById('dynamicText').innerText = 'The text has changed!';
}
Save all your files in the same directory (e.g., index.html
, styles.css
, script.js
).
Open index.html
in your browser by double-clicking it.
Test the functionality: Click buttons, check styles, and experiment with the code.
Once your web page is complete, you can host it online using:
GitHub Pages: Free hosting for static websites. Follow this guide.
Netlify: Another popular platform for free hosting.
Local Hosting: Use tools like XAMPP or WAMP for local testing.
Creating a web page from scratch involves understanding the basics of HTML, CSS, and JavaScript. By following the steps outlined in this guide, you can build your own web page and expand your knowledge of web development. Experiment, practice, and take your designs to the next level!