Creating a first website with CSS involves structuring your files, writing HTML to define content, and then applying CSS to style that content.


1. Project Setup:

  • Create a main project folder (e.g., MyFirstWebsite).
  • Inside, create an index.html file.
  • Also inside, create a css folder.
  • Inside the css folder, create a style.css file.

2. HTML Structure (index.html):

  • Define the basic HTML boilerplate.
  • Link your style.css file within the <head> section using the <link> tag.
  • Add some content within the <body> (e.g., headings, paragraphs, images).
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My First CSS Website</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
    <h1>Welcome to My Website!</h1>
    <p>This is my first website styled with CSS.</p>
    <div>
        <h2>About Me</h2>
        <p>I am learning web development.</p>
    </div>
</body>
</html>


 

3. CSS Styling (css/style.css):

  • Write CSS rules to target HTML elements and apply styles (e.g., colors, fonts, layout).
body {
    font-family: Arial, sans-serif;
    background-color: #f0f0f0;
    color: #333;
    margin: 20px;
}

h1 {
    color: #0056b3;
    text-align: center;
}

div {
    background-color: #fff;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-top: 20px;
}

p {
    line-height: 1.6;
}


 

4. Viewing Your Website:

  • Open the index.html file in your web browser. You will see the HTML content styled according to your style.css rules.