June 2, 2024
What is CSS?
CSS (Cascading Style Sheets) is a language used to describe the presentation of a document written in HTML or XML. It defines how elements should be displayed on screen, on paper, or in other media. CSS allows you to separate the content of a web page from its design, making it easier to maintain and update.
The History of CSS
CSS was developed by the World Wide Web Consortium (W3C) to address HTML's limitations in terms of design and layout. The first version, CSS1, was released in 1996, followed by CSS2 in 1998 and CSS3 in 2011. CSS3 introduced many new features, such as transitions, animations, and flexible box layouts.
How CSS Works with HTML
CSS is applied to HTML elements using three methods:
<link>
tag in the <head>
section.<style>
tag in the HTML file.style
attribute.Setting Up Your Development Environment
You'll need:
Your First CSS Stylesheet
Create an HTML File:
<!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</title> <link rel="stylesheet" href="styles.css"> </head> <body> <h1>Hello, World!</h1> <p>This is my first CSS example.</p> </body> </html>
Create a CSS File:
body { background-color: #f0f0f0; font-family: Arial, sans-serif; color: #333; } h1 { color: #0066cc; text-align: center; border: 1px solid #0066cc; } p { font-size: 16px; line-height: 1.5; text-align: center; }
Link the CSS File: Ensure the <link>
tag in your HTML file references styles.css
.
Open the HTML File in a Browser: Double-click index.html
to see your styled webpage.
Exercise: Styling a Simple Webpage
Try the following:
body
background color.<p>
font size and color.<h1>
element.<p>
elements.Coming Up Next
In Chapter 2, we'll delve into basic CSS selectors and properties, laying the foundation for more complex styling techniques.
Please Sign In to post a comment.